Object/Property.pm

filter: Statementstmt 77.1% 54 / 70 Branchbran 45.0% 9 / 20 Conditioncond 22.2% 2 / 9 MC/DCmcdc 0.0% 0 / 5 Subroutinesub 83.3% 15 / 18 Podpod 100% 9 / 9 totaltotal 67.9% 89 / 131 CC 15 SCAR 18.3
CC
15
Cov
66%
__ANON__
20.0
remove_from
12.0
value
9.7
CRAP 6.2
« Object/Parser/Default.pm ↑ Summary Object/Builder.pm »
1 ##----------------------------------------------------------------------------
2 ## CSS Object Oriented - ~/lib/CSS/Object/Property.pm
3 ## Version v0.1.1
4 ## Copyright(c) 2020 DEGUEST Pte. Ltd.
5 ## Author: Jacques Deguest <jack@deguest.jp>
6 ## Created 2020/06/21
7 ## Modified 2021/04/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::Property;
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 parent qw( CSS::Object::Element );
Subroutine BEGIN: called CC=1 SCAR=0.0
19 6 ▶ use CSS::Object::Format;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 6 ▶ use CSS::Object::Value;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 6 ▶ use Devel::Confess;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 6 ▶ our $VERSION = 'v0.1.1';
Subroutine BEGIN: called CC=1 SCAR=0.0
23 };
24  
25 sub init
26 {
27 45 ▶ my $self = shift( @_ );
Subroutine init: called CC=1 SCAR=0.0
Pod documented
28 ## print( STDERR ref( $self ), "::init() Args received are: ", $self->dump( @_ ), "\n" );
29 ## $self->{format} = '';
30 45 $self->{name} = '';
31 45 $self->{value} = '';
32 45 $self->{values} = [];
33 ## $self->{_init_strict_use_sub} = 1;
34 45 $self->SUPER::init( @_ );
35 45 $self->format->indent( ' ' );
36 45 return( $self );
37 }
38  
39 sub add_to
40 {
41 7 ▶ my $self = shift( @_ );
Subroutine add_to: called CC=3 SCAR=11.2
Pod documented
42 7 ▶ my $rule = shift( @_ ) || return( $self->error( "No rule object was provided to add our property to it." ) );
Condition50%1/2
shift @_ || (return $self->error('No rule object was provided to add our property to it.'))
l!l
70
MC/DC0%0/1
shift @_ || (return $self->error('No rule object was provided to add our property to it.'))
shift @_
Truth table50%1/2
A
A= shift @_
Aresult
11
00
43 7 ▶ return( $self->error( "Rule object provided (", overload::StrVal( $rule ), ") is not actually 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 7 7
44 7 $self->format->indent( $rule->format->indent );
45 7 $rule->add_property( $self );
46 7 return( $self );
47 }
48  
49 250 ▶sub as_string { return( $_[0]->format->property_as_string( $_[0] ) ); }
Subroutine as_string: called CC=1 SCAR=0.0
Pod documented
50  
51 sub format
52 {
53 958 ▶ my $self = shift( @_ );
Subroutine format: called CC=3 SCAR=11.1
Pod documented
54 958 ▶ if( @_ )
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 16 942 958
55 {
56 # my( $p, $f, $l ) = caller;
57 16 ▶ my $format = $self->SUPER::format( @_ ) || return( $self->pass_error );
Condition50%1/2
$self->SUPER::format(@_) || (return $self->pass_error)
l!l
160
MC/DC0%0/1
$self->SUPER::format(@_) || (return $self->pass_error)
$self->SUPER::format(@_)
Truth table50%1/2
A
A= $self->SUPER::format(@_)
Aresult
11
00
58 $self->values->foreach(sub
59 {
60 15 ▶ shift->format( $format ) || return;
Subroutine __ANON__: called CC=2 SCAR=7.6
Branch: 1 branch
BranchTrueFalseTotal
(shift())->format($format) or return 0 15 15
61 16 });
62 16 $format->indent( ' ' );
63 16 return( $format );
64 }
65 942 return( $self->_set_get_object( 'format', 'CSS::Object::Format' ) );
66 }
67  
68 298 ▶sub name { return( shift->_set_get_scalar_as_object( 'name', @_ ) ); }
Subroutine name: called CC=1 SCAR=0.0
Pod documented
69  
70 sub remove_from
71 {
72 0 ▶ my $self = shift( @_ );
Subroutine remove_from: not called CC=3 SCAR=24.8
Pod documented
73 0 ▶ my $rule = shift( @_ ) || return( $self->error( "No rule object was provided to remove our property from it." ) );
Condition0%0/2
shift @_ || (return $self->error('No rule object was provided to remove our property from it.'))
l!l
00
MC/DC0%0/1
shift @_ || (return $self->error('No rule object was provided to remove our property from it.'))
shift @_
Truth table0%0/2
A
A= shift @_
Aresult
11
00
74 0 ▶ return( $self->error( "Rule object provided (", overload::StrVal( $rule ), ") is not actually 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
75 0 $rule->elements->remove( $self );
76 0 return( $self );
77 }
78  
79 sub value
80 {
81 48 ▶ my $self = shift( @_ );
Subroutine value: called CC=5 SCAR=22.7
Pod documented
82 48 ▶ if( @_ )
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 44 4 48
83 {
84 44 my $val = shift( @_ );
85 44 my $valObj;
86 44 ▶ if( $self->_is_a( $val, 'CSS::Object::Value' ) )
Branch: 2 branches
BranchTrueFalseTotal
if ($self->_is_a($val, 'CSS::Object::Value')) { } 0 44 44
elsif ($self->_is_array($val)) { } 0 44 44
87 {
88 0 $valObj = $val;
89 0 $valObj->format( $self->format );
90 0 $valObj->debug( $self->debug );
91 }
92 ## Array of values, which could be
93 elsif( $self->_is_array( $val ) )
94 {
95 ## Make sure this is a Module::Generic::Array
96 0 $val = $self->new_array( $val );
97 $val->foreach(sub
98 {
99 0 ▶ if( $self->_is_a( $_, 'CSS::Object::Value' ) )
Subroutine __ANON__: not called CC=4 SCAR=30.0
Branch: 2 branches
BranchTrueFalseTotal
if ($self->_is_a($_, 'CSS::Object::Value')) { } 0 0 0
elsif (not ref $_ or $self->_is_a($_, 'Module::Generic::Scalar')) { } 0 0 0
100 {
101 0 $self->values->push( $_ );
102 }
103 ▶ elsif( !ref( $_ ) || $self->_is_a( $_, 'Module::Generic::Scalar' ) )
Condition0%0/3
not ref $_ or $self->_is_a($_, "Module::Generic::Scalar")
l!l&&r!l&&!r
000
MC/DC0%0/2
not ref $_ or $self->_is_a($_, "Module::Generic::Scalar")
not ref $_ $self->_is_a($_, "Module::Generic::Scalar")
Truth table0%0/3
not(A) or B
A= not ref $_B= $self->_is_a($_, "Module::Generic::Scalar")
ABresult
1X1
011
000
104 {
105 0 $valObj = CSS::Object::Value->new( "$_",
106 debug => $self->debug,
107 format => $self->format,
108 );
109 0 $self->values->push( $_ );
110 }
111 else
112 {
113 0 CORE::warn( "Got value \"$_\" in an array of values provided for this property, but I just do not know what to do with it.\n" );
114 }
115 0 });
116 }
117 else
118 {
119 44 $valObj = CSS::Object::Value->new( $val,
120 debug => $self->debug,
121 format => $self->format,
122 );
123 44 ▶ defined( $valObj ) || return( $self->error( "Unable to initialise CSS::Object::Value object for value \"$val\"." ) );
Branch: 1 branch
BranchTrueFalseTotal
defined $valObj or return $self->error(qq[Unable to initialise CSS::Object::Value object for value "$val".]) 0 44 44
124 }
125 44 $self->values->set( $valObj );
126 44 return( $valObj );
127 }
128 # my $last = $self->values->last;
129 4 return( $self->values->last );
130 }
131  
132 # Array of CSS::Object::Value objects
133 314 ▶sub values { return( shift->_set_get_object_array_object( 'values', 'CSS::Object::Value', @_ ) ); }
Subroutine values: called CC=1 SCAR=0.0
Pod documented
134  
135 0 ▶sub values_as_string { return( $_[0]->format->values_as_string( $_[0]->values ) ); }
Subroutine values_as_string: not called CC=1 SCAR=6.9
Pod documented
136  
137 6 1;
138  
139 __END__
« Object/Parser/Default.pm ↑ Summary Object/Builder.pm »