SYNOPSIS

 use XML::Atom::Microformats;

 my $feed = XML::Atom::Microformats
    -> new_feed( $xml, $base_uri )
    -> assume_profile( qw(hCard hCalendar) );
 print $feed->json(pretty => 1);

 my $results = RDF::Query
    -> new( $sparql )
    -> execute( $feed->model );

DESCRIPTION

The XML::Atom::Microformats module brings the functionality of HTML::Microformats to Atom 1.0 Syndication feeds. It finds microformats embedded in the <content> elements (note: not <summary>) of Atom entries.

The general pattern of usage is to create an XML::Atom::Microformats object (which corresponds to an Atom 1.0 feed) using the \*(C`new_feed\*(C' method; tell it which types of Microformat you expect to find there; then ask for the data, as a Perl hashref, a \s-1JSON\s0 string, or an RDF::Trine model.

Constructor

Constructs a feed object. $xml is the Atom source (string) or an XML::LibXML::Document. $base_url is the feed \s-1URL\s0, important for resolving relative \s-1URL\s0 references.

Profile Management Methods

HTML::Microformats uses \s-1HTML\s0 profiles (i.e. the profile attribute on the \s-1HTML\s0 <head> element) to detect which Microformats are used on a page. Any microformats which do not have a profile \s-1URI\s0 declared will not be parsed.

XML::Atom::Microformats uses a similar mechanism. Because Atom does not have a <head> element, Atom <link> is used instead:

<link rel="profile" href="http://ufs.cc/x/hcalendar" />

These links can be used on a per-entry basis, or for the whole feed.

Because many feeds fail to properly declare which profiles they use, there are various profile management methods to tell XML::Atom::Microformats to assume the presence of particular profile URIs, even if they're actually missing. Using \*(C`add_profile\*(C' you can add one or more profile URIs, and they are treated as if they were found on the document. For example: $feed->add_profile('http://microformats.org/profile/rel-tag') This is useful for adding profile URIs declared outside the document itself (e.g. in \s-1HTTP\s0 headers). \*(C`entry_add_profile\*(C' is a variant to allow you to add a profile which applies only to one specific entry within the feed, if you know that entry's \s-1ID\s0. For example: $feed->assume_profile(qw(hCard adr geo)) This method acts similarly to \*(C`add_profile\*(C' but allows you to use names of microformats rather than URIs. Microformat names are case sensitive, and must match HTML::Microformats::Format::Foo module names. \*(C`entry_assume_profile\*(C' is a variant to allow you to add a profile which applies only to one specific entry within the feed, if you know that entry's \s-1ID\s0. This method is equivalent to calling \*(C`assume_profile\*(C' for all known microformats. This method is equivalent to calling \*(C`entry_assume_profile\*(C' for all known microformats.

Parsing Methods

You can probably skip this section. The \*(C`data\*(C', \*(C`json\*(C' and \*(C`model\*(C' methods will automatically do this for you. Scans through the feed, finding microformat objects. On subsequent calls, does nothing (as everything is already parsed). Forgets information gleaned by \*(C`parse_microformats\*(C' and thus allows \*(C`parse_microformats\*(C' to be run again. This is useful if you've added some profiles between runs of \*(C`parse_microformats\*(C'.

Data Retrieval Methods

These methods allow you to retrieve the feed's data, and do things with it. $format is, for example, 'hCard', 'adr' or 'RelTag'. Returns a list of objects of that type. (If called in scalar context, returns an arrayref.) Each object is, for example, an HTML::Microformat::hCard object, or an HTML::Microformat::RelTag object, etc. See the relevent documentation for details. \*(C`entry_objects\*(C' is a variant to allow you to fetch data for one specific entry within the feed, if you know that entry's \s-1ID\s0. Returns a hashref of data. Each hashref key is the name of a microformat (e.g. 'hCard', 'RelTag', etc), and the values are arrayrefs of objects. Each object is, for example, an HTML::Microformat::hCard object, or an HTML::Microformat::RelTag object, etc. See the relevent documentation for details. \*(C`entry_all_objects\*(C' is a variant to allow you to fetch data for one specific entry within the feed, if you know that entry's \s-1ID\s0. Returns data roughly equivalent to the \*(C`all_objects\*(C' method, but as a \s-1JSON\s0 string. %opts is a hash of options, suitable for passing to the \s-1JSON\s0 module's to_json function. The 'convert_blessed' and 'utf8' options are enabled by default, but can be disabled by explicitly setting them to 0, e.g. print $feed->json( pretty=>1, canonical=>1, utf8=>0 ); \*(C`entry_json\*(C' is a variant to allow you to fetch data for one specific entry within the feed, if you know that entry's \s-1ID\s0. Returns data as an RDF::Trine::Model, suitable for serialising as \s-1RDF\s0 or running \s-1SPARQL\s0 queries. Quads are used (rather than triples) which allows you to trace statements to the entries from which they came. $opts{'atomowl'} is a boolean indicating whether or not to include data from XML::Atom::OWL in the returned model. If enabled, this always includes AtomOWL data for the whole feed (not just for a specific entry), even if you use the \*(C`entry_model\*(C' method. If RDF::RDFa::Parser 1.096 or above is installed, then $opts{'atomowl'} will automatically pull in DataRSS data too. \*(C`entry_model\*(C' is a variant to allow you to fetch data for one specific entry within the feed, if you know that entry's \s-1ID\s0. Adds data to an existing RDF::Trine::Model. Otherwise, the same as \*(C`model\*(C'. Adds data to an existing RDF::Trine::Model. Otherwise, the same as \*(C`entry_model\*(C'.

BUGS

Please report any bugs to <http://rt.cpan.org/>.

RELATED TO XML::Atom::Microformats…

HTML::Microformats, XML::Atom::OWL, XML::Atom::FromOWL, RDF::RDFa::Parser.

<http://microformats.org/>, <http://www.perlrdf.org/>.

AUTHOR

Toby Inkster <[email protected]>.

COPYRIGHT

Copyright 2010-2012 Toby Inkster

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

DISCLAIMER OF WARRANTIES

\s-1THIS\s0 \s-1PACKAGE\s0 \s-1IS\s0 \s-1PROVIDED\s0 \*(L"\s-1AS\s0 \s-1IS\s0\*(R" \s-1AND\s0 \s-1WITHOUT\s0 \s-1ANY\s0 \s-1EXPRESS\s0 \s-1OR\s0 \s-1IMPLIED\s0 \s-1WARRANTIES\s0, \s-1INCLUDING\s0, \s-1WITHOUT\s0 \s-1LIMITATION\s0, \s-1THE\s0 \s-1IMPLIED\s0 \s-1WARRANTIES\s0 \s-1OF\s0 \s-1MERCHANTIBILITY\s0 \s-1AND\s0 \s-1FITNESS\s0 \s-1FOR\s0 A \s-1PARTICULAR\s0 \s-1PURPOSE\s0.