Object/Property.pm

filter: Statementstmt 76.1% 51 / 67 Branchbran 45.0% 9 / 20 Conditioncond 22.2% 2 / 9 MC/DCmcdc 0.0% 0 / 5 Subroutinesub 82.3% 14 / 17 Podpod 100% 9 / 9 totaltotal 66.9% 85 / 127 CC 15 SCAR 18.6
CC
15
Cov
65%
__ANON__
20.0
remove_from
12.0
value
9.7
CRAP 6.4
« Object/Parser/Default.pm ↑ Summary Object/Builder.pm »
1 ##----------------------------------------------------------------------------
2 ## CSS Object Oriented - ~/lib/CSS/Object/Property.pm
3 ## Version v0.2.0
4 ## Copyright(c) 2021 DEGUEST Pte. Ltd.
5 ## Author: Jacques Deguest <jack@deguest.jp>
6 ## Created 2020/06/21
7 ## Modified 2024/09/05
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 6 ▶{
Subroutine BEGIN: called CC=1 SCAR=0.0
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 our $VERSION = 'v0.2.0';
22 };
23  
24 sub init
25 45 ▶{
Subroutine init: called CC=1 SCAR=0.0
Pod documented
26 45 my $self = shift( @_ );
27 ## print( STDERR ref( $self ), "::init() Args received are: ", $self->dump( @_ ), "\n" );
28 ## $self->{format} = '';
29 45 $self->{name} = '';
30 45 $self->{value} = '';
31 45 $self->{values} = [];
32 ## $self->{_init_strict_use_sub} = 1;
33 45 $self->SUPER::init( @_ );
34 45 $self->format->indent( ' ' );
35 45 return( $self );
36 }
37  
38 sub add_to
39 7 ▶{
Subroutine add_to: called CC=3 SCAR=11.2
Pod documented
40 7 my $self = shift( @_ );
41 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
42 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
43 7 $self->format->indent( $rule->format->indent );
44 7 $rule->add_property( $self );
45 7 return( $self );
46 }
47  
48 137 ▶sub as_string { return( $_[0]->format->property_as_string( $_[0] ) ); }
Subroutine as_string: called CC=1 SCAR=0.0
Pod documented
49  
50 sub format
51 603 ▶{
Subroutine format: called CC=3 SCAR=11.1
Pod documented
52 603 my $self = shift( @_ );
53 603 ▶ if( @_ )
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 16 587 603
54 {
55 # my( $p, $f, $l ) = caller;
56 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
57 $self->values->foreach(sub
58 15 ▶ {
Subroutine __ANON__: called CC=2 SCAR=7.6
59 15 ▶ shift->format( $format ) || return;
Branch: 1 branch
BranchTrueFalseTotal
(shift())->format($format) or return 15 0 15
60 16 });
61 16 $format->indent( ' ' );
62 16 return( $format );
63 }
64 587 return( $self->_set_get_object( 'format', 'CSS::Object::Format' ) );
65 }
66  
67 185 ▶sub name { return( shift->_set_get_scalar_as_object( 'name', @_ ) ); }
Subroutine name: called CC=1 SCAR=0.0
Pod documented
68  
69 sub remove_from
70 0 ▶{
Subroutine remove_from: not called CC=3 SCAR=24.8
Pod documented
71 0 my $self = shift( @_ );
72 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
73 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
74 0 $rule->elements->remove( $self );
75 0 return( $self );
76 }
77  
78 sub value
79 48 ▶{
Subroutine value: called CC=5 SCAR=22.7
Pod documented
80 48 my $self = shift( @_ );
81 48 ▶ if( @_ )
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 44 4 48
82 {
83 44 my $val = shift( @_ );
84 44 my $valObj;
85 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
86 {
87 0 $valObj = $val;
88 0 $valObj->format( $self->format );
89 0 $valObj->debug( $self->debug );
90 }
91 ## Array of values, which could be
92 elsif( $self->_is_array( $val ) )
93 {
94 ## Make sure this is a Module::Generic::Array
95 0 $val = $self->new_array( $val );
96 $val->foreach(sub
97 0 ▶ {
Subroutine __ANON__: not called CC=4 SCAR=30.0
98 0 ▶ if( $self->_is_a( $_, 'CSS::Object::Value' ) )
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
99 {
100 0 $self->values->push( $_ );
101 }
102 ▶ 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
103 {
104 0 $valObj = CSS::Object::Value->new( "$_",
105 debug => $self->debug,
106 format => $self->format,
107 );
108 0 $self->values->push( $_ );
109 }
110 else
111 {
112 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" );
113 }
114 0 });
115 }
116 else
117 {
118 44 $valObj = CSS::Object::Value->new( $val,
119 debug => $self->debug,
120 format => $self->format,
121 );
122 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".]) 44 0 44
123 }
124 44 $self->values->set( $valObj );
125 44 return( $valObj );
126 }
127 # my $last = $self->values->last;
128 4 return( $self->values->last );
129 }
130  
131 # Array of CSS::Object::Value objects
132 201 ▶sub values { return( shift->_set_get_object_array_object( 'values', 'CSS::Object::Value', @_ ) ); }
Subroutine values: called CC=1 SCAR=0.0
Pod documented
133  
134 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
135  
136 6 1;
137 # NOTE: POD
138 __END__
« Object/Parser/Default.pm ↑ Summary Object/Builder.pm »