Load XML-Feed-0.05 into trunk.
[catagits/XML-Feed.git] / lib / XML / Feed / Atom.pm
1 # $Id: Atom.pm 942 2004-12-31 23:01:21Z btrott $
2
3 package XML::Feed::Atom;
4 use strict;
5
6 use base qw( XML::Feed );
7 use XML::Atom::Feed;
8 use XML::Atom::Util qw( iso2dt );
9 use List::Util qw( first );
10
11 sub init_string {
12     my $feed = shift;
13     my($str) = @_;
14     if ($str) {
15         $feed->{atom} = XML::Atom::Feed->new(Stream => $str)
16             or return $feed->error(XML::Atom::Feed->errstr);
17     }
18     $feed;
19 }
20
21 sub format { 'Atom' }
22
23 sub title { $_[0]->{atom}->title }
24 sub link {
25     my $l = first { $_->rel eq 'alternate' } $_[0]->{atom}->link;
26     $l ? $l->href : undef;
27 }
28 sub description { $_[0]->{atom}->tagline }
29 sub copyright { $_[0]->{atom}->copyright }
30 sub language { $_[0]->{atom}->language }
31 sub generator { $_[0]->{atom}->generator }
32 sub author { $_[0]->{atom}->author ? $_[0]->{atom}->author->name : undef }
33 sub modified { iso2dt($_[0]->{atom}->modified) }
34
35 sub entries { 
36     my @entries;
37     for my $entry ($_[0]->{atom}->entries) {
38         push @entries, XML::Feed::Atom::Entry->wrap($entry);
39     }
40     @entries;
41 }
42
43 package XML::Feed::Atom::Entry;
44 use strict;
45
46 use base qw( XML::Feed::Entry );
47 use XML::Atom::Util qw( iso2dt );
48 use XML::Feed::Content;
49 use List::Util qw( first );
50
51 sub title { $_[0]->{entry}->title }
52 sub link {
53     my $l = first { $_->rel eq 'alternate' } $_[0]->{entry}->link;
54     $l ? $l->href : undef;
55 }
56
57 sub summary {
58     XML::Feed::Content->wrap({ type => 'text/html',
59                                body => $_[0]->{entry}->summary });
60 }
61
62 sub content {
63     my $c = $_[0]->{entry}->content;
64     XML::Feed::Content->wrap({ type => $c ? $c->type : undef,
65                                body => $c ? $c->body : undef });
66 }
67
68 sub category {
69     my $ns = XML::Atom::Namespace->new(dc => 'http://purl.org/dc/elements/1.1/');
70     $_[0]->{entry}->get($ns, 'subject');
71 }
72
73 sub author { $_[0]->{entry}->author ? $_[0]->{entry}->author->name : undef }
74 sub id { $_[0]->{entry}->id }
75 sub issued { iso2dt($_[0]->{entry}->issued) }
76 sub modified { iso2dt($_[0]->{entry}->modified) }
77
78 1;