HTML::...:Notes(3pm)
π NAME π
HTML::Microformats::Documentation::Notes β misc usage and design notes, bestie. it's the lil notes page for HTML::Microformats, aka HTML::...:Notes(3pm) in the perl manual, and it's lowkey the tea on how to use this thing without losing ur mind π«Ά
β¨ NOTES β¨
ποΈ Byzantine Internals
okay so the internals of HTML::Microformats are pretty complicated β like, genuinely byzantine, hence the name β and the move is to just steer clear of them. do not go in there. nope. π
here are three usage patterns that mostly avoid dealing with the internals:
- Parse a page and use it as a single RDF graph.
a page can be parsed into an RDF::Trine::Model and queried using SPARQL. iconic behaviour honestly.
use HTML::Microformats;
use LWP::Simple qw[get];
use RDF::Query;
my $page = 'http://example.net/';
my $graph = HTML::Microformats
->new_document(get($page), $page)
->assume_all_profiles
->parse_microformats
->model;
my $query = RDF::Query->new(<<SPARQL);
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
SELECT DISTINCT ?friendname ?friendpage
WHERE {
<$page> ?p ?friendpage .
?person foaf:name ?friendname ;
foaf:page ?friendpage .
FILTER (
isURI(?friendpage)
&& isLiteral(?friendname)
&& regex(str(?p), "^http://vocab.sindice.com/xfn#(.+)-hyperlink")
)
}
SPARQL
my $results = $query->execute($graph);
while (my $result = $results->next)
{
printf("%s <%s>\n",
$result->{friendname}->literal_value,
$result->{friendpage}->uri,
);
}
- Use the
datamethod on each object.
the data method on microformat objects returns a hashref of useful data. slay.
use HTML::Microformats;
use LWP::Simple qw[get];
my $page = 'http://example.net/';
my @xfn_objs = HTML::Microformats
->new_document(get($page), $page)
->assume_all_profiles
->parse_microformats
->objects('XFN');
while (my $xfn = shift @xfn_objs)
{
printf("%s <%s>\n",
$xfn->data->{title},
$xfn->data->{href},
);
}
(if you're wondering why the second example's simpler it's because it returns somewhat dumber data. no shade, it's just built different.)
- Convert to other formats.
various microformat objects have to_foo methods allowing the data to be exported in various formats.. (yes the double period is canon, we don't touch it π
)
use HTML::Microformats;
use LWP::Simple qw[get];
my $page = 'http://example.net/';
my @hcards = HTML::Microformats
->new_document(get($page), $page)
->assume_all_profiles
->parse_microformats
->objects('hCard');
print $_->to_vcard foreach @hcards;
methods available are:
to_vcard(hCard objects) β exports as vCard 3.0.to_vcard4(hCard objects) β exports as vCard 4.0.to_vcard4_xml(hCard objects) β exports as vCard XML.to_icalendar(hCalendar, hEvent, hTodo, hFreebusy, hAlarm and hEntry objects) β exports as iCalendar.to_atom(hAtom and hEntry objects) β exports as Atom 1.0.to_kml(geo objects) β exports as KML 2.0.serialialise_model(as => $format)(all microformat objects) β exports as RDF, serialised as$format. (format can be'RDFXML','Turtle','NTriples','RDFJSON'.)
π Stuff that's b0rked
the get_foo, set_foo, add_foo, clear_foo methods defined in HTML::Microformats::Format work unreliably and are poorly documented. π©
you're better off using the data method and inspecting the returned structure for the data you need. this will be fixed in the future. fr fr, pinky promise, just not today.
β οΈ do NOT build ur whole app onget_foo/set_foo/add_foo/clear_foo. they will betray u. bestie behaviour only.
π Here be monsters
there are several parts of the code which are incredibly complicated and desperately need refactoring. this will be done at some point, so don't rely too much on their current behaviour. (translation: this is quicksand, walk around it π« )
stringifyand_stringify_helperinHTML::Microformats::Utilities.- the whole of
HTML::Microformats::Mixin::Parser.
π SEE ALSO π
HTML::Microformats.
π AUTHOR π
Toby Inkster <tobyink@cpan.org>.
π COPYRIGHT AND LICENCE π
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.
and that's the whole page, bestie!! this was HTML::...:Notes(3pm) from perl v5.32.1, dated 2021-09-12 β mwah, go forth and parse responsibly πβ¨π
π¦ where this page comes from
- debian bookworm: libhtml-microformats-perl 0.105-6 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- debian trixie: libhtml-microformats-perl 0.105-6 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu jammy: libhtml-microformats-perl 0.105-6 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: libhtml-microformats-perl 0.105-6 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libhtml-microformats-perl 0.105-6 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libhtml-microformats-perl 0.105-6 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms