add example
[catagits/XML-Feed.git] / eg / check_feed.pl
CommitLineData
4fd4f906 1use strict;
2use warnings;
3use v5.10;
4
5=head1 DESCRIPTION
6
7Given a URL of an Atom or RSS feed or a filename of an already downloaded
8feed, this script will try to parse it and print out what it understands
9from the feed.
10
11=cut
12
13use XML::Feed;
14
15my $src = shift;
16
17die "Usage: $0 FILE|URL\n" if not $src;
18
19my $source = $src;
20if ($src =~ m{^https?://}) {
21 $source = URI->new($src);
22} else {
23 if (not -f $source) {
24 die "'$source' does not look like a URL and it does not exist on the file-system either.\n";
25 }
26}
27
28my $feed = XML::Feed->parse( $source ) or die XML::Feed->errstr;
29say 'Title: ' . ($feed->title // '');
30say 'Tagline: ' . ($feed->tagline // '');
31say 'Format: ' . ($feed->format // '');
32say 'Author: ' . ($feed->author // '');
33say 'Link: ' . ($feed->link // '');
34say 'Base: ' . ($feed->base // '');
35say 'Language: ' . ($feed->language // '');
36say 'Copyright: ' . ($feed->copyright // '');
37say 'Modified: ' . ($feed->modified // ''); # DateTime object
38say 'Generator: ' . ($feed->generator // '');
39
40for my $entry ($feed->entries) {
41 say '';
42 say ' Link: ' . ($entry->link // '');
43 say ' Author: ' . ($entry->author // '');
44 say ' Title: ' . ($entry->title // '');
45 say ' Caregory: ' . ($entry->category // '');
46 say ' Id: ' . ($entry->id // '');
47 say ' Issued: ' . ($entry->issued // ''); # DateTime object
48 say ' Modified: ' . ($entry->modified // ''); # DateTime object
49 say ' Lat: ' . ($entry->lat // '');
50 say ' Long: ' . ($entry->long // '');
51 say ' Format: ' . ($entry->format // '');
52 say ' Tags: ' . ($entry->tags // '');
53 say ' Enclosure: ' . ($entry->enclosure // '');
54 say ' Summary: ' . ($entry->summary->body // '');
55 say ' Content: ' . ($entry->content->body // '');
56}
57