line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package CSS::DOM::Rule::Media; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
$VERSION = '0.15'; |
4
|
|
|
|
|
|
|
|
5
|
6
|
|
|
6
|
|
1456
|
use warnings; no warnings qw 'utf8 parenthesis'; |
|
6
|
|
|
6
|
|
87
|
|
|
6
|
|
|
|
|
431
|
|
|
6
|
|
|
|
|
36
|
|
|
6
|
|
|
|
|
14
|
|
|
6
|
|
|
|
|
312
|
|
6
|
6
|
|
|
6
|
|
31
|
use strict; |
|
6
|
|
|
|
|
15
|
|
|
6
|
|
|
|
|
238
|
|
7
|
|
|
|
|
|
|
|
8
|
6
|
|
|
6
|
|
733
|
use CSS::DOM; |
|
6
|
|
|
|
|
12
|
|
|
6
|
|
|
|
|
195
|
|
9
|
6
|
|
|
6
|
|
37
|
use CSS::DOM::Exception qw/ SYNTAX_ERR INDEX_SIZE_ERR /; |
|
6
|
|
|
|
|
11
|
|
|
6
|
|
|
|
|
402
|
|
10
|
6
|
|
|
6
|
|
676
|
use CSS::DOM::Rule; |
|
6
|
|
|
|
|
12
|
|
|
6
|
|
|
|
|
553
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
our @ISA = 'CSS::DOM::Rule'; |
13
|
|
|
|
|
|
|
|
14
|
6
|
|
|
|
|
462
|
use constant 1.03 our $_const = { |
15
|
|
|
|
|
|
|
# Don't let this conflict with the superclass. |
16
|
|
|
|
|
|
|
ruls => 2, |
17
|
|
|
|
|
|
|
medi => 3, |
18
|
6
|
|
|
6
|
|
37
|
}; |
|
6
|
|
|
|
|
201
|
|
19
|
6
|
|
|
6
|
|
35
|
{ no strict; delete @{__PACKAGE__.'::'}{_const => keys %{our $_const}} } |
|
6
|
|
|
|
|
13
|
|
|
6
|
|
|
|
|
5444
|
|
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
# overrides: |
22
|
3
|
|
|
3
|
1
|
22
|
sub type { CSS::DOM::Rule::MEDIA_RULE } |
23
|
|
|
|
|
|
|
sub cssText { |
24
|
39
|
|
|
39
|
1
|
100
|
my $self = shift; |
25
|
39
|
|
|
|
|
64
|
my $old; |
26
|
39
|
100
|
|
|
|
127
|
if(defined wantarray) { |
27
|
38
|
50
|
|
|
|
265
|
$old = '@media ' . ( |
28
|
|
|
|
|
|
|
$self->[medi] ? $self->[medi]->mediaText : '' |
29
|
|
|
|
|
|
|
) . " {\n"; |
30
|
38
|
50
|
|
|
|
78
|
(my $rules = join '',map $_->cssText, @{$self->[ruls]||[]}) |
|
38
|
|
|
|
|
236
|
|
31
|
|
|
|
|
|
|
=~ s/^(?!$)/\t/gm; |
32
|
38
|
|
|
|
|
105
|
$old .= "$rules}\n"; |
33
|
|
|
|
|
|
|
} |
34
|
39
|
100
|
|
|
|
201
|
if (@_) { |
35
|
2
|
|
|
|
|
14
|
my $new_rule = $self->_parse(shift); |
36
|
1
|
|
|
|
|
6
|
@$self[ruls,medi] = @$new_rule[ruls,medi]; |
37
|
|
|
|
|
|
|
} |
38
|
38
|
|
|
|
|
217
|
$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
|
7823
|
wantarray ? @{$_[0]->[medi]||return} : |
|
1
|
100
|
|
|
|
12
|
|
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
|
1007
|
? @{shift->[ruls]||return} |
|
5
|
100
|
|
|
|
43
|
|
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
|
15
|
my ($self, $rule_string, $index) = @_; |
69
|
|
|
|
|
|
|
|
70
|
5
|
|
|
|
|
29
|
require CSS::DOM::Parser; |
71
|
5
|
|
|
|
|
9
|
my ($at,$rule); |
72
|
|
|
|
|
|
|
{ |
73
|
5
|
|
|
|
|
7
|
local *@; |
|
5
|
|
|
|
|
11
|
|
74
|
5
|
|
|
|
|
18
|
$rule = CSS::DOM::Parser::parse_statement($rule_string); |
75
|
5
|
|
|
|
|
17
|
$at = $@ |
76
|
|
|
|
|
|
|
} |
77
|
5
|
100
|
|
|
|
23
|
$at and die new CSS::DOM::Exception SYNTAX_ERR, $at; |
78
|
|
|
|
|
|
|
|
79
|
4
|
|
|
|
|
15
|
$rule->_set_parentStyleSheet($self->parentStyleSheet); |
80
|
4
|
|
|
|
|
15
|
$rule->_set_parentRule($self); |
81
|
|
|
|
|
|
|
|
82
|
4
|
|
|
|
|
9
|
my $list = $self->cssRules; # cssRules takes care of ||= |
83
|
4
|
|
|
|
|
20
|
splice @$list, $index, 0, $rule; |
84
|
|
|
|
|
|
|
|
85
|
4
|
100
|
|
|
|
36
|
$index < 0 ? $#$list + $index : |
|
|
100
|
|
|
|
|
|
86
|
|
|
|
|
|
|
$index <= $#$list ? $index : |
87
|
|
|
|
|
|
|
$#$list |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
sub deleteRule { |
91
|
2
|
|
|
2
|
1
|
11
|
my ($self,$index) = @_; |
92
|
2
|
|
|
|
|
6
|
my $list = $self->[ruls]; |
93
|
2
|
100
|
|
|
|
30
|
$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
|
|
|
|
|
15
|
} |
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.15 |
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<CSS::DOM>. It inherits |
133
|
|
|
|
|
|
|
from |
134
|
|
|
|
|
|
|
L<CSS::DOM::Rule> 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<mediaText> method to set it. |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
=item cssRules |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
In scalar context, this returns a L<CSS::DOM::RuleList> object (simply a |
151
|
|
|
|
|
|
|
blessed |
152
|
|
|
|
|
|
|
array reference) of L<CSS::DOM::Rule> 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<CSS::DOM> |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
L<CSS::DOM::Rule> |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
L<CSS::DOM::MediaList> |