HTML::Microformats(3pm) | User Contributed Perl Documentation | HTML::Microformats(3pm) |
HTML::Microformats - parse microformats in HTML
use HTML::Microformats; my $doc = HTML::Microformats ->new_document($html, $uri) ->assume_profile(qw(hCard hCalendar)); print $doc->json(pretty => 1); use RDF::TrineShortcuts qw(rdf_query); my $results = rdf_query($sparql, $doc->model);
The HTML::Microformats module is a wrapper for parser and handler modules of various individual microformats (each of those modules has a name like HTML::Microformats::Format::Foo).
The general pattern of usage is to create an HTML::Microformats object (which corresponds to an HTML document) using the "new_document" method; then ask for the data, as a Perl hashref, a JSON string, or an RDF::Trine model.
$html is the HTML or XHTML source (string) or an XML::LibXML::Document.
$uri is the document URI, important for resolving relative URL references.
%opts are additional parameters; currently only one option is defined: $opts{'type'} is set to 'text/html' or 'application/xhtml+xml', to control how $html is parsed.
HTML::Microformats uses HTML profiles (i.e. the profile attribute on the HTML <head> element) to detect which Microformats are used on a page. Any microformats which do not have a profile URI declared will not be parsed.
Because many pages fail to properly declare which profiles they use, there are various profile management methods to tell HTML::Microformats to assume the presence of particular profile URIs, even if they're actually missing.
For example:
$doc->add_profile('http://microformats.org/profile/rel-tag')
This is useful for adding profile URIs declared outside the document itself (e.g. in HTTP headers).
Returns a reference to the document.
$doc->assume_profile(qw(hCard adr geo))
This method acts similarly to "add_profile" 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.
Returns a reference to the document.
Returns a reference to the document.
Generally speaking, you can skip this. The "data", "json" and "model" methods will automatically do this for you.
On subsequent calls, does nothing (as everything is already parsed).
Returns a reference to the document.
Returns a reference to the document.
These methods allow you to retrieve the document's data, and do things with it.
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 relevant documentation for details.
Each object is, for example, an HTML::Microformat::hCard object, or an HTML::Microformat::RelTag object, etc. See the relevant documentation for details.
%opts is a hash of options, suitable for passing to the JSON 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 $doc->json( pretty=>1, canonical=>1, utf8=>0 );
Returns a reference to the document.
There already exist two microformats packages on CPAN (see Text::Microformat and Data::Microformat), so why create another?
Firstly, HTML::Microformats isn't being created from scratch. It's actually a fork/clean-up of a non-CPAN application (Swignition), and in that sense predates Text::Microformat (though not Data::Microformat).
It has a number of other features that distinguish it from the existing packages:
HTML::Microformats supports hCard, hCalendar, rel-tag, geo, adr, rel-enclosure, rel-license, hReview, hResume, hRecipe, xFolk, XFN, hAtom, hNews and more.
HTML::Microformats supports the include pattern, abbr pattern, table cell header pattern, value excerpting and other intricacies of microformat parsing better than the other modules on CPAN.
One of the key features of HTML::Microformats is that it makes data available as RDF::Trine models. This allows your application to benefit from a rich, feature-laden Semantic Web toolkit. Data gleaned from microformats can be stored in a triple store; output in RDF/XML or Turtle; queried using the SPARQL or RDQL query languages; and more.
If you're not comfortable using RDF, HTML::Microformats also makes all its data available as native Perl objects.
Please report any bugs to <http://rt.cpan.org/>.
HTML::Microformats::Documentation::Notes.
Individual format modules:
Similar modules: RDF::RDFa::Parser, HTML::HTML5::Microdata::Parser, XML::Atom::Microformats, Text::Microformat, Data::Microformats.
Related web sites: <http://microformats.org/>, <http://www.perlrdf.org/>.
Toby Inkster <tobyink@cpan.org>.
Copyright 2008-2012 Toby Inkster
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
2021-09-12 | perl v5.32.1 |