HTML::Native::Attributes - HTML element attributes


    use HTML::Native;

    my $elem = HTML::Native->new (
      a => { class => "active", href => "/home" },
    my $attrs = \%$elem;
    print $attrs;
    # prints " class="active" href="/home""

    use HTML::Native::Attributes;

    my $attrs = HTML::Native::Attributes->new ( {
      class => "active",
      href => "/home",
    } );
    print $attrs;
    # prints " class="active" href="/home""

    $attrs->{class}->{nav} = 1;
    print $attrs;
    # prints " class="active nav" href="/home""


An HTML::Native::Attributes object represents a set of HTML element attributes belonging to an HTML::Native object. It will be created automatically by HTML::Native as necessary; you probably do not ever need to manually create an HTML::Native::Attributes object.

An HTML::Native::Attributes object is a tied hash (see perltie). You can treat it as a normal Perl hash:

    my $attrs = HTML::Native::Attributes->new ( { href => "/home" } );
    print $attrs->{home};
    # prints "/home"

Any value stored in the hash will be automatically converted into a new HTML::Native::Attribute object, and can be transparently accessed either as a scalar, or as a hash, or as an array. For example:

    my $attrs = HTML::Native::Attributes->new();
    $attrs->{class} = "error";
    $attrs->{class}->{fatal} = 1;
    push @{$attrs->{class}}, "internal";
    print $attrs->{class};
    # prints "error fatal internal";

See HTML::Native::Attribute for more documentation and examples.


When subclassing HTML::Native::Attributes, you may wish to override the class that is used by default to hold new attributes. You can do this by overriding the new_attribute() method:


    $attr = $self->new_attribute ( <value> )

The default implementation of this method simply calls HTML::Native::Attribute->new():

    return HTML::Native::Attribute->new ( shift );