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

NAME

Web::Microformats2::Item - A parsed Microformats2 item

DESCRIPTION

An object of this class represents a Microformats2 item, contained within a larger, parsed Microformats2 data structure. An item represents a single semantically meaningful something-or-other: an article, a person, a photograph, et cetera.

The expected use-case is that you will never directly construct item objects. Instead, your code will receive item objects by querying a Web::Microformats2::Document instance, itself created by running Microformats2-laden HTML or JSON through a Web::Microformats2::Parser object.

See Web::Microformats2 for further context and purpose.

METHODS

Object Methods

get_properties

 $properties_ref = $item->get_properties( $property_key )

 # To get all "u-url" properties of this item:
 $urls = $item->get_properties( 'url' );
 # To get all "p-name" properties:
 $names = $item->get_properties( 'name' );

Returns a list reference of all property values identified by the given key. Values can be strings, unblessed references, or more item objects.

Note that Microformats2 stores its properties' keys without their prefixes, so that's how you should query for them here. In order words, pass in "name" or "url" as an argument, not "p-name" or "u-url".

get_property

 $property_value = $item->get_property( $property_key );

 # To get the first (and maybe only?) "u-url" property of this item:
 $url = $item->get_property( 'url' );
 # To get its "p-name" property:
 $name = $item->get_property( 'name' );

Like "get_properties", but returns only the first property value identified by the given key.

If this item contains more than one such value, this will also emit a warning.

value

 $value = $item->value;

Returns the special value attribute, if this item has it defined.

all_types

 my @types = $item->all_types;
 # Returns e.g. ( 'h-org', 'h-card' )

 my @short_types = $item->all_types( no_prefixes =>  1 );
 # Returns e.g. ( 'org', 'card' )

Returns a list of all the types that this item identifies as. Guaranteed to contain at least one value.

Takes an argument hash, which recognizes the following single key:

no_prefixes

If set to a true value, then this object will remove the prefixes from the list of item types before returning it to you. Practically speaking, this means that it will remove the leading h- from every type.

has_type

 $bool = $item->has_type( $type )

Returns true if the item claims to be of the given type, false otherwise. (The argument can include a prefix, so e.g. both "entry" and "h-entry" return the same result here.)

parent

 $parent = $item->parent;

Returns this item's parent item, if set.

children

 $children_ref = $item->children;

Returns a list reference of child items.

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