NAME

HTML::Microformats::DocumentContext - context for microformat objects

DESCRIPTION

Microformat objects need context when being parsed to properly make sense. For example, a base URI is needed to resolve relative URI references, and a full copy of the DOM tree is needed to implement the include pattern.

Constructor

$context = HTML::Microformats::DocumentContext->new($dom, $baseuri)

Creates a new context from a DOM document and a base URI.

$dom will be modified, so if you care about keeping it pristine, make a clone first.

Public Methods

$context->cache

A Microformat cache for the context. This prevents the same microformat object from being parsed and reparsed - e.g. an adr parsed first in its own right, and later as a child of an hCard.

$context->document

Return the modified DOM document.

$context->uri( [$relative_reference] )

Called without a parameter, returns the context's base URI.

Called with a parameter, resolves the URI reference relative to the base URI.

$context->document_uri

Returns a URI representing the document itself. (Usually the same as the base URI.)

$context->make_bnode( [$element] )

Mint a blank node identifier or a URI.

If an element is passed, this may be used to construct a URI in some way.

$context->profiles

A list of profile URIs declared by the document.

$context->has_profile(@profiles)

Returns true iff any of the profiles in the array are declared by the document.

$context->add_profile(@profiles)

Declare these additional profiles.

$context->representative_hcard

Returns the hCard for the person that is "represented by" the page (in the XFN sense), or undef if no suitable hCard could be found

$context->representative_person_id( [$as_trine] )

Equivalent to calling $context->representative_hcard->id($as_trine, 'holder'), however magically works even if $context->representative_hcard returns undef.

$context->contact_hcard

Returns the hCard for the contact person for the page, or undef if none can be found.

hCards are considered potential contact hCards if they are contained within an HTML <address> tag, or their root element is an <address> tag. If there are several such hCards, then the one in the shallowest <address> tag is used; if there are several <address> tags equally shallow, the first is used.

$context->contact_person_id( [$as_trine] )

Equivalent to calling $context->contact_hcard->id($as_trine, 'holder'), however magically works even if $context->contact_hcard returns undef.

BUGS

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

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.

DISCLAIMER OF WARRANTIES

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.