line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package CSS::DOM::Rule::Media; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
$VERSION = '0.17'; |
4
|
|
|
|
|
|
|
|
5
|
6
|
|
|
6
|
|
2155
|
use warnings; no warnings qw 'utf8 parenthesis'; |
|
6
|
|
|
6
|
|
10
|
|
|
6
|
|
|
|
|
270
|
|
|
6
|
|
|
|
|
25
|
|
|
6
|
|
|
|
|
18
|
|
|
6
|
|
|
|
|
245
|
|
6
|
6
|
|
|
6
|
|
29
|
use strict; |
|
6
|
|
|
|
|
10
|
|
|
6
|
|
|
|
|
107
|
|
7
|
|
|
|
|
|
|
|
8
|
6
|
|
|
6
|
|
705
|
use CSS::DOM; |
|
6
|
|
|
|
|
10
|
|
|
6
|
|
|
|
|
167
|
|
9
|
6
|
|
|
6
|
|
25
|
use CSS::DOM::Exception qw/ SYNTAX_ERR INDEX_SIZE_ERR /; |
|
6
|
|
|
|
|
10
|
|
|
6
|
|
|
|
|
262
|
|
10
|
6
|
|
|
6
|
|
412
|
use CSS::DOM::Rule; |
|
6
|
|
|
|
|
15
|
|
|
6
|
|
|
|
|
403
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
our @ISA = 'CSS::DOM::Rule'; |
13
|
|
|
|
|
|
|
|
14
|
6
|
|
|
|
|
360
|
use constant 1.03 our $_const = { |
15
|
|
|
|
|
|
|
# Don't let this conflict with the superclass. |
16
|
|
|
|
|
|
|
ruls => 2, |
17
|
|
|
|
|
|
|
medi => 3, |
18
|
6
|
|
|
6
|
|
30
|
}; |
|
6
|
|
|
|
|
88
|
|
19
|
6
|
|
|
6
|
|
33
|
{ no strict; delete @{__PACKAGE__.'::'}{_const => keys %{our $_const}} } |
|
6
|
|
|
|
|
15
|
|
|
6
|
|
|
|
|
3184
|
|
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
# overrides: |
22
|
3
|
|
|
3
|
1
|
16
|
sub type { CSS::DOM::Rule::MEDIA_RULE } |
23
|
|
|
|
|
|
|
sub cssText { |
24
|
39
|
|
|
39
|
1
|
70
|
my $self = shift; |
25
|
39
|
|
|
|
|
49
|
my $old; |
26
|
39
|
100
|
|
|
|
103
|
if(defined wantarray) { |
27
|
38
|
50
|
|
|
|
124
|
$old = '@media ' . ( |
28
|
|
|
|
|
|
|
$self->[medi] ? $self->[medi]->mediaText : '' |
29
|
|
|
|
|
|
|
) . " {\n"; |
30
|
38
|
50
|
|
|
|
52
|
(my $rules = join '',map $_->cssText, @{$self->[ruls]||[]}) |
|
38
|
|
|
|
|
155
|
|
31
|
|
|
|
|
|
|
=~ s/^(?!$)/\t/gm; |
32
|
38
|
|
|
|
|
81
|
$old .= "$rules}\n"; |
33
|
|
|
|
|
|
|
} |
34
|
39
|
100
|
|
|
|
73
|
if (@_) { |
35
|
2
|
|
|
|
|
8
|
my $new_rule = $self->_parse(shift); |
36
|
1
|
|
|
|
|
4
|
@$self[ruls,medi] = @$new_rule[ruls,medi]; |
37
|
|
|
|
|
|
|
} |
38
|
38
|
|
|
|
|
129
|
$old; |
39
|
|
|
|
|
|
|
}; |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
# CSSMediaRule interface: |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
# These methods are identical to those in CSS::DOM, but we’ve had to copy & |
45
|
|
|
|
|
|
|
# paste them here, because the constants have different values. Even if we |
46
|
|
|
|
|
|
|
# were to change them to have the same values, it would be a maintenance |
47
|
|
|
|
|
|
|
# nightmare. |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub media { |
50
|
53
|
50
|
66
|
53
|
1
|
3279
|
wantarray ? @{$_[0]->[medi]||return} : |
|
1
|
100
|
|
|
|
7
|
|
51
|
|
|
|
|
|
|
($_[0]->[medi] ||= ( |
52
|
|
|
|
|
|
|
require CSS::DOM::MediaList, |
53
|
|
|
|
|
|
|
CSS::DOM::MediaList->new |
54
|
|
|
|
|
|
|
)) |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
sub cssRules { |
58
|
|
|
|
|
|
|
wantarray |
59
|
64
|
50
|
66
|
64
|
1
|
858
|
? @{shift->[ruls]||return} |
|
5
|
100
|
|
|
|
29
|
|
60
|
|
|
|
|
|
|
: (shift->[ruls]||=new CSS::DOM::RuleList); |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
sub insertRule { # This is supposed to raise an HIERARCHY_REQUEST_ERR if |
64
|
|
|
|
|
|
|
# the rule cannot be inserted at the specified index; |
65
|
|
|
|
|
|
|
# e.g., if an @import rule is inserted after a stan- |
66
|
|
|
|
|
|
|
# dard rule. But we don’t do that, in order to maintain |
67
|
|
|
|
|
|
|
# future compatibility. |
68
|
5
|
|
|
5
|
1
|
13
|
my ($self, $rule_string, $index) = @_; |
69
|
|
|
|
|
|
|
|
70
|
5
|
|
|
|
|
23
|
require CSS::DOM::Parser; |
71
|
5
|
|
|
|
|
7
|
my ($at,$rule); |
72
|
|
|
|
|
|
|
{ |
73
|
5
|
|
|
|
|
5
|
local *@; |
|
5
|
|
|
|
|
11
|
|
74
|
5
|
|
|
|
|
12
|
$rule = CSS::DOM::Parser::parse_statement($rule_string); |
75
|
5
|
|
|
|
|
12
|
$at = $@ |
76
|
|
|
|
|
|
|
} |
77
|
5
|
100
|
|
|
|
18
|
$at and die new CSS::DOM::Exception SYNTAX_ERR, $at; |
78
|
|
|
|
|
|
|
|
79
|
4
|
|
|
|
|
11
|
$rule->_set_parentStyleSheet($self->parentStyleSheet); |
80
|
4
|
|
|
|
|
11
|
$rule->_set_parentRule($self); |
81
|
|
|
|
|
|
|
|
82
|
4
|
|
|
|
|
9
|
my $list = $self->cssRules; # cssRules takes care of ||= |
83
|
4
|
|
|
|
|
17
|
splice @$list, $index, 0, $rule; |
84
|
|
|
|
|
|
|
|
85
|
4
|
100
|
|
|
|
24
|
$index < 0 ? $#$list + $index : |
|
|
100
|
|
|
|
|
|
86
|
|
|
|
|
|
|
$index <= $#$list ? $index : |
87
|
|
|
|
|
|
|
$#$list |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
sub deleteRule { |
91
|
2
|
|
|
2
|
1
|
10
|
my ($self,$index) = @_; |
92
|
2
|
|
|
|
|
3
|
my $list = $self->[ruls]; |
93
|
2
|
100
|
|
|
|
10
|
$index > $#$list and die CSS::DOM::Exception->new( |
94
|
|
|
|
|
|
|
INDEX_SIZE_ERR, |
95
|
|
|
|
|
|
|
"The index passed to deleteRule ($index) is too large" |
96
|
|
|
|
|
|
|
); |
97
|
1
|
|
|
|
|
3
|
splice @$list, $index, 1; |
98
|
|
|
|
|
|
|
return # nothing; |
99
|
1
|
|
|
|
|
8
|
} |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
sub _set_parentStyleSheet { |
102
|
0
|
|
|
0
|
|
|
my $self = shift; |
103
|
0
|
|
|
|
|
|
$self->SUPER::_set_parentStyleSheet(@_); |
104
|
0
|
|
|
|
|
|
$_->_set_parentStyleSheet(@_) for @{$self->[ruls]}; |
|
0
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
!()__END__()! |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
=head1 NAME |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
CSS::DOM::Rule::Media - CSS @media rule class for CSS::DOM |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
=head1 VERSION |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
Version 0.17 |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
=head1 SYNOPSIS |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
use CSS::DOM; |
120
|
|
|
|
|
|
|
my $media_rule = CSS::DOM->parse( |
121
|
|
|
|
|
|
|
'@media print { body { background: none } }' |
122
|
|
|
|
|
|
|
)->cssRules->[0]; |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
# OR: |
125
|
|
|
|
|
|
|
use CSS::DOM::Rule::Media; |
126
|
|
|
|
|
|
|
my $media_rule = new CSS::DOM::Rule::Media $parent; |
127
|
|
|
|
|
|
|
push @{$media_rule->media}, 'print'; |
128
|
|
|
|
|
|
|
$media_rule->insertRule('body { background: none }') |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
=head1 DESCRIPTION |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
This module implements CSS C<@media> rules for L. It inherits |
133
|
|
|
|
|
|
|
from |
134
|
|
|
|
|
|
|
L and implements |
135
|
|
|
|
|
|
|
the CSSMediaRule DOM interface. |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
=head1 METHODS |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
=over 4 |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
=item media |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
Returns the MediaList associated with the @media rule (or a plain list in |
144
|
|
|
|
|
|
|
list context). This defaults to an |
145
|
|
|
|
|
|
|
empty list. You can pass a comma-delimited string to the MediaList's |
146
|
|
|
|
|
|
|
C method to set it. |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
=item cssRules |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
In scalar context, this returns a L object (simply a |
151
|
|
|
|
|
|
|
blessed |
152
|
|
|
|
|
|
|
array reference) of L objects. In list context it returns a |
153
|
|
|
|
|
|
|
list. |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
=item insertRule ( $css_code, $index ) |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
Parses the rule contained in the C<$css_code>, inserting it the @media |
158
|
|
|
|
|
|
|
rule's list of subrules at the given C<$index>. |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
=item deleteRule ( $index ) |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
Deletes the rule at the given C<$index>. |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
=back |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
=head1 SEE ALSO |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
L |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
L |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
L |