| 1 |
|
|---|
| 2 |
|
|---|
| 3 |
package XML::Atom::Entry; |
|---|
| 4 |
use strict; |
|---|
| 5 |
|
|---|
| 6 |
use XML::Atom; |
|---|
| 7 |
use base qw( XML::Atom::Thing ); |
|---|
| 8 |
use MIME::Base64 qw( encode_base64 decode_base64 ); |
|---|
| 9 |
use XML::Atom::Person; |
|---|
| 10 |
use XML::Atom::Content; |
|---|
| 11 |
use XML::Atom::Util qw( first ); |
|---|
| 12 |
|
|---|
| 13 |
sub element_name { 'entry' } |
|---|
| 14 |
|
|---|
| 15 |
sub content { |
|---|
| 16 |
my $entry = shift; |
|---|
| 17 |
if (my @arg = @_) { |
|---|
| 18 |
if (ref($arg[0]) ne 'XML::Atom::Content') { |
|---|
| 19 |
$arg[0] = XML::Atom::Content->new(Body => $arg[0], Version => $entry->version); |
|---|
| 20 |
} |
|---|
| 21 |
$entry->set($entry->ns, 'content', @arg); |
|---|
| 22 |
} else { |
|---|
| 23 |
return $entry->get_object($entry->ns, 'content', 'XML::Atom::Content'); |
|---|
| 24 |
} |
|---|
| 25 |
} |
|---|
| 26 |
|
|---|
| 27 |
__PACKAGE__->mk_elem_accessors(qw( summary source )); |
|---|
| 28 |
|
|---|
| 29 |
__PACKAGE__->_rename_elements('issued' => 'published'); |
|---|
| 30 |
__PACKAGE__->_rename_elements('modified' => 'updated'); |
|---|
| 31 |
|
|---|
| 32 |
|
|---|
| 33 |
__PACKAGE__->mk_elem_accessors(qw( created )); |
|---|
| 34 |
|
|---|
| 35 |
1; |
|---|
| 36 |
__END__ |
|---|
| 37 |
|
|---|
| 38 |
=head1 NAME |
|---|
| 39 |
|
|---|
| 40 |
XML::Atom::Entry - Atom entry |
|---|
| 41 |
|
|---|
| 42 |
=head1 SYNOPSIS |
|---|
| 43 |
|
|---|
| 44 |
use XML::Atom::Entry; |
|---|
| 45 |
my $entry = XML::Atom::Entry->new; |
|---|
| 46 |
$entry->title('My Post'); |
|---|
| 47 |
$entry->content('The content of my post.'); |
|---|
| 48 |
my $xml = $entry->as_xml; |
|---|
| 49 |
my $dc = XML::Atom::Namespace->new(dc => 'http://purl.org/dc/elements/1.1/'); |
|---|
| 50 |
$entry->set($dc, 'subject', 'Food & Drink'); |
|---|
| 51 |
|
|---|
| 52 |
=head1 USAGE |
|---|
| 53 |
|
|---|
| 54 |
=head2 XML::Atom::Entry->new([ $stream ]) |
|---|
| 55 |
|
|---|
| 56 |
Creates a new entry object, and if I<$stream> is supplied, fills it with the |
|---|
| 57 |
data specified by I<$stream>. |
|---|
| 58 |
|
|---|
| 59 |
Automatically handles autodiscovery if I<$stream> is a URI (see below). |
|---|
| 60 |
|
|---|
| 61 |
Returns the new I<XML::Atom::Entry> object. On failure, returns C<undef>. |
|---|
| 62 |
|
|---|
| 63 |
I<$stream> can be any one of the following: |
|---|
| 64 |
|
|---|
| 65 |
=over 4 |
|---|
| 66 |
|
|---|
| 67 |
=item * Reference to a scalar |
|---|
| 68 |
|
|---|
| 69 |
This is treated as the XML body of the entry. |
|---|
| 70 |
|
|---|
| 71 |
=item * Scalar |
|---|
| 72 |
|
|---|
| 73 |
This is treated as the name of a file containing the entry XML. |
|---|
| 74 |
|
|---|
| 75 |
=item * Filehandle |
|---|
| 76 |
|
|---|
| 77 |
This is treated as an open filehandle from which the entry XML can be read. |
|---|
| 78 |
|
|---|
| 79 |
=back |
|---|
| 80 |
|
|---|
| 81 |
=head2 $entry->content([ $content ]) |
|---|
| 82 |
|
|---|
| 83 |
Returns the content of the entry. If I<$content> is given, sets the content |
|---|
| 84 |
of the entry. Automatically handles all necessary escaping. |
|---|
| 85 |
|
|---|
| 86 |
=head2 $entry->author([ $author ]) |
|---|
| 87 |
|
|---|
| 88 |
Returns an I<XML::Atom::Person> object representing the author of the entry, |
|---|
| 89 |
or C<undef> if there is no author information present. |
|---|
| 90 |
|
|---|
| 91 |
If I<$author> is supplied, it should be an I<XML::Atom::Person> object |
|---|
| 92 |
representing the author. For example: |
|---|
| 93 |
|
|---|
| 94 |
my $author = XML::Atom::Person->new; |
|---|
| 95 |
$author->name('Foo Bar'); |
|---|
| 96 |
$author->email('foo@bar.com'); |
|---|
| 97 |
$entry->author($author); |
|---|
| 98 |
|
|---|
| 99 |
=head2 $entry->link |
|---|
| 100 |
|
|---|
| 101 |
If called in scalar context, returns an I<XML::Atom::Link> object |
|---|
| 102 |
corresponding to the first I<E<lt>linkE<gt>> tag found in the entry. |
|---|
| 103 |
|
|---|
| 104 |
If called in list context, returns a list of I<XML::Atom::Link> objects |
|---|
| 105 |
corresponding to all of the I<E<lt>linkE<gt>> tags found in the entry. |
|---|
| 106 |
|
|---|
| 107 |
=head2 $entry->add_link($link) |
|---|
| 108 |
|
|---|
| 109 |
Adds the link I<$link>, which must be an I<XML::Atom::Link> object, to |
|---|
| 110 |
the entry as a new I<E<lt>linkE<gt>> tag. For example: |
|---|
| 111 |
|
|---|
| 112 |
my $link = XML::Atom::Link->new; |
|---|
| 113 |
$link->type('text/html'); |
|---|
| 114 |
$link->rel('alternate'); |
|---|
| 115 |
$link->href('http://www.example.com/2003/12/post.html'); |
|---|
| 116 |
$entry->add_link($link); |
|---|
| 117 |
|
|---|
| 118 |
=head2 $entry->get($ns, $element) |
|---|
| 119 |
|
|---|
| 120 |
Given an I<XML::Atom::Namespace> element I<$ns> and an element name |
|---|
| 121 |
I<$element>, retrieves the value for the element in that namespace. |
|---|
| 122 |
|
|---|
| 123 |
This is useful for retrieving the value of elements not in the main Atom |
|---|
| 124 |
namespace, like categories. For example: |
|---|
| 125 |
|
|---|
| 126 |
my $dc = XML::Atom::Namespace->new(dc => 'http://purl.org/dc/elements/1.1/'); |
|---|
| 127 |
my $subj = $entry->get($dc, 'subject'); |
|---|
| 128 |
|
|---|
| 129 |
=head2 $entry->getlist($ns, $element) |
|---|
| 130 |
|
|---|
| 131 |
Just like I<$entry-E<gt>get>, but if there are multiple instances of the |
|---|
| 132 |
element I<$element> in the namespace I<$ns>, returns all of them. I<get> |
|---|
| 133 |
will return only the first. |
|---|
| 134 |
|
|---|
| 135 |
=head1 AUTHOR & COPYRIGHT |
|---|
| 136 |
|
|---|
| 137 |
Please see the I<XML::Atom> manpage for author, copyright, and license |
|---|
| 138 |
information. |
|---|
| 139 |
|
|---|
| 140 |
=cut |
|---|
| 141 |
|
|---|