# $Id: Entry.pm,v 1.1 2005/04/15 17:37:32 bradfitz Exp $ package XML::Atom::Entry; use strict; use XML::Atom; use base qw( XML::Atom::Thing ); use MIME::Base64 qw( encode_base64 decode_base64 ); use XML::Atom::Person; use XML::Atom::Content; use XML::Atom::Util qw( first ); use constant NS => 'http://purl.org/atom/ns#'; sub element_name { 'entry' } sub content { my $entry = shift; my @arg = @_; if (@arg && ref($arg[0]) ne 'XML::Atom::Content') { $arg[0] = XML::Atom::Content->new($arg[0]); } $entry->_element('XML::Atom::Content', 'content', @arg); } 1; __END__ =head1 NAME XML::Atom::Entry - Atom entry =head1 SYNOPSIS use XML::Atom::Entry; my $entry = XML::Atom::Entry->new; $entry->title('My Post'); $entry->content('The content of my post.'); my $xml = $entry->as_xml; my $dc = XML::Atom::Namespace->new(dc => 'http://purl.org/dc/elements/1.1/'); $entry->set($dc, 'subject', 'Food & Drink'); =head1 USAGE =head2 XML::Atom::Entry->new([ $stream ]) Creates a new entry object, and if I<$stream> is supplied, fills it with the data specified by I<$stream>. Automatically handles autodiscovery if I<$stream> is a URI (see below). Returns the new I object. On failure, returns C. I<$stream> can be any one of the following: =over 4 =item * Reference to a scalar This is treated as the XML body of the entry. =item * Scalar This is treated as the name of a file containing the entry XML. =item * Filehandle This is treated as an open filehandle from which the entry XML can be read. =back =head2 $entry->content([ $content ]) Returns the content of the entry. If I<$content> is given, sets the content of the entry. Automatically handles all necessary escaping. =head2 $entry->author([ $author ]) Returns an I object representing the author of the entry, or C if there is no author information present. If I<$author> is supplied, it should be an I object representing the author. For example: my $author = XML::Atom::Person->new; $author->name('Foo Bar'); $author->email('foo@bar.com'); $entry->author($author); =head2 $entry->link If called in scalar context, returns an I object corresponding to the first IlinkE> tag found in the entry. If called in list context, returns a list of I objects corresponding to all of the IlinkE> tags found in the entry. =head2 $entry->add_link($link) Adds the link I<$link>, which must be an I object, to the entry as a new IlinkE> tag. For example: my $link = XML::Atom::Link->new; $link->type('text/html'); $link->rel('alternate'); $link->href('http://www.example.com/2003/12/post.html'); $entry->add_link($link); =head2 $entry->get($ns, $element) Given an I element I<$ns> and an element name I<$element>, retrieves the value for the element in that namespace. This is useful for retrieving the value of elements not in the main Atom namespace, like categories. For example: my $dc = XML::Atom::Namespace->new(dc => 'http://purl.org/dc/elements/1.1/'); my $subj = $entry->get($dc, 'subject'); =head2 $entry->getlist($ns, $element) Just like I<$entry-Eget>, but if there are multiple instances of the element I<$element> in the namespace I<$ns>, returns all of them. I will return only the first. =head1 AUTHOR & COPYRIGHT Please see the I manpage for author, copyright, and license information. =cut