1XML::Atom::Feed(3pm)  User Contributed Perl Documentation XML::Atom::Feed(3pm)
2
3
4

NAME

6       XML::Atom::Feed - Atom feed
7

SYNOPSIS

9           use XML::Atom::Feed;
10           use XML::Atom::Entry;
11           my $feed = XML::Atom::Feed->new;
12           $feed->title('My Weblog');
13           $feed->id('tag:example.com,2006:feed-id');
14           my $entry = XML::Atom::Entry->new;
15           $entry->title('First Post');
16           $entry->id('tag:example.com,2006:entry-id');
17           $entry->content('Post Body');
18           $feed->add_entry($entry);
19           $feed->add_entry($entry, { mode => 'insert' });
20
21           my @entries = $feed->entries;
22           my $xml = $feed->as_xml;
23
24           ## Get a list of the <link rel="..." /> tags in the feed.
25           my $links = $feed->link;
26
27           ## Find all of the Atom feeds on a given page, using auto-discovery.
28           my @uris = XML::Atom::Feed->find_feeds('http://www.example.com/');
29
30           ## Use auto-discovery to load the first Atom feed on a given page.
31           my $feed = XML::Atom::Feed->new(URI->new('http://www.example.com/'));
32

USAGE

34   XML::Atom::Feed->new([ $stream ])
35       Creates a new feed object, and if $stream is supplied, fills it with
36       the data specified by $stream.
37
38       Automatically handles autodiscovery if $stream is a URI (see below).
39
40       Returns the new XML::Atom::Feed object. On failure, returns "undef".
41
42       $stream can be any one of the following:
43
44       ·   Reference to a scalar
45
46           This is treated as the XML body of the feed.
47
48       ·   Scalar
49
50           This is treated as the name of a file containing the feed XML.
51
52       ·   Filehandle
53
54           This is treated as an open filehandle from which the feed XML can
55           be read.
56
57       ·   URI object
58
59           This is treated as a URI, and the feed XML will be retrieved from
60           the URI.
61
62           If the content type returned from fetching the content at URI is
63           text/html, this method will automatically try to perform auto-
64           discovery by looking for a <link> tag describing the feed URL. If
65           such a URL is found, the feed XML will be automatically retrieved.
66
67           If the URI is already of a feed, no auto-discovery is necessary,
68           and the feed XML will be retrieved and parsed as normal.
69
70   XML::Atom::Feed->find_feeds($uri)
71       Given a URI $uri, use auto-discovery to find all of the Atom feeds
72       linked from that page (using <link> tags).
73
74       Returns a list of feed URIs.
75
76   $feed->link
77       If called in scalar context, returns an XML::Atom::Link object
78       corresponding to the first <link> tag found in the feed.
79
80       If called in list context, returns a list of XML::Atom::Link objects
81       corresponding to all of the <link> tags found in the feed.
82
83   $feed->add_link($link)
84       Adds the link $link, which must be an XML::Atom::Link object, to the
85       feed as a new <link> tag. For example:
86
87           my $link = XML::Atom::Link->new;
88           $link->type('text/html');
89           $link->rel('alternate');
90           $link->href('http://www.example.com/');
91           $feed->add_link($link);
92
93   $feed->add_entry($entry)
94       Adds the entry $entry, which must be an XML::Atom::Entry object, to the
95       feed. If you want to add an entry before existent entries, you can pass
96       optional hash reference containing "mode" value set to "insert".
97
98         $feed->add_entry($entry, { mode => 'insert' });
99
100   $feed->entries
101       Returns list of XML::Atom::Entry objects contained in the feed.
102
103   $feed->language
104       Returns the language of the feed, from xml:lang.
105
106   $feed->author([ $author ])
107       Returns an XML::Atom::Person object representing the author of the
108       entry, or "undef" if there is no author information present.
109
110       If $author is supplied, it should be an XML::Atom::Person object
111       representing the author. For example:
112
113           my $author = XML::Atom::Person->new;
114           $author->name('Foo Bar');
115           $author->email('foo@bar.com');
116           $feed->author($author);
117
118   $feed->id([ $id ])
119       Returns an id for the feed. If $id is supplied, set the id. When
120       generating the new feed, it is your responsibility to generate unique
121       ID for the feed and set to XML::Atom::Feed object. You can use http
122       permalink, tag URI scheme or urn:uuid for handy.
123

UNICODE FLAGS

125       By default, XML::Atom takes off all the Unicode flag from the feed
126       content. For example,
127
128         my $title = $feed->title;
129
130       the variable $title contains UTF-8 bytes without Unicode flag set, even
131       if the feed title contains some multibyte characters.
132
133       If you don't like this behaviour and wants to handle everything as
134       Unicode characters (rather than UTF-8 bytes), set
135       $XML::Atom::ForceUnicode flag to 1.
136
137         $XML::Atom::ForceUnicode = 1;
138
139       then all the data returned from XML::Atom::Feed object and
140       XML::Atom::Entry object etc., will have Unicode flag set.
141
142       The only exception will be "$entry->content->body", if content type is
143       not text/* (e.g. image/gif). In that case, the content body is still
144       binary data, without Unicode flag set.
145

CREATING ATOM 1.0 FEEDS

147       By default, XML::Atom::Feed and other classes (Entry, Link and Content)
148       will create entities using Atom 0.3 namespaces. In order to create 1.0
149       feed and entry elements, you can set Version as a parameter, like:
150
151         $feed = XML::Atom::Feed->new(Version => 1.0);
152         $entry = XML::Atom::Entry->new(Version => 1.0);
153
154       Setting those Version to every element would be sometimes painful. In
155       that case, you can override the default version number by setting
156       $XML::Atom::DefaultVersion global variable to "1.0".
157
158         use XML::Atom;
159
160         $XML::Atom::DefaultVersion = "1.0";
161
162         my $feed = XML::Atom::Feed->new;
163         $feed->title("blah");
164
165         my $entry = XML::Atom::Entry->new;
166         $feed->add_entry($entry);
167
168         $feed->version; # 1.0
169
171       Please see the XML::Atom manpage for author, copyright, and license
172       information.
173
174
175
176perl v5.32.0                      2020-07-28              XML::Atom::Feed(3pm)
Impressum