NAME
HTML::DOM::Element::Link - A Perl class for representing 'link' elements in an HTML DOM tree
SYNOPSIS
use HTML::DOM;
$doc = HTML::DOM->new;
$elem = $doc->createElement('link');
$elem->charset('iso-8859-1'); # set attribute
$elem->href; # get attribute
$elem->tagName;
# etc
DESCRIPTION
This class implements 'link' elements in an HTML::DOM tree. It implements the HTMLLinkElement DOM interface and inherits from HTML::DOM::Element (q.v.).
METHODS
In addition to those inherited from HTML::DOM::Element and its superclasses, this class implements the following DOM methods:
- disabled
-
Returns a boolean. Pass an argument to set it.
- charset
- href
- hreflang
- media
- rel
- rev
- target
- type
-
Each of these returns the corresponding HTML attribute. If you pass an argument, it will become the new value of the attribute, and the old value will be returned.
- sheet
-
By default, this returns null.
You can parse an argument to set it. You normally only do this if 'rel' is set to 'stylesheet', but CSS::DOM is kind, and trusts you know what you are doing if you set it when that is not the case.
Here is an example of how one might parse CSS style sheets while the HTML document is being parsed (a bit simplistic, as it only works with absolute URLs):
use LWP::Simple 'get'; use CSS::DOM 0.03; $doc = new HTML::DOM; $doc->elem_handler( link => sub { my ($doc, $elem) = @_; return unless $elem->attr('rel') =~ /\bstylesheet\b/i; my $css = get($elem->src); my $charset = $doc->charset || 'iso-8859-1'; CSS::DOM::parse( $css, encoding_hint => $charset, url_fetcher => sub { get(shift), encoding_hint => $charset }, ); }); If the 'rel' attribute is set to 'stylesheet', this returns null.
Otherwise it returns a style sheet (a CSS::DOM object), empty by default (since fetching URLs is something HTML::DOM doesn't do). You can set the contents of the style sheet by passing CSS code to its
read_string
method.