DOM/Style.pm

filter: Statementstmt 97.6% 164 / 168 Branchbran 90.6% 87 / 96 Conditioncond 80.0% 28 / 35 MC/DCmcdc 60.0% 12 / 20 Subroutinesub 91.6% 22 / 24 Podpod 92.8% 13 / 14 totaltotal 91.3% 326 / 357 CC 67 SCAR 21.0
CC
67
Cov
93%
setProperty
14.0
_set_property_tokens
13.0
getPropertyValue
12.0
CRAP 8.1
« DOM.pm ↑ Summary DOM/Value/List.pm »
1 package CSS::DOM::Style;
2  
3 22 $VERSION = '0.16';
4  
5 22 ▶use warnings; no warnings qw' utf8';
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
6 22 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 22 ▶use CSS::DOM::Exception 'SYNTAX_ERR';
Subroutine BEGIN: called CC=1 SCAR=0.0
9 22 ▶use CSS::DOM::Util qw 'escape_ident unescape';
Subroutine BEGIN: called CC=1 SCAR=0.0
10 22 ▶use Scalar::Util 'weaken';
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 # ~~~ use overload fallback => 1, '@{}' =>
13  
14 # Internal object structure
15 #
16 # Each style object is a hash ref:
17 # {
18 # owner => $owner_rule,
19 # parser => $property_parser,
20 # mod_handler => sub { ... }, # undef initially
21 # names => [...],
22 # props => {...},
23 # pri => {...}, # property priorities
24 # }
25 #
26 # The value of an element in the props hash can be one of three things
27 # 1) a CSSValue object
28 # 2) an array ref that is a blueprint for a CSSValue object:
29 # [ $css_code, $class, @constructor_args]
30 # 3) a string of css code
31 # Item (3) is only used when there is no property parser.
32  
33 sub parse {
34 393 ▶ require CSS::DOM::Parser;
Subroutine parse: called CC=1 SCAR=0.0
Pod documented
35 393 goto &CSS::DOM::Parser::parse_style_declaration;
36 }
37  
38 sub new {
39 532 ▶ my($class) = shift;
Subroutine new: called CC=5 SCAR=16.1
Pod documented
40  
41 532 my $self = bless {}, $class;
42 532 ▶ if(@_ == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ == 1) { } 128 404 532
43 128 $self->{owner} = shift;
44 }
45 else {
46 404 my %args = @_;
47 404 $self->{owner} = delete $args{owner};
48 $self->{parser}
49 404 = delete $args{property_parser};
50 }
51 {
52 532 $self->{parser} ||= (
53 532 ▶ ($self->{owner} || next)->parentStyleSheet || next
Condition100%7/7
$self->{"parser"} ||= (($self->{"owner"} || (next))->parentStyleSheet || (next))->property_parser
l!l&&r!l&&!r
8394130
($self->{'owner'} || (next))->parentStyleSheet || (next)
l!l
8543
$self->{'owner'} || (next)
l!l
128396
MC/DC100%2/2
$self->{"parser"} ||= (($self->{"owner"} || (next))->parentStyleSheet || (next))->property_parser
$self->{"parser"} (($self->{"owner"} || (next))->parentStyleSheet || (next))->property_parser
MC/DC100%1/1
($self->{'owner'} || (next))->parentStyleSheet || (next)
($self->{'owner'} || (next))->parentStyleSheet
MC/DC100%1/1
$self->{'owner'} || (next)
$self->{'owner'}
Truth table100%3/3
A ||= B
A= $self->{"parser"}B= (($self->{"owner"} || (next))->parentStyleSheet || (next))->property_parser
ABresult
1X1
011
000
Truth table100%2/2
A
A= ($self->{'owner'} || (next))->parentStyleSheet
Aresult
11
00
Truth table100%2/2
A
A= $self->{'owner'}
Aresult
11
00
54 )->property_parser;
55 }
56 532 weaken $self->{owner};
57 532 return $self
58 }
59  
60 sub cssText {
61 94 ▶ my $self = shift;
Subroutine cssText: called CC=5 SCAR=16.1
Pod documented
62 94 my $out;
63 94 ▶ if (defined wantarray) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined wantarray) 89 5 94
64 $out = join "; ", map {
65 88 my $pri = $self->getPropertyPriority($_);
66 88 "$_: ".$self->getPropertyValue($_)." !"x!!$pri
67 . escape_ident($pri)
68 89 } @{$$self{names}};
69 }
70 94 ▶ if(@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 6 88 94
71 6 my $css = shift;
72 !defined $css || !length $css and
73 6 ▶ @$self{'props','names'} = (), return $out;
Branch: 1 branch
BranchTrueFalseTotal
defined $css and CORE::length $css or @$self{"props", "names"} = (), (return $out) 1 5 6
Condition66%2/3
defined $css and CORE::length $css
!ll&&!rl&&r
015
MC/DC50%1/2
defined $css and CORE::length $css
defined $css CORE::length $css
Truth table66%2/3
A and B
A= defined $cssB= CORE::length $css
ABresult
0X0
100
111
74  
75 5 require CSS::DOM::Parser;
76 my $new =CSS::DOM::Parser::parse_style_declaration(
77 $css, property_parser => $$self{parser}
78 5 );
79  
80 5 @$self{'props','names'} = @$new{'props','names'};
81 5 _m($self);
82 }
83 93 return $out;
84 }
85  
86 sub getPropertyValue { # ~~~ Later I plan to make this return lists of
87 # scalars in list context (for list properties).
88 2899 ▶ my $self = shift;
Subroutine getPropertyValue: called CC=12 SCAR=24.9
Pod documented
89 2899 ▶ my $props = $self->{props} || return '';
Condition50%1/2
$self->{'props'} || (return '')
l!l
28990
MC/DC0%0/1
$self->{'props'} || (return '')
$self->{'props'}
Truth table50%1/2
A
A= $self->{'props'}
Aresult
11
00
90 2899 my $name = lc$_[0];
91  
92 2899 ▶ if(my $spec = $self->{parser}) { serialise: {
Branch: 1 branch
BranchTrueFalseTotal
if (my $spec = $self->{"parser"}) 1917 982 2899
93 1917 ▶ if(my $p = $spec->get_property($name)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $p = $spec->get_property($name)) 1916 1 1917
94 1916 ▶ if(exists $p->{serialise} and my $s = $p->{serialise}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $p->{"serialise"} and my $s = $p->{"serialise"}) 115 1801 1916
Condition66%2/3
exists $p->{"serialise"} and my $s = $p->{"serialise"}
!ll&&!rl&&r
18010115
MC/DC50%1/2
exists $p->{"serialise"} and my $s = $p->{"serialise"}
exists $p->{"serialise"} my $s = $p->{"serialise"}
Truth table66%2/3
A and B
A= exists $p->{"serialise"}B= my $s = $p->{"serialise"}
ABresult
0X0
100
111
95 115 my @p = $spec->subproperty_names($name);
96 115 my %p;
97 115 for(@p) {
98 436 my $v = $self->getPropertyValue($_) ;
99 436 ▶ length $v or last serialise;
Branch: 1 branch
BranchTrueFalseTotal
CORE::length $v or last serialise 33 403 436
100 $p{$_}
101 403 ▶ = $spec->get_property($_)->{default} eq $v ?'':$v;
Branch: 1 branch
BranchTrueFalseTotal
$spec->get_property($_)->{'default'} eq $v ? : 131 272 403
102 }
103 82 return $s->(\%p);
104 }
105 }
106 }}
107  
108 2817 ▶ exists $props->{$name}
Branch: 1 branch
BranchTrueFalseTotal
exists $props->{$name} or return (return "") 199 2618 2817
109 or return return '';
110 2618 my $val = $props->{$name};
111 2618 ▶ return ref $val eq 'ARRAY' ? $$val[0]
Branch: 2 branches
BranchTrueFalseTotal
ref $val eq 'ARRAY' ? : 1592 1026 2618
!ref($val) ? : 978 48 1026
112 : !ref $val ? $val
113 : $val->cssText;
114 }
115  
116 sub getPropertyCSSValue {
117 86 ▶ my $self = shift;
Subroutine getPropertyCSSValue: called CC=6 SCAR=17.9
Pod documented
118 86 ▶ $self->{parser} or return;
Branch: 1 branch
BranchTrueFalseTotal
$self->{"parser"} or return 1 85 86
119 exists +(my $props = $self->{props} || return)->{
120 85 ▶ my $name = lc$_[0]
Branch: 1 branch
BranchTrueFalseTotal
exists((my $props = $self->{"props"} || (return))->{my $name = lc $_[0]}) or return return 4 81 85
Condition50%1/2
$self->{'props'} || (return)
l!l
850
MC/DC0%0/1
$self->{'props'} || (return)
$self->{'props'}
Truth table50%1/2
A
A= $self->{'props'}
Aresult
11
00
121 } or return return;
122 81 my $valref = \$props->{$name};
123 return ref $$valref eq 'ARRAY'
124 ? scalar (
125 $$$valref[1]->can('new')
126 81 ▶ || do {
Branch: 2 branches
BranchTrueFalseTotal
ref $$valref eq 'ARRAY' ? : 69 12 81
$$valref->[1]->can("new") or do { (my $pack = $$valref->[1]) =~ s[::][/]g; require "$pack.pm" } 5 64 69
127 5 (my $pack = $$$valref[1]) =~ s e::e/egg;
128 5 require "$pack.pm";
129 },
130 $$valref =
131 $$$valref[1]->new(
132 owner => $self, property => $name,
133 @$$valref[2..$#$$valref],
134 )
135 ) : $$valref;
136 }
137  
138 sub removeProperty {
139 102 ▶ my $self = shift;
Subroutine removeProperty: called CC=7 SCAR=19.5
Pod documented
140 102 my $name = lc shift;
141  
142 # Get the value so we can return it
143 102 my $val;
144 102 ▶ $val = $self->getPropertyValue($name)
Branch: 1 branch
BranchTrueFalseTotal
if defined wantarray 2 100 102
145 if defined wantarray;
146  
147 # Get names of subprops if we are dealing with a shorthand prop
148 102 my @to_delete;
149 102 ▶ if(my $spec = $self->{parser}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $spec = $self->{"parser"}) 96 6 102
150 96 @to_delete = $spec->subproperty_names($name);
151 }
152 102 ▶ @to_delete or @to_delete = $name;
Branch: 1 branch
BranchTrueFalseTotal
@to_delete or @to_delete = $name 82 20 102
153  
154 # Delete the properties
155 102 for my $name(@to_delete) {
156 175 ▶ delete +($self->{props} || return $val)->{$name};
Condition50%1/2
$self->{'props'} || (return $val)
l!l
1750
MC/DC0%0/1
$self->{'props'} || (return $val)
$self->{'props'}
Truth table50%1/2
A
A= $self->{'props'}
Aresult
11
00
157 175 @{$$self{names}} = grep $_ ne $name,
158 175 ▶ @{$$self{names} || return $val};
Branch: 1 branch
BranchTrueFalseTotal
$self->{"names"} or return $val 0 175 175
159 }
160  
161 102 $val;
162 }
163  
164 sub getPropertyPriority {
165 92 ▶ return ${shift->{pri}||return ''}{lc shift} || ''
Subroutine getPropertyPriority: called CC=3 SCAR=11.1
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
+(shift())->{"pri"} or return "" 0 92 92
Condition100%2/2
${+(shift())->{'pri'} or return '';}{lc shift()} || ''
l!l
488
MC/DC100%1/1
${+(shift())->{'pri'} or return '';}{lc shift()} || ''
${+(shift())->{'pri'} or return '';}{lc shift()}
Truth table100%2/2
A
A= ${+(shift())->{'pri'} or return '';}{lc shift()}
Aresult
11
00
166 }
167  
168 sub setProperty {
169 1085 ▶ my ($self, $name, $value, $priority) = @_;
Subroutine setProperty: called CC=14 SCAR=26.4
Pod documented
170  
171 # short-circuit for the common case
172 1085 ▶ length $value or $self->removeProperty($name),return;
Branch: 1 branch
BranchTrueFalseTotal
CORE::length $value or $self->removeProperty($name), return 31 1054 1085
173  
174 1054 require CSS'DOM'Parser;
175 1054 ▶ my @tokens = eval { CSS'DOM'Parser'tokenise_value($value); }
Branch: 1 branch
BranchTrueFalseTotal
my(@tokens) = eval { do { CSS::DOM::Parser::tokenise_value($value) } } or die "CSS::DOM::Exception"->new(12, $@) 1 1053 1054
176 or die CSS::DOM'Exception->new( SYNTAX_ERR, $@);
177  
178 # check for whitespace/comment assignment
179 1053 ▶ $tokens[0] =~ /^s+\z/ and $self->removeProperty($name),return;
Branch: 1 branch
BranchTrueFalseTotal
$tokens[0] =~ /^s+\z/ and $self->removeProperty($name), return 2 1051 1053
180  
181 1051 ▶ my $props = $$self{props} ||= {};
Condition100%2/2
$self->{"props"} ||= {}
l!l
10465
MC/DC100%1/1
$self->{"props"} ||= {}
$self->{"props"}
Truth table100%2/2
A
A= $self->{"props"}
Aresult
11
00
182 1051 ▶ my $pri = $$self{pri} ||= {};
Condition100%2/2
$self->{"pri"} ||= {}
l!l
10465
MC/DC100%1/1
$self->{"pri"} ||= {}
$self->{"pri"}
Truth table100%2/2
A
A= $self->{"pri"}
Aresult
11
00
183  
184 1051 my $val;
185 1051 ▶ if(my $spec = $self->{parser}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $spec = $self->{"parser"}) 902 149 1051
186 902 ▶ my(@args) = $spec->match($name, @tokens)
Branch: 1 branch
BranchTrueFalseTotal
my(@args) = $spec->match($name, @tokens) or return 27 875 902
187 or return;
188 875 ▶ if(@args == 1) { # shorthand
Branch: 1 branch
BranchTrueFalseTotal
if (@args == 1) { } 117 758 875
189 117 ▶ while(my($k,$v) = each %{ $args[0] }) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %{$args[0];}) 618 117 735
190 618 ▶ $self->removeProperty($k), next
Branch: 1 branch
BranchTrueFalseTotal
if $v eq "" 65 553 618
191 if $v eq "";
192 exists $$props{$k=lc$k}
193 553 ▶ or push @{$$self{names}}, $k;
Branch: 1 branch
BranchTrueFalseTotal
exists $$props{$k = lc $k} or push @{$$self{"names"};}, $k 82 471 553
194 553 $$props{$k} = $v;
195 553 $$pri{$k} = $priority;
196 }
197 117 return;
198 }
199 else {
200 758 $val = \@args;
201 }
202 }
203  
204 907 ▶ exists $$props{$name=lc$name} or push @{$$self{names}}, $name;
Branch: 1 branch
BranchTrueFalseTotal
exists $$props{$name = lc $name} or push @{$$self{"names"};}, $name 135 772 907
205 907 ▶ $$props{$name} = $val || join "", @{ $tokens[1] };
Condition66%2/3
$val || join('', @{$tokens[1];})
l!l&&r!l&&!r
7581490
MC/DC0%0/2
$val || join('', @{$tokens[1];})
$val join('', @{$tokens[1];})
Truth table66%2/3
A || B
A= $valB= join('', @{$tokens[1];})
ABresult
1X1
011
000
206 907 $$pri{$name} = $priority;
207  
208 907 _m($self);
209 return
210 907 }
211  
212 sub item {
213 4 ▶ my $ret = shift->{names}[shift];
Subroutine item: called CC=2 SCAR=6.9
Pod documented
214 4 ▶ return defined $ret ? $ret : ''
Branch: 1 branch
BranchTrueFalseTotal
defined $ret ? : 3 1 4
215 }
216  
217 sub parentRule {
218 shift->{owner}
219 3 ▶}
Subroutine parentRule: called CC=1 SCAR=0.0
Pod documented
220  
221 sub _set_property_tokens { # private
222 631 ▶ my ($self,$name,$types,$tokens) = @_;
Subroutine _set_property_tokens: called CC=13 SCAR=25.7
223  
224 # Parse out the priority first
225 631 my $priority;
226 631 ▶ if($types =~ /(s?(ds?))i\z/ and $tokens->[$-[2]] eq '!') {
Branch: 1 branch
BranchTrueFalseTotal
if ($types =~ /(s?(ds?))i\z/ and $$tokens[$-[2]] eq '!') { } 3 628 631
Condition66%2/3
$types =~ /(s?(ds?))i\z/ and $$tokens[$-[2]] eq "!"
!ll&&!rl&&r
62803
MC/DC50%1/2
$types =~ /(s?(ds?))i\z/ and $$tokens[$-[2]] eq "!"
$types =~ /(s?(ds?))i\z/ $$tokens[$-[2]] eq "!"
Truth table66%2/3
A and B
A= $types =~ /(s?(ds?))i\z/B= $$tokens[$-[2]] eq "!"
ABresult
0X0
100
111
227 3 $types =~ s///;
228 3 $priority = unescape pop @$tokens;
229 3 pop @$tokens for 1..length $1;
230 } else {
231 628 $priority = '';
232 }
233  
234 # Get the prop & priority hashes
235 631 ▶ my $props = $$self{props} ||= {};
Condition100%2/2
$self->{"props"} ||= {}
l!l
133498
MC/DC100%1/1
$self->{"props"} ||= {}
$self->{"props"}
Truth table100%2/2
A
A= $self->{"props"}
Aresult
11
00
236 631 ▶ my $pri = $$self{pri} ||={};
Condition100%2/2
$self->{"pri"} ||= {}
l!l
133498
MC/DC100%1/1
$self->{"pri"} ||= {}
$self->{"pri"}
Truth table100%2/2
A
A= $self->{"pri"}
Aresult
11
00
237  
238 # See if we need to parse the value
239 631 my $val;
240 631 ▶ if(my $spec = $self->{parser}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $spec = $self->{'parser'}) { } 13 618 631
241 13 ▶ my(@args) = $spec->match($name,$types,$tokens)
Branch: 1 branch
BranchTrueFalseTotal
my(@args) = $spec->match($name, $types, $tokens) or return 4 9 13
242 or return;
243 9 ▶ if(@args == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (@args == 1) { } 1 8 9
244 1 ▶ while(my($k,$v) = each %{ $args[0] }) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %{$args[0];}) 3 1 4
245 3 ▶ $self->removeProperty($k), next
Branch: 1 branch
BranchTrueFalseTotal
if $v eq "" 1 2 3
246 if $v eq "";
247 exists $$props{$k=lc$k}
248 2 ▶ or push @{$$self{names}}, $k;
Branch: 1 branch
BranchTrueFalseTotal
exists $$props{$k = lc $k} or push @{$$self{"names"};}, $k 2 0 2
249 2 $$props{$k} = $v;
250 2 $$pri{$k} = $priority;
251 }
252 1 return;
253 }
254 else {
255 8 $val = \@args;
256 }
257 }
258 618 else { $val = join "", @$tokens }
259  
260 # Assign the value & priority
261 626 ▶ exists $$props{$name=lc$name} or push @{$$self{names}}, $name;
Branch: 1 branch
BranchTrueFalseTotal
exists $$props{$name = lc $name} or push @{$$self{"names"};}, $name 626 0 626
262 626 $$props{$name} = $val;
263 626 $$pri{$name} = $priority;
264 }
265  
266  
267 22 { my $prop_re = qr/[a-z]+(?:[A-Z][a-z]+)*/;
268 sub can {
269 0 ▶ SUPER::can { shift } @_ or
Branch: 1 branch
BranchTrueFalseTotal
$_[0] =~ /^$prop_re\z/o ? : 0 0 0
270 0 ▶ $_[0] =~ /^$prop_re\z/o ? \&{+shift} : undef;
Subroutine can: not called CC=3 SCAR=24.8
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
do { shift() }->SUPER::can(@_) or $_[0] =~ /^$prop_re\z/o ? \&{shift();} : undef 0 0 0
271 }
272 sub AUTOLOAD {
273 2187 ▶ my $self = shift;
Subroutine AUTOLOAD: called CC=4 SCAR=14.0
274 2187 ▶ if(our $AUTOLOAD =~ /(?<=:)($prop_re)\z/o) {
Branch: 1 branch
BranchTrueFalseTotal
if (our $AUTOLOAD =~ /(?<=:)($prop_re)\z/o) { } 2187 0 2187
275 2187 (my $prop = $1) =~ s/([A-Z])/-\l$1/g;
276 2187 my $val;
277 defined wantarray
278 2187 ▶ and $val = $self->getPropertyValue($prop);
Branch: 1 branch
BranchTrueFalseTotal
defined wantarray and $val = $self->getPropertyValue($prop) 1273 914 2187
279 2187 ▶ @_ and $self->setProperty($prop, shift);
Branch: 1 branch
BranchTrueFalseTotal
@_ and $self->setProperty($prop, shift()) 1037 1150 2187
280 2187 return $val;
281 } else {
282 0 die "Undefined subroutine $AUTOLOAD called at ",
283 join(" line ", (caller)[1,2]), ".\n";
284 }
285 }
286 ▶sub DESTROY{}
Subroutine DESTROY: not called CC=1 SCAR=0.0
287 }
288 22 *cssFloat = \&float;
289  
290 sub modification_handler {
291 110 ▶ my $old = (my $self = shift)->{mod_handler};
Subroutine modification_handler: called CC=2 SCAR=6.9
Pod documented
292 110 ▶ $self->{mod_handler} = shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 4 106 110
293 110 $old;
294 }
295  
296 sub _m#odified
297 {
298 912 ▶ &{$_[0]->{mod_handler} or return}($_[0]);
Subroutine _m: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
$_[0]{"mod_handler"} or return 904 8 912
299 }
300  
301 97 ▶sub property_parser { shift->{parser} }
Subroutine property_parser: called CC=1 SCAR=0.0
Pod documented
302  
303 sub length { # We put this one last to avoid having to say CORE::length
304 # elsewhere.
305 5 ▶ scalar @{shift->{names}||return 0}
Subroutine length: called CC=2 SCAR=6.9
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
+(shift())->{"names"} or return 0 1 4 5
306 }
307  
308  
309  
310 22 !()__END__()!
311  
312 =head1 NAME
313  
314 CSS::DOM::Style - CSS style declaration class for CSS::DOM
315  
316 =head1 VERSION
317  
318 Version 0.16
319  
320 =head1 SYNOPSIS
321  
322 use CSS::DOM::Style;
323
324 $style = CSS::DOM::Style::parse(' text-decoration: none ');
325
326 $style->cssText; # returns 'text-decoration: none'
327 $style->cssText('color: blue'); # replace contents
328
329 $style->getPropertyValue('color'); # 'blue'
330 $style->color; # same
331 $style->setProperty(color=>'green'); # change it
332 $style->color('green'); # same
333  
334 =head1 DESCRIPTION
335  
336 This module provides the CSS style declaration class for L<CSS::DOM>. (A
337 style declaration is what comes between the braces in C<p { margin: 0 }>.)
338 It
339 implements
340 the CSSStyleDeclaration DOM interface.
341  
342 =head1 CONSTRUCTORS
343  
344 =over 4
345  
346 =item CSS::DOM::Style::parse( $string )
347  
348 =item CSS::DOM::Style::parse( $string, property_parser => $parser )
349  
350 This parses the C<$string> and returns a new style declaration
351 object. This is useful if you have text from an HTML C<style> attribute,
352 for instance.
353  
354 For details on C<$property_parser>, see L<CSS::DOM::PropertyParser>.
355  
356 =item new CSS::DOM::Style $owner_rule
357  
358 =item new CSS::DOM::Style owner => $owner_rule, property_parser => $p
359  
360 You don't normally need to call this, but, in case you do, here it is.
361 C<$owner_rule>, which is optional, is expected to be a L<CSS::DOM::Rule>
362 object, or a subclass like L<CSS::DOM::Rule::Style>.
363  
364 =back
365  
366 =head1 METHODS
367  
368 =over 4
369  
370 =item cssText ( $new_value )
371  
372 Returns the body of this style declaration (without the braces). If you
373 pass an argument, it will parsed and replace the existing CSS data.
374  
375 =item getPropertyValue ( $name )
376  
377 Returns the value of the named CSS property as a string.
378  
379 =item getPropertyCSSValue ( $name )
380  
381 Returns an object representing the property's value.
382 (See L<CSS::DOM::Value>.)
383  
384 =item removeProperty ( $name )
385  
386 Removes the named property, returning its value.
387  
388 =item getPropertyPriority
389  
390 Returns the property's priority. This is usually the empty string or the
391 word 'important'.
392  
393 =item setProperty ( $name, $value, $priority )
394  
395 Sets the CSS property named C<$name>, giving it a value of C<$value> and
396 setting the priority to C<$priority>.
397  
398 =item length
399  
400 Returns the number of properties
401  
402 =item item ( $index )
403  
404 Returns the name of the property at the given index.
405  
406 =item parentRule
407  
408 Returns the rule to which this declaration belongs.
409  
410 =item modification_handler ( $coderef )
411  
412 This method, not part of the DOM, allows you to attach a call-back routine
413 that is run whenever a change occurs to the style object (with the style
414 object as its only argument). If you call it
415 without an argument it returns the current handler. With an argument, it
416 returns the old value after setting it.
417  
418 =item property_parser
419  
420 This returns the parser that was passed to the constructor.
421  
422 =back
423  
424 This module also has methods for accessing each CSS property directly.
425 Simply capitalise each letter in a CSS property name that follows a hyphen,
426 then remove the hyphens, and you'll have the method name. E.g., call the
427 C<borderBottomWidth> method to get/set the border-bottom-width property.
428 One exception to this is that C<cssFloat> is the method used to access the
429 'float' property. (But you can also use the C<float> method, though it's
430 not part of the DOM standard.)
431  
432 =head1 SEE ALSO
433  
434 L<CSS::DOM>
435  
436 L<CSS::DOM::Rule::Style>
437  
438 L<CSS::DOM::PropertyParser>
439  
440 L<HTML::DOM::Element>
« DOM.pm ↑ Summary DOM/Value/List.pm »