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/Element.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 260 ▶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 988 ▶ my $self = shift( @_ );
Subroutine format: called CC=3 SCAR=11.1
Pod documented
54 988 ▶ if( @_ )
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 16 972 988
55 {
56 # my( $p, $f, $l ) = caller;
57 # $self->message( 3, "Property format called in package $p at line $l in file $f" );
58 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
59 $self->values->foreach(sub
60 {
61 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
62 16 });
63 16 $format->indent( ' ' );
64 16 return( $format );
65 }
66 972 return( $self->_set_get_object( 'format', 'CSS::Object::Format' ) );
67 }
68  
69 308 ▶sub name { return( shift->_set_get_scalar_as_object( 'name', @_ ) ); }
Subroutine name: called CC=1 SCAR=0.0
Pod documented
70  
71 sub remove_from
72 {
73 0 ▶ my $self = shift( @_ );
Subroutine remove_from: not called CC=3 SCAR=24.8
Pod documented
74 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
75 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
76 0 $rule->elements->remove( $self );
77 0 return( $self );
78 }
79  
80 sub value
81 {
82 48 ▶ my $self = shift( @_ );
Subroutine value: called CC=5 SCAR=22.7
Pod documented
83 48 ▶ if( @_ )
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 44 4 48
84 {
85 44 my $val = shift( @_ );
86 44 my $valObj;
87 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
88 {
89 0 $valObj = $val;
90 0 $valObj->format( $self->format );
91 0 $valObj->debug( $self->debug );
92 }
93 ## Array of values, which could be
94 elsif( $self->_is_array( $val ) )
95 {
96 ## Make sure this is a Module::Generic::Array
97 0 $val = $self->new_array( $val );
98 $val->foreach(sub
99 {
100 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
101 {
102 0 $self->values->push( $_ );
103 }
104 ▶ 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
105 {
106 0 $valObj = CSS::Object::Value->new( "$_",
107 debug => $self->debug,
108 format => $self->format,
109 );
110 0 $self->values->push( $_ );
111 }
112 else
113 {
114 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" );
115 }
116 0 });
117 }
118 else
119 {
120 # $self->message( 3, "Creating a value object for value '$val'." );
121 44 $valObj = CSS::Object::Value->new( $val,
122 debug => $self->debug,
123 format => $self->format,
124 );
125 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
126 }
127 # $self->message( 3, "Adding new value object '", overload::StrVal( $valObj ), " ($val) to our stack." );
128 44 $self->values->set( $valObj );
129 # $self->message( 3, "Stack of values contains ", $self->values->length, " elements. Returning the CSS::Object::Value object (", $valObj->as_string, ")." );
130 44 return( $valObj );
131 }
132 # my $last = $self->values->last;
133 # $self->message( 3, "Returning value object '", $last, "'." );
134 4 return( $self->values->last );
135 }
136  
137 # Array of CSS::Object::Value objects
138 324 ▶sub values { return( shift->_set_get_object_array_object( 'values', 'CSS::Object::Value', @_ ) ); }
Subroutine values: called CC=1 SCAR=0.0
Pod documented
139  
140 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
141  
142 6 1;
143  
144 __END__
« Object/Element.pm ↑ Summary Object/Builder.pm »