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