NAME

HTML::Parser::Simple::Attributes - a simple HTML attribute parser

Synopsis

Note: This module assumes the attributes belong to a start tag.

my($parser) = HTML::Parser::Simple::Attributes -> new(' height="20" width="20"');

# Get all the attributes as a hashref.

my($attr_href) = $parser -> get_attr;

# Get the value of a specific attribute.

my($height) = $parser -> get_attr('height');

Methods

get_attr([$name])

The [] indicate an optional parameter.

my($attrs_ref) = $parser -> get_attr;
my($val)       = $parser -> get_attr('attr_name');

If you don't pass in an attribute name, returns a hash ref with the attribute names as keys and the attribute values as the values.

If you pass in an attribute name, it will return the value for just that attribute.

Return undef if you supply the name of a non-existant attribute.

parse_attributes($attr_string)

$attr_href = $parser -> parse_attributes($attr_string);
$attr_href = HTML::Parser::Simple::Attributes -> parse_attributes($attr_string);

Parses a string of HTML attributes and returns the result as a hash ref, or dies if the string is a valid attribute string. Attribute values may be quoted with double quotes or single quotes.

Quotes may be omitted if there are no spaces in the value.

Returns an empty hashref if $attr_string is not supplied.

This method may also be called as a class method.

Author

HTML::Parser::Simple::Attributes was written by Mark Stosberg <mark@summersault.com> in 2009.

Home page: http://mark.stosberg.com/

Copyright

Copyright (c) 2009 Mark Stosberg.

All Programs of mine are 'OSI Certified Open Source Software';
you can redistribute them and/or modify them under the terms of
The Artistic License, a copy of which is available at:
http://www.opensource.org/licenses/index.html