NAME
HTML::Object::Attribute - HTML Object Element Attribute Class
SYNOPSIS
use HTML::Object::Attribute;
# Attribute name only
my $attr = HTML::Object::Attribute->new( 'id' );
# Name with properties as key-value pairs
my $attr = HTML::Object::Attribute->new( 'id', value => 'hello', element => $e );
# Name with properties as a hash reference
my $attr = HTML::Object::Attribute->new( 'id', { value => 'hello', element => $e } );
# Properties only, via SUPER::init key-value dispatch
my $attr = HTML::Object::Attribute->new( name => 'id', value => 'hello' );
$attr->value( 'hello' );
print $attr->name; # id
print $attr->value; # hello
VERSION
v0.3.0
DESCRIPTION
This class represents an HTML element attribute. It is the base class used throughout the HTML::Object framework to store an attribute name, its associated value, the element it belongs to, and its rank (position) within that element's attribute list.
The DOM-oriented interface (node traversal, XPath coercions, stringification, and so on) is provided by the subclass HTML::Object::DOM::Attribute, which extends this class.
CONSTRUCTOR
new
my $attr = HTML::Object::Attribute->new( 'id' );
my $attr = HTML::Object::Attribute->new( 'id', value => 'hello', element => $e );
my $attr = HTML::Object::Attribute->new( 'id', { value => 'hello', element => $e } );
my $attr = HTML::Object::Attribute->new( name => 'id', value => 'hello' );
Creates and returns a new HTML::Object::Attribute object.
The constructor accepts the attribute name as an optional leading positional argument (a plain string or any object that overloads stringification), followed by either a flat list of key-value pairs or a hash reference of properties. When no positional name is given, the name may be supplied via the name key in the property list.
Returns the new object on success, or sets an error and returns undef on failure.
METHODS
element
my $element = $attr->element;
$attr->element( $element );
Gets or sets the HTML::Object::Element object to which this attribute belongs. Accepts an HTML::Object::Element instance or undef to clear the association.
name
my $name = $attr->name;
$attr->name( 'class' );
Gets or sets the attribute name. Returns a scalar object.
Normally, under JavaScript, this is read-only, but under perl you can change it. Still be careful.
See also https://developer.mozilla.org/en-US/docs/Web/API/Attr/name
rank
my $rank = $attr->rank;
$attr->rank(3);
Gets or sets the position (rank) of this attribute within its parent element's attribute list. Returns a number object.
value
my $val = $attr->value;
$attr->value( 'hello' );
Gets or sets the attribute value. Leading and trailing horizontal whitespace is stripped automatically when a value is set. Returns a scalar object.
See also https://developer.mozilla.org/en-US/docs/Web/API/Attr/value
AUTHOR
Jacques Deguest <jack@deguest.jp>
SEE ALSO
HTML::Object::DOM::Attribute, the DOM subclass that adds node traversal, XPath coercion, toString, nodeValue, and the full attribute node interface.
HTML::Object, HTML::Object::Boolean, HTML::Object::Closing, HTML::Object::Collection, HTML::Object::Comment, HTML::Object::Declaration, HTML::Object::Document, HTML::Object::Element, HTML::Object::Exception, HTML::Object::Literal, HTML::Object::Number, HTML::Object::Root, HTML::Object::Space, HTML::Object::Text, HTML::Object::XQuery
https://developer.mozilla.org/en-US/docs/Web/API/Attr
Mozilla HTML attributes reference
COPYRIGHT & LICENSE
Copyright (c) 2021 DEGUEST Pte. Ltd.
All rights reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.