=head1 NAME

HTML::Microformats::Documentation::Notes - misc usage and design notes

=head1 NOTES

=head2 Byzantine Internals

The internals of HTML::Microformats are pretty complicated - best to steer clear
of them. Here are three usage patterns that avoid dealing with the internals:

=over

=item * B<Parse a page and use it as a single RDF graph.>

A page can be parsed into an L<RDF::Trine::Model> and queried
using SPARQL.

	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,
			);
	}

=item * B<Use the data method on each object.>

The C<data> method on microformat objects returns a hashref of useful data.

	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.)

=back

=head2 Things that would be nice

Convert an hCard to a vCard; hCalendar to iCalendar; hAtom to Atom and so
forth.

Ideal way would be to create a separate vCard-RDF to vCard module, and then
have HTML::Microformats::Format::hCard hook into that. And equivalent for
other formats.

=head2 Stuff that's b0rked

The C<get_foo>, C<set_foo>, C<add_foo>, C<clear_foo> methods defined in
L<HTML::Microformats::Format> work unreliably and are poorly documented.
You're better off using the C<data> method and inspecting the returned structure
for the data you need. This will be fixed in the future.

=head2 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.

C<stringify> and C<_stringify_helper> in L<HTML::Microformats::Utilities>.
The whole of L<HTML::Microformats::Mixin::Parser>.

=head1 SEE ALSO

L<HTML::Microformats>.

=head1 AUTHOR

Toby Inkster E<lt>tobyink@cpan.orgE<gt>.

=head1 COPYRIGHT

Copyright 2008-2010 Toby Inkster

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

=cut
