HTML-HTML5-DOM

 view release on metacpan or  search on metacpan

lib/HTML/HTML5/DOM.pm  view on Meta::CPAN

		__PACKAGE__,
		'p5_ancestors',
		'Returns a (Perl or XML::LibXML::NodeList) list of this element\'s ancestors - i.e. the parentNode, the parentNode of the parentNode, etc.',
		);

	sub p5_contains
	{
		my ($self, $thing) = @_;
		my @results = grep {
			$_ == $self
		} $thing->p5_ancestors;
		return 1 if @results;
		return;
	}

	HTML::HTML5::DOMutil::AutoDoc->add(
		__PACKAGE__,
		'p5_contains',
		'Given an argument, returns true if that argument is an element nested within this element.',
		);

	__PACKAGE__->_mk_attribute_accessors(qw/
		id
		title lang translate==boolean dir className=class
		hidden==boolean tabIndex=tabindex accessKey=accesskey
		classList=class=LIST
		/);

	sub dataset
	{
		my $self = shift;
		my %rv;
		foreach my $attr ($self->attributes)
		{
			if ($attr->nodeName =~ /^data-[^A-Z]$/)
			{
				my $key = $1;
				$key =~ s{ \- ([a-z]) }{ uc('-'.$1) }gex;
				$rv{$key} = $attr->value;
			}
		}
		return \%rv;
	}

	HTML::HTML5::DOMutil::AutoDoc->add(
		__PACKAGE__,
		'dataset',
		'Gets a hashref based on C<< data-foo >> attributes. This is currently read-only, but in future may be implemented as a tied hash to allow read/write access.',
		);

	sub XML::LibXML::Node::_p5_numericPath
	{
		join q{:},
			map { sprintf('%09d', $_) }
			map {
				if (m{^[*]\[(\d+)]$})   { $1; }
				elsif (m{^[*]$})       { 0; }
				elsif (m{^$})          { 0; }
				else                   { 999_999_999 }
			}
			split m{/}, (shift)->nodePath;
	}

	sub compareDocumentPosition
	{
		my ($self, $other) = @_;
		$self->_p5_numericPath cmp $other->_p5_numericPath;
	}

	HTML::HTML5::DOMutil::AutoDoc->add(
		__PACKAGE__,
		'compareDocumentPosition',
		'Compares this node with another based on document order.',
		);

	*getUserData =
	*setUserData =
	sub { die "TODO" };

	HTML::HTML5::DOMutil::AutoDoc->add(
		__PACKAGE__,
		$_,
		'Not implemented - perhaps never will be. Try C<dataset> instead.',
		) for qw( getUserData setUserData );

	sub getFeature { (shift)->ownerDocument->implementation->getFeature(@_) }

	HTML::HTML5::DOMutil::AutoDoc->add(
		__PACKAGE__,
		'getFeature',
		'Acts as a shortcut for C<< $element->ownerDocument->implementation->getFeature >>.',
		);

	sub isDefaultNamespace { my $self = shift; !$self->lookupNamespacePrefix("".shift) }

	HTML::HTML5::DOMutil::AutoDoc->add(
		__PACKAGE__,
		'isDefaultNamespace',
		'Given a URI, returns true if that is the default namespace prefix.',
		);

	*lookupPrefix = XML::LibXML::Augment::Element->can('lookupNamespacePrefix');

	HTML::HTML5::DOMutil::AutoDoc->add(
		__PACKAGE__,
		'lookupPrefix',
		'Alias for C<lookupNamespacePrefix>.',
		);

	sub isSupported { (shift)->ownerDocument->implementation->hasFeature(@_) }

	HTML::HTML5::DOMutil::AutoDoc->add(
		__PACKAGE__,
		'isSupported',
		'Acts as a shortcut for C<< $element->ownerDocument->implementation->hasFeature >>.',
		);

	*schemaTypeInfo =
	*setIdAttribute =
	*setIdAttributeNS =
	*setIdAttributeNode =



( run in 0.594 second using v1.01-cache-2.11-cpan-71847e10f99 )