DOM/Value/List.pm

filter: Statementstmt 98.4% 65 / 66 Branchbran 76.4% 26 / 34 Conditioncond 80.0% 4 / 5 MC/DCmcdc 66.6% 2 / 3 Subroutinesub 100% 12 / 12 Podpod 66.6% 4 / 6 totaltotal 89.6% 113 / 126 CC 22 SCAR 20.7
CC
22
Cov
90%
cssText
14.0
item
6.2
DOES
5.7
CRAP 8.0
« DOM/Style.pm ↑ Summary DOM/Rule/Import.pm »
1 package CSS::DOM::Value::List;
2  
3 4 $VERSION = '0.16';
4  
5 4 ▶use CSS'DOM'Constants <CSS_VALUE_LIST NO_MODIFICATION_ALLOWED_ERR>;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 4 ▶use Scalar'Util 'weaken';
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 # Object of this class are hashes, with the following keys:
9 # c: CSS code
10 # v: values
11 # s: separator
12 # o: owner
13 # p: property
14  
15 sub DOES {
16 1 ▶ return 1 if $_[1] eq 'CSS::DOM::Value';
Subroutine DOES: called CC=3 SCAR=17.3
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
if $_[1] eq "CSS::DOM::Value" 1 0 1
17 0 ▶ goto &UNIVERSAL'DOES if defined &UNIVERSAL'DOES;
Branch: 1 branch
BranchTrueFalseTotal
if defined &UNIVERSAL::DOES 0 0 0
18 }
19  
20 use overload
21 fallback => 1,
22 4 ▶ '@{}' => sub { tie my @shext, __PACKAGE__, shift; \@shext };
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
23  
24 sub new {
25 30 ▶ my $class = shift;
Subroutine new: called CC=1 SCAR=0.0
Pod undocumented
26 30 my %args = @_;
27 30 my %self;
28 @self{< c v s o p >}
29 30 = @args{< css values separator owner property >};
30 30 weaken $self{o};
31 30 bless \%self, $class;
32 }
33  
34 sub cssText {
35 25 ▶ my $self = shift;
Subroutine cssText: called CC=14 SCAR=26.4
Pod documented
36 25 my $old;
37 25 ▶ if(defined wantarray) {{
Branch: 1 branch
BranchTrueFalseTotal
if (defined wantarray) 21 4 25
38 21 ▶ if(!defined $$self{c} || grep ref ne 'ARRAY', @{$$self{v}}) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $self->{'c'} or grep((ref $_ ne 'ARRAY'), @{$$self{'v'};})) { } 14 7 21
Condition100%3/3
not defined $self->{"c"} or grep((ref $_ ne "ARRAY"), @{$$self{"v"};})
l!l&&r!l&&!r
597
MC/DC100%2/2
not defined $self->{"c"} or grep((ref $_ ne "ARRAY"), @{$$self{"v"};})
not defined $self->{"c"} grep((ref $_ ne "ARRAY"), @{$$self{"v"};})
Truth table100%3/3
not(A) or B
A= not defined $self->{"c"}B= grep((ref $_ ne "ARRAY"), @{$$self{"v"};})
ABresult
1X1
011
000
39 14 ▶ @{$$self{v}} or $old = 'none', last;
Branch: 1 branch
BranchTrueFalseTotal
@{$self->{"v"};} or $old = "none", last 1 13 14
40 13 require CSS'DOM'Value'Primitive;
41 13 my @args; my $index = 0;
42 13 for(@{$$self{v}}) {
43 18 ▶ next unless ref eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $_ eq "ARRAY" 12 6 18
44 @args or @args = (
45 6 ▶ (owner => property => @$self{<o p>})[0,2,1,3], index => $index
Branch: 1 branch
BranchTrueFalseTotal
@args or @args = (("owner", "property", @$self{glob "o p"})[0, 2, 1, 3], "index", $index) 4 2 6
46 );
47 6 $_ = new CSS'DOM'Value'Primitive @$_, @args;
48 }
49 4 ▶ no warnings 'uninitialized';
Subroutine BEGIN: called CC=1 SCAR=0.0
50 $old = join length $$self{s} ? $$self{s} : ' ',
51 13 ▶ map cssText $_, @{$$self{v}}
Branch: 1 branch
BranchTrueFalseTotal
CORE::length $self->{'s'} ? : 7 6 13
52 }
53 7 else { $old = $$self{c} }
54 }}
55 25 ▶ if(@_) { # assignment
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 4 21 25
56 die new CSS'DOM'Exception
57 NO_MODIFICATION_ALLOWED_ERR,
58 "Unowned value objects cannot be modified"
59 4 ▶ unless my $owner = $self->{o};
Branch: 1 branch
BranchTrueFalseTotal
unless my $owner = $self->{"o"} 1 3 4
60 die new CSS'DOM'Exception
61 NO_MODIFICATION_ALLOWED_ERR,
62 "CSS::DOM::Value objects that do not know to which "
63 ."property they belong cannot be modified"
64 3 ▶ unless my $prop = $self->{p};
Branch: 1 branch
BranchTrueFalseTotal
unless my $prop = $self->{"p"} 1 2 3
65
66 2 ▶ if(
Branch: 1 branch
BranchTrueFalseTotal
if (my(@arsg) = $owner->property_parser->match($prop, $_[0])) 2 0 2
67 my @arsg
68 = $owner->property_parser->match($prop, $_[0])
69 ) {
70 2 require CSS'DOM'Value;
71 2 CSS'DOM'Value::_apply_args_to_self($self,$owner,$prop,@arsg);
72 }
73  
74 2 ▶ if(my $mh = $owner->modification_handler) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $mh = $owner->modification_handler) 2 0 2
75 2 &$mh();
76 }
77 }
78 23 $old;
79 }
80  
81 10 ▶sub cssValueType { CSS_VALUE_LIST }
Subroutine cssValueType: called CC=1 SCAR=0.0
Pod documented
82  
83 sub item {
84 24 ▶ my($self, $index) = @_;
Subroutine item: called CC=6 SCAR=18.3
Pod documented
85 24 ▶ my $v = $self->{v} || return;
Condition50%1/2
$self->{'v'} || (return)
l!l
240
MC/DC0%0/1
$self->{'v'} || (return)
$self->{'v'}
Truth table50%1/2
A
A= $self->{'v'}
Aresult
11
00
86 24 ▶ exists $$v[$index] or return;
Branch: 1 branch
BranchTrueFalseTotal
exists $v->[$index] or return 0 24 24
87  
88 24 for($$v[$index]) {
89 24 ▶ defined or return;
Branch: 1 branch
BranchTrueFalseTotal
defined $_ or return 0 24 24
90 24 ▶ ref eq 'ARRAY' or return exit die return $_;
Branch: 1 branch
BranchTrueFalseTotal
ref $_ eq "ARRAY" or return exit die((return $_)) 3 21 24
91  
92 21 require CSS'DOM'Value'Primitive;
93 return $_ = new CSS'DOM'Value'Primitive
94 @$_,
95 21 (owner => property => @$self{<o p>})[0,2,1,3],
96 index => $index;
97 }
98 }
99  
100 21 ▶sub length { scalar @{ shift->{v} || return 0 } }
Subroutine length: called CC=2 SCAR=7.2
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
+(shift())->{"v"} or return 0 0 21 21
101  
102 4 *FETCH = *item;
103 4 *FETCHSIZE = *length;
104 9 ▶sub TIEARRAY { $_[1] }
Subroutine TIEARRAY: called CC=1 SCAR=0.0
105  
106  
107  
108 4 (undef) = (undef) __END__
109  
110 =head1 NAME
111  
112 CSS::DOM::Value::List - CSSValueList class for CSS::DOM
113  
114 =head1 VERSION
115  
116 Version 0.16
117  
118 =head1 SYNOPSIS
119  
120 # ...
121  
122 =head1 DESCRIPTION
123  
124 This module implements objects that represent CSS list property
125 values. It
126 implements the DOM CSSValueList interface.
127  
128 You can access the individual elements of the list using the C<item> and
129 C<length> methods, or by using it as an array ref.
130  
131 =head1 METHODS
132  
133 If you need the constructor, it's below the object methods. Normally you
134 would get an object via L<CSS::DOM::Style's C<getPropertyCSSValue>
135 method|CSS::DOM::Style/getPropertyCSSValue>.
136  
137 =head2 CSSValue Interface
138  
139 =over 4
140  
141 =item cssText
142  
143 Returns a string representation of the attribute. Pass an argument to set
144 it.
145  
146 =item cssValueType
147  
148 Returns C<CSS::DOM::Value::CSS_PRIMITIVE_VALUE>.
149  
150 =back
151  
152 =head2 CSSValueList Interface
153  
154 =over
155  
156 =item item
157  
158 Returns the 'primitive' value at the given index.
159  
160 =item length
161  
162 Returns the number of values in the list.
163  
164 =back
165  
166 =head2 Constructor
167  
168 You probably don't need to call this, but here it is anyway:
169  
170 $val = new CSS::DOM::Value::List:: %args;
171  
172 The hash-style arguments are as follows. Only C<values> is
173 required.
174  
175 =over
176  
177 =item values
178  
179 This must be an array ref containing the individual values to be stored in
180 the list. The individual elements can be value objects or array refs of
181 arguments to pass to C<< new CSS::DOM::Value::Primitive >>. E.g.,
182  
183 [
184 [type => CSS_PX, value => 20],
185 [type => CSS_PERCENTAGE, value => 50],
186 [type => CSS_PERCENTAGE, value => 50],
187 [type => CSS_PX, value => 50],
188 ]
189  
190 =item css
191  
192 CSS code used for serialisation. This will make reading C<cssText> faster
193 at least until the value is modified.
194  
195 =item separator
196  
197 The value separator used in serialisation. This is usually S<' '> or
198 S<', '>. An empty string or C<undef> is treated as a space.
199  
200 =item owner
201  
202 The style object that owns this value; if this is omitted, then the value
203 is read-only. The value object holds a weak reference to the owner.
204  
205 =item property
206  
207 The name of the CSS property to which this value belongs. C<cssText> uses
208 this to determine how to parse text passed to it. This does not
209 apply to the sub-values of colours, counters and rects, but it I<does>
210 apply to individual elements of a list value.
211  
212 =back
213  
214 =head1 SEE ALSO
215  
216 L<CSS::DOM>
217  
218 L<CSS::DOM::Value>
219  
220 L<CSS::DOM::Value::Primitive>
221  
222 L<CSS::DOM::Style>
« DOM/Style.pm ↑ Summary DOM/Rule/Import.pm »