File Coverage

blib/lib/CSS/DOM/MediaList.pm
Criterion Covered Total %
statement 19 19 100.0
branch 6 6 100.0
condition n/a
subroutine 5 5 100.0
pod 3 3 100.0
total 33 33 100.0


line stmt bran cond sub pod time code
1             package CSS::DOM::MediaList;
2              
3             $VERSION = '0.17';
4              
5             require CSS::DOM::Array;
6             @ISA = 'CSS::DOM::Array';
7              
8 9     9   1585 use CSS::DOM::Exception 'NOT_FOUND_ERR';
  9         12  
  9         798  
9              
10             sub mediaText {
11 47     47 1 64 my $list = shift;
12 47 100       127 my $old = join ', ', @$list unless not defined wantarray;
13 47 100       91 if (@_) {
14             # This parser is based on the description in the HTML spec.
15 8     8   3167 @$list = map /^\p{IsSpacePerl}*([A-Za-z0-9-]*)/,
  8         82  
  8         89  
  4         31  
16             split /,/, shift;
17             }
18             $old
19 47         115 }
20              
21             sub deleteMedium {
22 2     2 1 4 my ($list, $medium) = @_;
23 2         3 my $length = @$list;
24 2         6 @$list = grep $_ ne $medium, @$list;
25 2 100       12 @$list == $length and die CSS::DOM::Exception->new(
26             NOT_FOUND_ERR,
27             qq'The medium "$medium" cannot be found in the list'
28             );
29             return # nothing;
30 1         3 }
31              
32             sub appendMedium { # ~~~ If someone passes ‘foo>>@#’ as an argument, are we
33             # supposed to truncate it or throw an exception? The
34             # DOM Style spec. is vague and refers to the ‘under-
35             # lying style language’. The HTML spec. has a sec-
36             # tion on parsing of entire lists. Does that apply
37             # to this, or do I have to hunt through the CSS
38             # spec. to find that which I seek?
39 2     2 1 237 my ($list ,$medium) = @_;
40 2         8 @$list = (grep($_ ne $medium, @$list), $medium);
41             return # nothing;
42 2         6 }
43              
44             !()__END__()!
45              
46             =head1 NAME
47              
48             CSS::DOM::MediaList - Medium list class for CSS::DOM
49              
50             =head1 VERSION
51              
52             Version 0.17
53              
54             =head1 SYNOPSIS
55              
56             use CSS::DOM;
57             $media_list = new CSS::DOM ->media;
58              
59             use CSS::DOM::MediaList;
60             $media_list = new MediaList 'screen', 'papyrus';
61              
62             @media = @$media_list; # use as array
63             $media_list->mediaText; # returns a string
64             $media_list->mediaText('print, screen'); # change it
65             $media_list->deleteMedium('print');
66             $media_list->appendMedium('tv');
67              
68             =head1 DESCRIPTION
69              
70             This module implements medium lists for L. It implements the
71             CSSMediaList DOM interface and inherits from L.
72              
73             =head1 METHODS
74              
75             =head2 DOM Attributes
76              
77             =over 4
78              
79             =item mediaText
80              
81             A comma-and-space-separated string of the individual media in the list,
82             e.g., 'screen, print'.
83              
84             =back
85              
86             =head2 DOM Methods
87              
88             =over 4
89              
90             =item deleteMedium ( $name )
91              
92             Deletes the named medium from the list, or throws an error if it cannot
93             be found.
94              
95             =item appendMedium ( $name )
96              
97             Adds a medium to the end of the list.
98              
99             =back
100              
101             =head1 SEE ALSO
102              
103             L
104              
105             L