root/lang/perl/Data-Feed/trunk/lib/Data/Feed/Atom/Entry.pm @ 16241

Revision 16241, 3.2 kB (checked in by daisuke, 6 years ago)

fix test count, fix constructor calls

  • Property svn:keywords set to Id
Line 
1# $Id$
2
3package Data::Feed::Atom::Entry;
4use Moose;
5use Data::Feed::Web::Content;
6use List::Util qw( first );
7use XML::Atom::Util qw( iso2dt );
8use XML::Atom::Entry;
9
10with 'Data::Feed::Web::Entry';
11
12has '+entry' => (
13    isa => 'XML::Atom::Entry'
14);
15
16__PACKAGE__->meta->make_immutable;
17
18no Moose;
19
20sub title { shift->{entry}->title(@_) }
21sub link {
22    my $entry = shift;
23    if (@_) {
24        $entry->{entry}->add_link({ rel => 'alternate', href => $_[0],
25                                    type => 'text/html', });
26    } else {
27        my $l = first { !defined $_->rel || $_->rel eq 'alternate' } $entry->{entry}->link;
28        $l ? $l->href : undef;
29    }
30}
31
32sub summary {
33    my $entry = shift;
34    if (@_) {
35        $entry->{entry}->summary(
36            blessed $_[0] && $_[0]->isa('Data:::Feed::Web::Content') ?
37                $_[0]->body : $_[0]
38        );
39    } else {
40        Data::Feed::Web::Content->wrap({ type => 'html',
41                                   body => $entry->{entry}->summary });
42    }
43}
44
45sub content {
46    my $entry = shift;
47    if (@_) {
48        my %param;
49        if (blessed $_[0] && $_[0]->isa('Data::Feed::Web::Content')) {
50            %param = (Body => $_[0]->body);
51        } else {
52            %param = (Body => $_[0]);
53        }
54        $entry->{entry}->content(XML::Atom::Content->new(%param, Version => 1.0));
55    } else {
56        my $c = $entry->{entry}->content;
57
58        # map Atom types to MIME types
59        my $type = $c ? $c->type : undef;
60        if ($type) {
61            $type = 'text/html'  if $type eq 'xhtml' || $type eq 'html';
62            $type = 'text/plain' if $type eq 'text';
63        }
64
65        Data::Feed::Web::Content->wrap({ type => $type,
66                                   body => $c ? $c->body : undef });
67    }
68}
69
70sub category {
71    my $entry = shift;
72    my $ns = XML::Atom::Namespace->new(dc => 'http://purl.org/dc/elements/1.1/');
73    if (@_) {
74        $entry->{entry}->add_category({ term => $_[0] });
75    } else {
76        my $category = $entry->{entry}->category;
77        $category ? ($category->label || $category->term) : $entry->{entry}->get($ns, 'subject');
78    }
79}
80
81sub author {
82    my $entry = shift;
83    if (@_ && $_[0]) {
84        my $person = XML::Atom::Person->new(Version => 1.0);
85        $person->name($_[0]);
86        $entry->{entry}->author($person);
87    } else {
88        $entry->{entry}->author ? $entry->{entry}->author->name : undef;
89    }
90}
91
92sub id { shift->{entry}->id(@_) }
93
94sub issued {
95    my $entry = shift;
96    if (@_) {
97        $entry->{entry}->issued(DateTime::Format::W3CDTF->format_datetime($_[0])) if $_[0];
98    } else {
99        $entry->{entry}->issued ? iso2dt($entry->{entry}->issued) : undef;
100    }
101}
102
103sub modified {
104    my $entry = shift;
105    if (@_) {
106        $entry->{entry}->modified(DateTime::Format::W3CDTF->format_datetime($_[0])) if $_[0];
107    } else {
108        $entry->{entry}->modified ? iso2dt($entry->{entry}->modified) : undef;
109    }
110}
111
112sub enclosures {
113    confess "FIX ME!!!!!";
114}
115
1161;
117
118__END__
119
120=head1 NAME
121
122Data::Feed::Atom::Entry - An Atom Entry
123
124=head1 METHODS
125
126=head2 author
127
128=head2 category
129
130=head2 content
131
132=head2 enclosures
133
134=head2 id
135
136=head2 issued
137
138=head2 link
139
140=head2 modified
141
142=head2 summary
143
144=head2 title
145
146=cut
147
Note: See TracBrowser for help on using the browser.