| CSS-DOM documentation | Contained in the CSS-DOM distribution. |
CSS::DOM::MediaList - Medium list class for CSS::DOM
Version 0.14
use CSS::DOM;
$media_list = new CSS::DOM ->media;
use CSS::DOM::MediaList;
$media_list = new MediaList 'screen', 'papyrus';
@media = @$media_list; # use as array
$media_list->mediaText; # returns a string
$media_list->mediaText('print, screen'); # change it
$media_list->deleteMedium('print');
$media_list->appendMedium('tv');
This module implements medium lists for CSS::DOM. It implements the CSSMediaList DOM interface and inherits from CSS::DOM::Array.
A comma-and-space-separated string of the individual media in the list, e.g., 'screen, print'.
Deletes the named medium from the list, or throws an error if it cannot be found.
Adds a medium to the end of the list.
| CSS-DOM documentation | Contained in the CSS-DOM distribution. |
package CSS::DOM::MediaList; $VERSION = '0.14'; require CSS::DOM::Array; @ISA = 'CSS::DOM::Array'; use CSS::DOM::Exception 'NOT_FOUND_ERR'; sub mediaText { my $list = shift; my $old = join ', ', @$list unless not defined wantarray; if (@_) { # This parser is based on the description in the HTML spec. @$list = map /^\p{IsSpacePerl}*([A-Za-z0-9-]*)/, split /,/, shift; } $old } sub deleteMedium { my ($list, $medium) = @_; my $length = @$list; @$list = grep $_ ne $medium, @$list; @$list == $length and die CSS::DOM::Exception->new( NOT_FOUND_ERR, qq'The medium "$medium" cannot be found in the list' ); return # nothing; } sub appendMedium { # ~~~ If someone passes âfoo>>@#â as an argument, are we # supposed to truncate it or throw an exception? The # DOM Style spec. is vague and refers to the âunder- # lying style languageâ. The HTML spec. has a sec- # tion on parsing of entire lists. Does that apply # to this, or do I have to hunt through the CSS # spec. to find that which I seek? my ($list ,$medium) = @_; @$list = (grep($_ ne $medium, @$list), $medium); return # nothing; } !()__END__()!