| 1 | # $Id$ |
|---|
| 2 | |
|---|
| 3 | package Data::Feed::Atom::Entry; |
|---|
| 4 | use Moose; |
|---|
| 5 | use Data::Feed::Web::Content; |
|---|
| 6 | use List::Util qw( first ); |
|---|
| 7 | use XML::Atom::Util qw( iso2dt ); |
|---|
| 8 | use XML::Atom::Entry; |
|---|
| 9 | |
|---|
| 10 | with 'Data::Feed::Web::Entry'; |
|---|
| 11 | |
|---|
| 12 | has '+entry' => ( |
|---|
| 13 | isa => 'XML::Atom::Entry' |
|---|
| 14 | ); |
|---|
| 15 | |
|---|
| 16 | __PACKAGE__->meta->make_immutable; |
|---|
| 17 | |
|---|
| 18 | no Moose; |
|---|
| 19 | |
|---|
| 20 | sub title { shift->{entry}->title(@_) } |
|---|
| 21 | sub 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 | |
|---|
| 32 | sub 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 | |
|---|
| 45 | sub 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 | |
|---|
| 70 | sub 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 | |
|---|
| 81 | sub 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 | |
|---|
| 92 | sub id { shift->{entry}->id(@_) } |
|---|
| 93 | |
|---|
| 94 | sub 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 | |
|---|
| 103 | sub 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 | |
|---|
| 112 | sub enclosures { |
|---|
| 113 | confess "FIX ME!!!!!"; |
|---|
| 114 | } |
|---|
| 115 | |
|---|
| 116 | 1; |
|---|
| 117 | |
|---|
| 118 | __END__ |
|---|
| 119 | |
|---|
| 120 | =head1 NAME |
|---|
| 121 | |
|---|
| 122 | Data::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 | |
|---|