DOM/Value.pm

filter: Statementstmt 96.8% 62 / 64 Branchbran 90.9% 20 / 22 Conditioncond 33.3% 2 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 100% 15 / 15 Podpod 66.6% 2 / 3 totaltotal 88.6% 101 / 114 CC 14 SCAR 13.4
CC
14
Cov
91%
cssText
8.0
new
4.3
_apply_args_to_self
3.0
CRAP 3.8
« DOM/Rule/Import.pm ↑ Summary DOM/Rule/Media.pm »
1 package CSS::DOM::Value;
2  
3 3 $VERSION = '0.16';
4  
5 3 ▶use warnings; no warnings qw 'utf8 parenthesis';;
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
6 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 3 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 3 ▶use CSS::DOM::Constants;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 3 ▶use CSS'DOM'Exception 'NO_MODIFICATION_ALLOWED_ERR';
Subroutine BEGIN: called CC=1 SCAR=0.0
11 3 ▶use Exporter 5.57 'import';
Subroutine BEGIN: called CC=1 SCAR=0.0
12 3 ▶use Scalar'Util < weaken reftype >;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 3 use constant 1.03 our $_const = {
15 type => 0,
16 valu => 1,
17 ownr => 2,
18 prop => 3,
19 3 ▶};
Subroutine BEGIN: called CC=1 SCAR=0.0
20 3 ▶{ no strict; delete @{__PACKAGE__.'::'}{_const => keys %{our $_const}} }
Subroutine BEGIN: called CC=1 SCAR=0.0
21  
22 3 *EXPORT_OK = $CSS::DOM::Constants::EXPORT_TAGS{value};
23 3 our %EXPORT_TAGS = ( all => \our @EXPORT_OK );
24  
25 sub new {
26 15 ▶ my $self = bless[], shift;
Subroutine new: called CC=4 SCAR=14.6
Pod undocumented
27 15 my %args = @_;
28 15 my $type = $self->[type] = $args{type};
29 $type == CSS_CUSTOM
30 15 ▶ ? !exists $args{value} && croak
Branch: 1 branch
BranchTrueFalseTotal
$type == 3 ? : 6 9 15
Condition33%2/6
exists $args{"value"} or croak("new CSS::DOM::Value(type => CSS_CUSTOM) requires a value")
l!l&&r!l&&!r
600
$type == 0 or croak("Type must be CSS_CUSTOM or CSS_INHERIT")
l!l&&r!l&&!r
900
MC/DC0%0/2
exists $args{"value"} or croak("new CSS::DOM::Value(type => CSS_CUSTOM) requires a value")
exists $args{"value"} croak("new CSS::DOM::Value(type => CSS_CUSTOM) requires a value")
MC/DC0%0/2
$type == 0 or croak("Type must be CSS_CUSTOM or CSS_INHERIT")
$type == 0 croak("Type must be CSS_CUSTOM or CSS_INHERIT")
Truth table33%1/3
A or B
A= exists $args{"value"}B= croak("new CSS::DOM::Value(type => CSS_CUSTOM) requires a value")
ABresult
1X1
011
000
Truth table33%1/3
A or B
A= $type == 0B= croak("Type must be CSS_CUSTOM or CSS_INHERIT")
ABresult
1X1
011
000
31 'new CSS::DOM::Value(type => CSS_CUSTOM) requires a value'
32 : $type == CSS_INHERIT
33 || croak "Type must be CSS_CUSTOM or CSS_INHERIT";
34  
35 15 @$self[valu,ownr,prop] = @args{< value owner property >};
36 15 weaken $$self[ownr];
37  
38 15 $self;
39 }
40  
41 7 ▶sub cssValueType { shift->[type] }
Subroutine cssValueType: called CC=1 SCAR=0.0
Pod documented
42  
43 sub cssText {
44 14 ▶ my $self = shift;
Subroutine cssText: called CC=8 SCAR=20.8
Pod documented
45 14 ▶ my $old = $self->[type] == CSS_CUSTOM
Branch: 2 branches
BranchTrueFalseTotal
if defined wantarray 8 6 14
$self->[0] == 3 ? : 4 4 8
46 ? $self->[valu] : 'inherit'
47 if defined wantarray;
48 14 ▶ if(@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 6 8 14
49 6 ▶ die new CSS'DOM'Exception
Branch: 1 branch
BranchTrueFalseTotal
unless my $owner = $self->[2] 1 5 6
50 NO_MODIFICATION_ALLOWED_ERR,
51 "Unowned value objects cannot be modified"
52 unless my $owner = $self->[ownr];
53 5 ▶ die new CSS'DOM'Exception
Branch: 1 branch
BranchTrueFalseTotal
unless my $prop = $self->[3] 1 4 5
54 NO_MODIFICATION_ALLOWED_ERR,
55 "CSS::DOM::Value objects that do not know to which "
56 ."property they belong cannot be modified"
57 unless my $prop = $self->[prop];
58  
59 4 ▶ if(
Branch: 1 branch
BranchTrueFalseTotal
if (my(@arsg) = $owner->property_parser->match($prop, $_[0])) 4 0 4
60 my @arsg
61 = $owner->property_parser->match($prop, $_[0])
62 ) {
63 4 _apply_args_to_self($self,$owner,$prop,@arsg);
64 }
65  
66 4 ▶ if(my $mh = $owner->modification_handler) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $mh = $owner->modification_handler) 1 3 4
67 1 &$mh();
68 }
69 }
70 $old
71 12 }
72  
73 sub _apply_args_to_self {
74 50 ▶ my($self,$owner,$prop,@arsg) = @_;
Subroutine _apply_args_to_self: called CC=3 SCAR=11.0
75 50 _load_if_necessary($arsg[1]);
76 50 my $new = $arsg[1]->new(
77 owner => $owner, property => $prop, @arsg[2...$#arsg]
78 );
79 50 ▶ reftype $self eq "HASH"
Branch: 1 branch
BranchTrueFalseTotal
builtin::reftype($self) eq 'HASH' ? : 2 48 50
80 ? %$self = %$new
81 : (@$self = @$new);
82 50 ▶ bless $self, ref $new unless ref $new eq ref $self;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $new eq ref $self 3 47 50
83 }
84  
85 sub _load_if_necessary {
86 $_[0]->can('new')
87 59 ▶ || do {
Subroutine _load_if_necessary: called CC=2 SCAR=10.5
Branch: 1 branch
BranchTrueFalseTotal
$_[0]->can("new") or do { (my $pack = $_[0]) =~ s[::][/]g; require "$pack.pm" } 0 59 59
88 0 (my $pack = $_[0]) =~ s e::e/egg;
89 0 require "$pack.pm";
90 };
91 }
92  
93 3 !()__END__()!
94  
95 =head1 NAME
96  
97 CSS::DOM::Value - CSSValue class for CSS::DOM
98  
99 =head1 VERSION
100  
101 Version 0.16
102  
103 =head1 SYNOPSIS
104  
105 # ...
106  
107 =head1 DESCRIPTION
108  
109 This module implements objects that represent CSS property values. It
110 implements the DOM CSSValue interface.
111  
112 This class is used only for custom values (neither primitive values nor
113 lists) and the special 'inherit' value.
114  
115 =head1 METHODS
116  
117 =head2 Object Methods
118  
119 =over 4
120  
121 =item cssText
122  
123 Returns a string representation of the attribute. Pass an argument to set
124 it.
125  
126 =item cssValueType
127  
128 Returns one of the constants below.
129  
130 =back
131  
132 =head2 Constructor
133  
134 You probably don't need to call this, but here it is anyway:
135  
136 $val = new CSS::DOM::Value %arguments;
137  
138 The hash-style C<%arguments> are as follows:
139  
140 =over
141  
142 =item type
143  
144 C<CSS_INHERIT> or C<CSS_CUSTOM>
145  
146 =item css
147  
148 A string of CSS code. This is
149 only used when C<TYPE> is C<CSS_CUSTOM>.
150  
151 =item owner
152  
153 The style object that owns this value; if this is omitted, then the value
154 is read-only. The value object holds a weak reference to the owner.
155  
156 =item property
157  
158 The name of the CSS property to which this value belongs. C<cssText> uses
159 this to determine how to parse text passed to it.
160  
161 =back
162  
163 =head1 CONSTANTS
164  
165 The following constants can be imported with C<use CSS::DOM::Value ':all'>.
166 They represent the type of CSS value.
167  
168 =over
169  
170 =item CSS_INHERIT (0)
171  
172 =item CSS_PRIMITIVE_VALUE (1)
173  
174 =item CSS_VALUE_LIST (2)
175  
176 =item CSS_CUSTOM (3)
177  
178 =back
179  
180 =head1 SEE ALSO
181  
182 L<CSS::DOM>
183  
184 L<CSS::DOM::Value::Primitive>
185  
186 L<CSS::DOM::Value::List>
187  
188 L<CSS::DOM::Style>
« DOM/Rule/Import.pm ↑ Summary DOM/Rule/Media.pm »