/[pub]/suikawiki/script/WalWiki/lib/Yuki/RSS.pm
Suika

Contents of /suikawiki/script/WalWiki/lib/Yuki/RSS.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1.1.1 - (hide annotations) (download) (vendor branch)
Sun Jun 2 04:26:24 2002 UTC (22 years, 10 months ago) by wakaba
Branch: walwiki
CVS Tags: release-2-0-beta1-wal1
Changes since 1.1: +0 -0 lines

1 wakaba 1.1 package Yuki::RSS;
2     use strict;
3     use vars qw($VERSION);
4    
5     $VERSION = '0.2';
6    
7     =head1 NAME
8    
9     Yuki::RSS - The smallest module to generate RSS 1.0.
10     It is downward compatible to XML::RSS.
11    
12     =head1 SYNOPSIS
13    
14     use strict;
15     use Yuki::RSS;
16    
17     my $rss = new Yuki::RSS(
18     version => '1.0',
19     encoding => 'Shift_JIS'
20     );
21    
22     $rss->channel(
23     title => "Site Title",
24     link => "http://url.of.your.site/",
25     description => "The description of your site",
26     );
27    
28     $rss->add_item(
29     title => "Item Title",
30     link => "http://url.of.your/item.html",
31     description => "Yoo, hoo, hoo",
32     );
33    
34     print $rss->as_string;
35    
36     =head1 DESCRIPTION
37    
38     Yuki::RSS is the smallest RSS 1.0 generator.
39     This module helps you to create the minimum document of RSS 1.0.
40     If you need more than that, use XML::RSS.
41    
42     =head1 METHODS
43    
44     =over 4
45    
46     =item new Yuki::RSS (version => $version, encoding => $encoding)
47    
48     Constructor for Yuki::RSS.
49     It returns a reference to a Yuki::RSS object.
50     B<version> must be 1.0.
51     B<encoding> will be inserted output document as a XML encoding.
52     This module does not convert to this encoding.
53    
54     =item add_item (title => $title, link => $link, description => $description)
55    
56     Adds an item to the Yuki::RSS object.
57    
58     =item as_string
59    
60     Returns the RSS string.
61    
62     =item channel (title => $title, link => $link, description => $desc)
63    
64     Channel information of RSS.
65    
66     =head1 SEE ALSO
67    
68     =over 4
69    
70     =item L<XML::RSS>
71    
72     =back
73    
74     =head1 AUTHOR
75    
76     Hiroshi Yuki <hyuki@hyuki.com> http://www.hyuki.com/
77    
78     =head1 LICENSE
79    
80     Copyright (C) 2001 by Hiroshi Yuki.
81    
82     This program is free software; you can redistribute it and/or
83     modify it under the same terms as Perl itself.
84    
85     =cut
86    
87     # The constructor.
88     sub new {
89     my ($class, %hash) = @_;
90     my $self = {
91     version => $hash{version},
92     encoding => $hash{encoding},
93     channel => { },
94     items => [],
95     };
96     return bless $self, $class;
97     }
98    
99     # Setting channel.
100     sub channel {
101     my ($self, %hash) = @_;
102     foreach (keys %hash) {
103     $self->{channel}->{$_} = $hash{$_};
104     }
105     return $self->{channel};
106     }
107    
108     # Adding item.
109     sub add_item {
110     my ($self, %hash) = @_;
111     push(@{$self->{items}}, \%hash);
112     return $self->{items};
113     }
114    
115     #
116     sub as_string {
117     my ($self) = @_;
118     my $doc = <<"EOD";
119     <?xml version="1.0" encoding="$self->{encoding}" ?>
120    
121     <rdf:RDF
122     xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
123     xmlns="http://purl.org/rss/1.0/"
124     >
125    
126     <channel rdf:about="$self->{channel}->{link}">
127     <title>$self->{channel}->{title}</title>
128     <link>$self->{channel}->{link}</link>
129     <description>$self->{channel}->{description}</description>
130     <items>
131     <rdf:Seq>
132     @{[
133     map {
134     qq{<rdf:li rdf:resource="$_->{link}" />}
135     } @{$self->{items}}
136     ]}
137     </rdf:Seq>
138     </items>
139     </channel>
140     @{[
141     map {
142     qq{
143     <item rdf:about="$_->{link}">
144     <title>$_->{title}</title>
145     <link>$_->{link}</link>
146     <description>$_->{description}</description>
147     </item>
148     }
149     } @{$self->{items}}
150     ]}
151     </rdf:RDF>
152     EOD
153     }
154    
155     1;

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24