Object.pm

filter: Statementstmt 81.3% 166 / 204 Branchbran 38.4% 30 / 78 Conditioncond 38.4% 10 / 26 MC/DCmcdc 0.0% 0 / 14 Subroutinesub 84.4% 38 / 45 Podpod 87.5% 21 / 24 totaltotal 67.7% 265 / 391 CC 56 SCAR 22.0
CC
56
Cov
67%
read_string
56.0
__ANON__
12.0
remove_rule
12.0
CRAP 9.0
« Object/Parser/Default.pm ↑ Summary Object/Element.pm »
1 ##----------------------------------------------------------------------------
2 ## CSS Object Oriented - ~/lib/CSS/Object.pm
3 ## Version v0.1.5
4 ## Copyright(c) 2021 DEGUEST Pte. Ltd.
5 ## Author: Jacques Deguest <jack@deguest.jp>
6 ## Created 2020/06/24
7 ## Modified 2021/11/28
8 ## All rights reserved
9 ##
10 ## This program is free software; you can redistribute it and/or modify it
11 ## under the same terms as Perl itself.
12 ##----------------------------------------------------------------------------
13 package CSS::Object;
14 BEGIN
15 {
16 6 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 6 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 6 ▶ use warnings::register;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 6 ▶ use parent qw( Module::Generic );
Subroutine BEGIN: called CC=1 SCAR=0.0
20 6 ▶ use CSS::Object::Builder;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 6 ▶ use CSS::Object::Comment;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 6 ▶ use CSS::Object::Format;
Subroutine BEGIN: called CC=1 SCAR=0.0
23 6 ▶ use CSS::Object::Property;
Subroutine BEGIN: called CC=1 SCAR=0.0
24 6 ▶ use CSS::Object::Rule;
Subroutine BEGIN: called CC=1 SCAR=0.0
25 6 ▶ use CSS::Object::Rule::At;
Subroutine BEGIN: called CC=1 SCAR=0.0
26 6 ▶ use CSS::Object::Rule::Keyframes;
Subroutine BEGIN: called CC=1 SCAR=0.0
27 6 ▶ use CSS::Object::Selector;
Subroutine BEGIN: called CC=1 SCAR=0.0
28 6 ▶ use CSS::Object::Value;
Subroutine BEGIN: called CC=1 SCAR=0.0
29 6 ▶ use Want ();
Subroutine BEGIN: called CC=1 SCAR=0.0
30 6 ▶ use Devel::Confess;
Subroutine BEGIN: called CC=1 SCAR=0.0
31 6 ▶ our $VERSION = 'v0.1.5';
Subroutine BEGIN: called CC=1 SCAR=0.0
32 };
33  
34 sub init
35 {
36 6 ▶ my $self = shift( @_ );
Subroutine init: called CC=3 SCAR=11.0
Pod documented
37 6 $self->{parser} = 'CSS::Object::Parser::Default';
38 6 $self->{format} = '';
39 6 $self->{_init_strict_use_sub} = 1;
40 6 ▶ $self->SUPER::init( @_ ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->SUPER::init(@_) or return $self->pass_error 0 6 6
41 # $self->message( 3, "Formatter class set: '", ref( $self->format ), "'." );
42 6 ▶ unless( $self->_is_a( $self->{format}, 'CSS::Object::Format' ) )
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_is_a($self->{"format"}, "CSS::Object::Format")) 3 3 6
43 {
44 3 my $format = CSS::Object::Format->new(
45 debug => $self->debug
46 );
47 3 $self->format( $format );
48 }
49 6 $self->{rules} = Module::Generic::Array->new;
50 6 return( $self );
51 }
52  
53 # Add comment at the top level. To add comment inside a rule, see add_element in CSS::Object::Rule
54 sub add_element
55 {
56 1 ▶ my $self = shift( @_ );
Subroutine add_element: called CC=3 SCAR=11.2
Pod documented
57 1 ▶ my $elem = shift( @_ ) || return( $self->error( "No element object was provided to add to this rule." ) );
Condition50%1/2
shift @_ || (return $self->error('No element object was provided to add to this rule.'))
l!l
10
MC/DC0%0/1
shift @_ || (return $self->error('No element object was provided to add to this rule.'))
shift @_
Truth table50%1/2
A
A= shift @_
Aresult
11
00
58 1 ▶ return( $self->error( "Element object provided ($elem) is not a CSS::Object::Element object." ) ) if( !$self->_is_a( $elem, 'CSS::Object::Element' ) );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_is_a($elem, "CSS::Object::Element") 0 1 1
59 # $self->message( 3, "Adding element object '$elem'." );
60 # $elem->format( $self->format );
61 1 $elem->debug( $self->debug );
62 # $self->properties->push( $prop );
63 1 $self->elements->push( $elem );
64 1 return( $self );
65 }
66  
67 sub add_rule
68 {
69 9 ▶ my $self = shift( @_ );
Subroutine add_rule: called CC=3 SCAR=11.1
Pod documented
70 9 my $rule = shift( @_ );
71 9 $self->message( 4, "CSS rule provided to add to our stack of elements: '", overload::StrVal( $rule ), "'." );
72 9 ▶ return( $self->error( "No rule object was provided to add." ) ) if( !defined( $rule ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $rule 0 9 9
73 9 ▶ return( $self->error( "Object provided is not a CSS::Object::Rule object." ) ) if( !$self->_is_a( $rule, 'CSS::Object::Rule' ) );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_is_a($rule, "CSS::Object::Rule") 0 9 9
74 # $self->rules->push( $rule );
75 9 $self->elements->push( $rule );
76 9 $self->message( 4, "Returning rule object added: '", overload::StrVal( $rule ), "'. Now we have ", $self->elements->length, " rules stored." );
77 9 return( $rule );
78 }
79  
80 sub as_string
81 {
82 2 ▶ my $self = shift( @_ );
Subroutine as_string: called CC=4 SCAR=18.5
Pod documented
83 2 $self->messagef( 3, "There are %d elements in our stack.", $self->elements->length );
84 2 ▶ if( @_ )
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 2 2
85 {
86 0 my $format = shift( @_ );
87 0 ▶ return( $self->error( "Provided parameter to as_string was not an CSS::Object::Format object." ) ) if( $format !~ /^CSS\::Object\::Format/ && !$self->_is_a( $format, 'CSS::Object::Format' ) );
Branch: 1 branch
BranchTrueFalseTotal
unless $format =~ /^CSS\::Object\::Format/ or $self->_is_a($format, "CSS::Object::Format") 0 0 0
Condition0%0/3
$format =~ /^CSS\::Object\::Format/ or $self->_is_a($format, "CSS::Object::Format")
l!l&&r!l&&!r
000
MC/DC0%0/2
$format =~ /^CSS\::Object\::Format/ or $self->_is_a($format, "CSS::Object::Format")
$format =~ /^CSS\::Object\::Format/ $self->_is_a($format, "CSS::Object::Format")
Truth table0%0/3
A or B
A= $format =~ /^CSS\::Object\::Format/B= $self->_is_a($format, "CSS::Object::Format")
ABresult
1X1
011
000
88 $self->elements->foreach(sub
89 {
90 0 ▶ shift->format( $format );
Subroutine __ANON__: not called CC=1 SCAR=6.9
91 0 });
92 }
93  
94 2 my $output = Module::Generic::Array->new;
95 # $self->rules->foreach(sub
96 $self->elements->foreach(sub
97 {
98 4 ▶ $output->push( shift->as_string );
Subroutine __ANON__: called CC=1 SCAR=0.0
99 2 });
100 2 my $nl = $self->format->new_line;
101 2 return( $output->join( "$nl$nl" )->scalar );
102 }
103  
104 sub builder
105 {
106 1 ▶ my $self = shift( @_ );
Subroutine builder: called CC=3 SCAR=11.3
Pod documented
107 1 ▶ return( $self->{_builder} ) if( $self->_is_object( $self->{_builder} ) );
Branch: 1 branch
BranchTrueFalseTotal
if $self->_is_object($self->{"_builder"}) 0 1 1
108 # $self->message( 3, "Creating builder object with debug set to '", $self->debug, "' and formatter set to '", $self->format->class, "'." );
109 1 ▶ my $b = CSS::Object::Builder->new( $self, debug => $self->debug ) ||
Condition50%1/2
'CSS::Object::Builder'->new($self, 'debug', $self->debug) || (return $self->error('Could not initialise the CSS builder: ', 'CSS::Object::Builder'->error))
l!l
10
MC/DC0%0/1
'CSS::Object::Builder'->new($self, 'debug', $self->debug) || (return $self->error('Could not initialise the CSS builder: ', 'CSS::Object::Builder'->error))
'CSS::Object::Builder'->new($self, 'debug', $self->debug)
Truth table50%1/2
A
A= 'CSS::Object::Builder'->new($self, 'debug', $self->debug)
Aresult
11
00
110 return( $self->error( "Could not initialise the CSS builder: ", CSS::Object::Builder->error ) );
111 1 $self->{_builder} = $b;
112 1 return( $b );
113 }
114  
115 1 ▶sub charset { return( shift->_set_get_scalar_as_object( 'charset', @_ ) ); }
Subroutine charset: called CC=1 SCAR=0.0
Pod documented
116  
117 # Array of CSS::Object::Element objects or their sub classes
118 35 ▶sub elements { return( shift->_set_get_object_array_object( 'elements', 'CSS::Object::Element', @_ ) ); }
Subroutine elements: called CC=1 SCAR=0.0
Pod documented
119  
120 sub format
121 {
122 132 ▶ my $self = shift( @_ );
Subroutine format: called CC=8 SCAR=24.7
Pod documented
123 132 ▶ if( @_ )
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 6 126 132
124 {
125 6 my $val = shift( @_ );
126 6 my $format;
127 6 ▶ if( ref( $val ) )
Branch: 2 branches
BranchTrueFalseTotal
if (ref $val) { } 3 3 6
elsif (not ref $val and index($val, '::') != -1) { } 3 0 3
128 {
129 3 ▶ $format = $self->_set_get_object( 'format', 'CSS::Object::Format', $val ) || return( $self->pass_error );
Condition50%1/2
$self->_set_get_object('format', 'CSS::Object::Format', $val) || (return $self->pass_error)
l!l
30
MC/DC0%0/1
$self->_set_get_object('format', 'CSS::Object::Format', $val) || (return $self->pass_error)
$self->_set_get_object('format', 'CSS::Object::Format', $val)
Truth table50%1/2
A
A= $self->_set_get_object('format', 'CSS::Object::Format', $val)
Aresult
11
00
130 }
131 # Formatter as a class name
132 ▶ elsif( !ref( $val ) && CORE::index( $val, '::' ) != -1 )
Condition33%1/3
not ref $val and index($val, "::") != -1
!ll&&!rl&&r
003
MC/DC0%0/2
not ref $val and index($val, "::") != -1
not ref $val index($val, "::") != -1
Truth table33%1/3
not(A) and B
A= not ref $valB= index($val, "::") != -1
ABresult
0X0
100
111
133 {
134 3 ▶ $self->_load_class( $val ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class($val) or return $self->pass_error 0 3 3
135 3 ▶ $format = $val->new( debug => $self->debug ) || return( $self->pass_error( $val->error ) );
Condition50%1/2
$val->new('debug', $self->debug) || (return $self->pass_error($val->error))
l!l
30
MC/DC0%0/1
$val->new('debug', $self->debug) || (return $self->pass_error($val->error))
$val->new('debug', $self->debug)
Truth table50%1/2
A
A= $val->new('debug', $self->debug)
Aresult
11
00
136 3 $self->_set_get_object( 'format', 'CSS::Object::Format', $format );
137 }
138 else
139 {
140 0 return( $self->error( "Unknown format \"$val\". I do not know what to do with it." ) );
141 }
142 6 ▶ $self->messagef( 3, "Setting new formatter '$format' for %d elements -> %s", $self->elements->length, sub{ $self->elements->join( "', '" )} );
Subroutine __ANON__: not called CC=1 SCAR=1.2
143 $self->elements->foreach(sub
144 {
145 0 ▶ return(1) if( !$self->_is_object( $_[0] ) );
Subroutine __ANON__: not called CC=3 SCAR=24.8
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_is_object($_[0]) 0 0 0
146 0 ▶ shift->format( $format ) || return;
Branch: 1 branch
BranchTrueFalseTotal
(shift())->format($format) or return 0 0 0
147 6 });
148 6 return( $format );
149 }
150 126 return( $self->_set_get_object( 'format', 'CSS::Object::Format' ) );
151 }
152  
153 sub get_rule_by_selector
154 {
155 1 ▶ my( $self, $name ) = @_;
Subroutine get_rule_by_selector: called CC=9 SCAR=24.3
Pod documented
156 1 ▶ return( $self->error( "No selector was provided to find its equivalent rule object." ) ) if( !$name );
Branch: 1 branch
BranchTrueFalseTotal
unless $name 0 1 1
157 # $self->messagef( 3, "%d elements found.", $self->elements->length );
158 1 my $found = Module::Generic::Array->new;
159 1 foreach my $rule ( @{$self->elements} )
160 {
161 3 ▶ next if( !$rule->isa( 'CSS::Object::Rule' ) );
Branch: 1 branch
BranchTrueFalseTotal
unless $rule->isa("CSS::Object::Rule") 0 3 3
162 # $self->messagef( 3, "This rule has %d selectors", $rule->selectors->length );
163 3 foreach my $sel ( @{$rule->selectors} )
164 {
165 # $self->message( 3, "Does '", $sel->name, "' match our target selector '$name' ?" );
166 5 ▶ if( $sel->name eq $name )
Branch: 1 branch
BranchTrueFalseTotal
if ($sel->name eq $name) 1 4 5
167 {
168 # return( $rule );
169 1 $found->push( $rule );
170 }
171 }
172 }
173 ## The user is calling this in a chain context, we make sure this is possible using the Module::Generic::Null class if needed
174 1 ▶ if( Want::want( 'OBJECT' ) )
Branch: 2 branches
BranchTrueFalseTotal
if (Want::want('OBJECT')) { } 0 1 1
elsif (Want::want('LIST')) { } 0 1 1
175 {
176 0 ▶ rreturn( $found->length > 0 ? $found->first : Module::Generic::Null->new );
Branch: 1 branch
BranchTrueFalseTotal
$found->length > 0 ? : 0 0 0
177 }
178 elsif( Want::want( 'LIST' ) )
179 {
180 0 rreturn( @$found );
181 }
182 else
183 {
184 1 return( $found->first );
185 }
186 }
187  
188 sub load_parser
189 {
190 5 ▶ my $self = shift( @_ );
Subroutine load_parser: called CC=3 SCAR=11.2
Pod documented
191 5 my $parser_class = $self->parser;
192 5 ▶ $self->_load_class( "$parser_class" ) || return( $self->error( "Unable to load parser class \"$parser_class\": ", $self->error ) );
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class("$parser_class") or return $self->error(qq[Unable to load parser class "$parser_class": ], $self->error) 0 5 5
193 5 ▶ my $parser = $parser_class->scalar->new( $self ) || return( $self->error( "Unable to instantiate parser \"$parser_class\" object: ", $parser_class->scalar->error ) );
Condition50%1/2
$parser_class->scalar->new($self) || (return $self->error(qq[Unable to instantiate parser "$parser_class" object: ], $parser_class->scalar->error))
l!l
50
MC/DC0%0/1
$parser_class->scalar->new($self) || (return $self->error(qq[Unable to instantiate parser "$parser_class" object: ], $parser_class->scalar->error))
$parser_class->scalar->new($self)
Truth table50%1/2
A
A= $parser_class->scalar->new($self)
Aresult
11
00
194 5 $parser->debug( $self->debug );
195 # $self->message( 3, "Parser \"$parser_class\" initiated with object '$parser'." );
196 5 return( $parser );
197 }
198  
199 sub new_at_rule
200 {
201 0 ▶ my $self = shift( @_ );
Subroutine new_at_rule: not called CC=2 SCAR=17.9
Pod undocumented
202 0 my $o = CSS::Object::Rule::At->new( @_,
203 format => $self->format,
204 debug => $self->debug,
205 css => $self,
206 );
207 0 ▶ return( $self->error( "Cannot create a new at rule object: ", CSS::Object::Rule::At->error ) ) if( !defined( $o ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $o 0 0 0
208 0 return( $o );
209 }
210  
211 sub new_keyframes_rule
212 {
213 1 ▶ my $self = shift( @_ );
Subroutine new_keyframes_rule: called CC=2 SCAR=7.0
Pod undocumented
214 1 my $o = CSS::Object::Rule::Keyframes->new( @_,
215 format => $self->format,
216 debug => $self->debug,
217 css => $self,
218 );
219 1 ▶ return( $self->error( "Cannot create a new keyframes rule object: ", CSS::Object::Rule::Keyframes->error ) ) if( !defined( $o ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $o 0 1 1
220 1 return( $o );
221 }
222  
223 sub new_comment
224 {
225 5 ▶ my $self = shift( @_ );
Subroutine new_comment: called CC=2 SCAR=7.0
Pod documented
226 5 my $o = CSS::Object::Comment->new( @_, format => $self->format, debug => $self->debug );
227 5 ▶ return( $self->error( "Cannot create a new comment object: ", CSS::Object::Comment->error ) ) if( !defined( $o ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $o 0 5 5
228 5 return( $o );
229 }
230  
231 sub new_property
232 {
233 15 ▶ my $self = shift( @_ );
Subroutine new_property: called CC=2 SCAR=7.0
Pod documented
234 15 my $o = CSS::Object::Property->new( @_, format => $self->format, debug => $self->debug );
235 15 ▶ return( $self->error( "Cannot create a new property object: ", CSS::Object::Property->error ) ) if( !defined( $o ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $o 0 15 15
236 15 return( $o );
237 }
238  
239 sub new_rule
240 {
241 26 ▶ my $self = shift( @_ );
Subroutine new_rule: called CC=2 SCAR=7.0
Pod documented
242 26 $self->message( 3, "Creating new rule with formatter '", $self->format->class, "'." );
243 26 my $o = CSS::Object::Rule->new( @_, format => $self->format, debug => $self->debug );
244 26 ▶ return( $self->error( "Cannot create a new rule object: ", CSS::Object::Rule->error ) ) if( !defined( $o ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $o 0 26 26
245 # $self->message( 3, "Returning \"", overload::StrVal( $o ), "\"." );
246 26 return( $o );
247 }
248  
249 sub new_selector
250 {
251 47 ▶ my $self = shift( @_ );
Subroutine new_selector: called CC=2 SCAR=7.0
Pod documented
252 47 my $o = CSS::Object::Selector->new( @_, format => $self->format, debug => $self->debug );
253 47 ▶ return( $self->error( "Cannot create a new selector object: ", CSS::Object::Selector->error ) ) if( !defined( $o ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $o 0 47 47
254 47 return( $o );
255 }
256  
257 sub new_value
258 {
259 0 ▶ my $self = shift( @_ );
Subroutine new_value: not called CC=2 SCAR=17.9
Pod documented
260 0 my $o = CSS::Object::Value->new( @_, format => $self->format, debug => $self->debug );
261 0 ▶ return( $self->error( "Cannot create a new value object: ", CSS::Object::Value->error ) ) if( !defined( $o ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $o 0 0 0
262 0 return( $o );
263 }
264  
265 sub parse_string
266 {
267 5 ▶ my $self = shift( @_ );
Subroutine parse_string: called CC=3 SCAR=11.1
Pod documented
268 5 my $string = shift( @_ );
269 5 $self->message( 3, "Parsing string '$string'" );
270  
271 # remove comments
272 # $string =~ s!/\*.*?\*\/!!g;
273 5 $string =~ s|<!--||g;
274 5 $string =~ s|-->||g;
275
276 5 ▶ my $parser = $self->load_parser || return( $self->pass_error );
Condition50%1/2
$self->load_parser || (return $self->pass_error)
l!l
50
MC/DC0%0/1
$self->load_parser || (return $self->pass_error)
$self->load_parser
Truth table50%1/2
A
A= $self->load_parser
Aresult
11
00
277 5 ▶ my $elems = $parser->parse_string( $string ) || return( $self->pass_error( $parser->error ) );
Condition50%1/2
$parser->parse_string($string) || (return $self->pass_error($parser->error))
l!l
50
MC/DC0%0/1
$parser->parse_string($string) || (return $self->pass_error($parser->error))
$parser->parse_string($string)
Truth table50%1/2
A
A= $parser->parse_string($string)
Aresult
11
00
278 5 $self->messagef( 3, "Parser returned %d elements.", $elems->length );
279 5 $self->messagef( 3, "First element is of class \"", ref( $elems->first ), "\"." );
280 # $self->messagef( 3, "First rule has %d properties.", $rules->first->properties->length );
281 5 return( $elems );
282 }
283  
284 6 ▶sub parser { return( shift->_set_get_scalar_as_object( 'parser', @_ ) ); }
Subroutine parser: called CC=1 SCAR=0.0
Pod documented
285  
286 2 ▶sub purge { return( shift->elements->reset ); }
Subroutine purge: called CC=1 SCAR=0.0
Pod documented
287  
288 sub read_file
289 {
290 5 ▶ my $self = shift( @_ );
Subroutine read_file: called CC=8 SCAR=24.1
Pod documented
291 5 my $path = shift( @_ );
292  
293 5 ▶ if( ref( $path ) )
Branch: 2 branches
BranchTrueFalseTotal
if (ref $path) { } 0 5 5
elsif ($path) { } 5 0 5
294 {
295 0 ▶ if( ref( $path ) eq 'ARRAY' )
Branch: 1 branch
BranchTrueFalseTotal
if (ref $path eq "ARRAY") 0 0 0
296 {
297 0 $self->read_file( $_ ) for( @$path );
298 0 return( $self );
299 }
300 }
301 elsif( $path )
302 {
303 5 $self->message( 3, "Reading file \"$path\"." );
304 5 ▶ my $io = IO::File->new( "<$path" ) || return( $self->error( "Could not open file \"$path\": $!" ) );
Condition50%1/2
'IO::File'->new("<$path") || (return $self->error(qq[Could not open file "$path": $!]))
l!l
50
MC/DC0%0/1
'IO::File'->new("<$path") || (return $self->error(qq[Could not open file "$path": $!]))
'IO::File'->new("<$path")
Truth table50%1/2
A
A= 'IO::File'->new("<$path")
Aresult
11
00
305 5 $io->binmode( ':utf8' );
306 5 my $source = join( '', $io->getlines );
307 5 $io->close;
308 5 $self->messagef( 3, "%d bytes of data read.", CORE::length( $source ) );
309 5 ▶ if( $source )
Branch: 1 branch
BranchTrueFalseTotal
if ($source) 5 0 5
310 {
311 5 ▶ my $elems = $self->parse_string( $source ) || return( $self->pass_error );
Condition50%1/2
$self->parse_string($source) || (return $self->pass_error)
l!l
50
MC/DC0%0/1
$self->parse_string($source) || (return $self->pass_error)
$self->parse_string($source)
Truth table50%1/2
A
A= $self->parse_string($source)
Aresult
11
00
312 5 $self->messagef( 3, "%d elements found from parsing.", $elems->length );
313 # $self->rules->push( @$rules );
314 5 $self->elements->push( @$elems );
315 }
316 5 return( $self );
317 }
318 0 return( $self->error( "Only scalars and arrays accepted: $!" ) );
319 }
320  
321 sub read_string
322 {
323 0 ▶ my $self = shift( @_ );
Subroutine read_string: not called CC=7 SCAR=40.3
Pod documented
324 0 my $data = shift( @_ );
325  
326 0 ▶ if( ref( $data ) )
Branch: 2 branches
BranchTrueFalseTotal
if (ref $data) { } 0 0 0
elsif (length $data) { } 0 0 0
327 {
328 0 ▶ if( ref( $data ) eq 'ARRAY' )
Branch: 1 branch
BranchTrueFalseTotal
if (ref $data eq "ARRAY") 0 0 0
329 {
330 0 for( @$data )
331 {
332 0 ▶ $self->read_string( $_ ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->read_string($_) or return $self->pass_error 0 0 0
333 }
334 0 return( $self );
335 }
336 }
337 elsif( length( $data ) )
338 {
339 0 ▶ my $elems = $self->parse_string( $data ) || return( $self->pass_error );
Condition0%0/2
$self->parse_string($data) || (return $self->pass_error)
l!l
00
MC/DC0%0/1
$self->parse_string($data) || (return $self->pass_error)
$self->parse_string($data)
Truth table0%0/2
A
A= $self->parse_string($data)
Aresult
11
00
340 ## $self->rules->push( @$rules );
341 0 $self->elements->push( @$elems );
342 }
343 0 return( $self );
344 }
345  
346 sub remove_rule
347 {
348 0 ▶ my $self = shift( @_ );
Subroutine remove_rule: not called CC=3 SCAR=24.8
Pod undocumented
349 0 my $rule = shift( @_ );
350 # $self->message( 3, "CSS rule provided to add to our stack of elements: '", overload::StrVal( $rule ), "'." );
351 0 ▶ return( $self->error( "No rule object was provided to remove." ) ) if( !defined( $rule ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $rule 0 0 0
352 0 ▶ return( $self->error( "Object provided is not a CSS::Object::Rule object." ) ) if( !$self->_is_a( $rule, 'CSS::Object::Rule' ) );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_is_a($rule, "CSS::Object::Rule") 0 0 0
353 0 $self->elements->remove( $rule );
354 0 return( $self );
355 }
356  
357 # sub rules { return( shift->_set_get_array_as_object( 'rules', @_ ) ); }
358 27 ▶sub rules { return( $_[0]->elements->map(sub{ $_[0]->_is_a( $_, 'CSS::Object::Rule' ) ? $_ : () }) ); }
Subroutine __ANON__: called CC=2 SCAR=7.2
Subroutine rules: called CC=1 SCAR=0.2
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
$_[0]->_is_a($_, 'CSS::Object::Rule') ? : 27 0 27
359  
360 6 1;
361  
362 # XXX POD
363 __END__
« Object/Parser/Default.pm ↑ Summary Object/Element.pm »