| 1 | package CSS::DOM::MediaList; | ||||||||||
| 2 | |||||||||||
| 3 | 9 | $VERSION = '0.16'; | |||||||||
| 4 | |||||||||||
| 5 | 9 | require CSS::DOM::Array; | |||||||||
| 6 | 9 | @ISA = 'CSS::DOM::Array'; | |||||||||
| 7 | |||||||||||
| 8 | 9 | ▶ | use CSS::DOM::Exception 'NOT_FOUND_ERR'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | |||||||||||
| 10 | sub mediaText { | ||||||||||
| 11 | 47 | ▶ | my $list = shift; | ||||||||
|
Subroutine
mediaText: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||
| 12 | 47 | ▶ | my $old = join ', ', @$list unless not defined wantarray; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 13 | 47 | ▶ | if (@_) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 14 | # This parser is based on the description in the HTML spec. | ||||||||||
| 15 | 4 | @$list = map /^\p{IsSpacePerl}*([A-Za-z0-9-]*)/, | |||||||||
| 16 | split /,/, shift; | ||||||||||
| 17 | } | ||||||||||
| 18 | $old | ||||||||||
| 19 | 47 | } | |||||||||
| 20 | |||||||||||
| 21 | sub deleteMedium { | ||||||||||
| 22 | 2 | ▶ | my ($list, $medium) = @_; | ||||||||
|
Subroutine
deleteMedium: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||
| 23 | 2 | my $length = @$list; | |||||||||
| 24 | 2 | @$list = grep $_ ne $medium, @$list; | |||||||||
| 25 | 2 | ▶ | @$list == $length and die CSS::DOM::Exception->new( | ||||||||
|
Branch: 1 branch
| |||||||||||
| 26 | NOT_FOUND_ERR, | ||||||||||
| 27 | qq'The medium "$medium" cannot be found in the list' | ||||||||||
| 28 | ); | ||||||||||
| 29 | return # nothing; | ||||||||||
| 30 | 1 | } | |||||||||
| 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 | ▶ | my ($list ,$medium) = @_; | ||||||||
|
Subroutine
appendMedium: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 40 | 2 | @$list = (grep($_ ne $medium, @$list), $medium); | |||||||||
| 41 | return # nothing; | ||||||||||
| 42 | 2 | } | |||||||||
| 43 | |||||||||||
| 44 | 9 | !()__END__()! | |||||||||
| 45 | |||||||||||
| 46 | =head1 NAME | ||||||||||
| 47 | |||||||||||
| 48 | CSS::DOM::MediaList - Medium list class for CSS::DOM | ||||||||||
| 49 | |||||||||||
| 50 | =head1 VERSION | ||||||||||
| 51 | |||||||||||
| 52 | Version 0.16 | ||||||||||
| 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<CSS::DOM>. It implements the | ||||||||||
| 71 | CSSMediaList DOM interface and inherits from L<CSS::DOM::Array>. | ||||||||||
| 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<CSS::DOM> | ||||||||||
| 104 | |||||||||||
| 105 | L<CSS::DOM::Array> | ||||||||||