The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Web::Microformats2::Document - A parsed Microformats2 data structure

DESCRIPTION

An object of this class represents a Microformats2 data structure that has been either parsed from an HTML document or deserialized from JSON.

The expected use-case is that you will construct document objects either via the "parse" in Web::Microformats2::Parser method of Web::Microformats2::Parser, or by this class's "new_from_json" method. Once constructed, we expect you to treat documents as read-only.

See Web::Microformats2 for further context and purpose.

METHODS

Class Methods

new_from_json

 $doc = Web::Microformats2->new_from_json( $json_string )

Given a JSON string containing a properly serialized Microformats2 data structure, returns a Web::Microformats2::Document object.

Object Methods

as_json

 $json = $doc->as_json

Returns a JSON representation of this object, created according to Microformats2 serialization rules.

as_raw_data

 $mf2_data_ref = $doc->as_raw_data

Returns a hash reference containing unblessed data structures that map exactly to the JSON version of this object, as defined by Microformats2 serialization rules. In other words, it contains items, rels, and rel-urls keys, and builds down from there.

Call this if you'd like to parse the Microformats2 metadata out of a document and then work with it at low level, as opposed to (or as well as) using the various convenience methods offered by this class.

Equivalent to calling decode_json() (see "decode_json" in JSON) on the output of as_json.

all_items

 @items = $doc->all_items;

Returns a list of all Web::Microformats2::Item objects this document contains at any level.

all_top_level_items

 @items = $doc->all_top_level_items;

Returns a list of all Web::Microformats2::Item objects this document contains at the top level.

get_first

 $item = $doc->get_first( $item_type );

 # So:
 $entry = $doc->get_first( 'h-entry' );
 # Or...
 $entry = $doc->get_first( 'entry' );

Given a Microformats2 item-type string -- e.g. "h-entry" (or just "entry") -- returns the first item of that type that this document contains (in document order, depth-first).

AUTHOR

Jason McIntosh (jmac@jmac.org)

COPYRIGHT AND LICENSE

This software is Copyright (c) 2018 by Jason McIntosh.

This is free software, licensed under:

  The MIT (X11) License