Object/Value.pm

filter: Statementstmt 59.2% 45 / 76 Branchbran 27.5% 11 / 40 Conditioncond 5.8% 1 / 17 MC/DCmcdc 0.0% 0 / 10 Subroutinesub 70.5% 12 / 17 Podpod 57.1% 4 / 7 totaltotal 43.7% 73 / 167 CC 28 SCAR 36.0
CC
28
Cov
43%
with_comment
110.0
_comment_data_to_object
42.0
value
24.1
CRAP 36.8
« Object/Parser/Enhanced.pm ↑ Summary Object.pm »
1 ##----------------------------------------------------------------------------
2 ## CSS Object Oriented - ~/lib/CSS/Object/Value.pm
3 ## Version v0.2.0
4 ## Copyright(c) 2020 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::Value;
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::Comment;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 6 ▶ use CSS::Object::Format;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 6 ▶ use overload (
Subroutine BEGIN: called CC=1 SCAR=0.0
22 6 '""' => 'as_string',
23 fallback => 1,
24 6 );
25 6 our $VERSION = 'v0.2.0';
26 };
27  
28 sub init
29 45 ▶{
Subroutine init: called CC=3 SCAR=11.0
Pod documented
30 45 my $self = shift( @_ );
31 45 my $val;
32 45 ▶ $val = shift( @_ ) if( ( scalar( @_ ) % 2 ) );
Branch: 1 branch
BranchTrueFalseTotal
if scalar(@_) % 2 44 1 45
33 45 $self->{format} = '';
34 45 $self->{value} = '';
35 45 $self->{_init_strict_use_sub} = 1;
36 45 $self->SUPER::init( @_ );
37 45 ▶ $self->value( $val ) if( defined( $val ) );
Branch: 1 branch
BranchTrueFalseTotal
if defined $val 44 1 45
38 45 return( $self );
39 }
40  
41 # Inherited
42 # sub format
43  
44 sub as_string
45 145 ▶{
Subroutine as_string: called CC=2 SCAR=7.1
Pod documented
46 145 my $self = shift( @_ );
47 145 ▶ return( '' ) if( !$self->format );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->format 0 145 145
48 145 return( $self->format->value_as_string( $self ) );
49 # return(
50 # $self->comment_before->map(sub{ $_->as_string })->scalar . ( $self->comment_before->length ? ' ' : '' ) .
51 # $self->format->value_as_string( $self ) .
52 # ( $self->comment_after->length ? ' ' : '' ) . $self->comment_after->map(sub{ $_->as_string })->scalar
53 # );
54 }
55  
56 0 ▶sub comment { return( shift->_set_get_object_array_object( 'comment_after', 'CSS::Object::Comment', @_ ) ); }
Subroutine comment: not called CC=1 SCAR=6.9
Pod undocumented
57  
58 290 ▶sub comment_after { return( shift->_set_get_object_array_object( 'comment_after', 'CSS::Object::Comment', @_ ) ); }
Subroutine comment_after: called CC=1 SCAR=0.0
Pod undocumented
59  
60 292 ▶sub comment_before { return( shift->_set_get_object_array_object( 'comment_before', 'CSS::Object::Comment', @_ ) ); }
Subroutine comment_before: called CC=1 SCAR=0.0
Pod undocumented
61  
62 sub value
63 189 ▶{
Subroutine value: called CC=9 SCAR=31.8
Pod documented
64 189 my $self = shift( @_ );
65 189 ▶ if( @_ )
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 44 145 189
66 {
67 44 my $val = shift( @_ );
68 44 ▶ if( $self->_is_a( $val, 'CSS::Object::Value' ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_is_a($val, 'CSS::Object::Value')) { } 0 44 44
69 {
70 ## If the value object provided has some comments attached to it
71 ## Make sure each data stored is an object, or else we create an object before adding it
72 0 ▶ if( $val->comment_after->length )
Branch: 1 branch
BranchTrueFalseTotal
if ($val->comment_after->length) 0 0 0
73 {
74 $val->comment_after->foreach(sub
75 0 ▶ {
Subroutine __ANON__: not called CC=2 SCAR=17.9
76 0 my $cmt = $self->_comment_data_to_object( $_ );
77 0 ▶ $self->comment_after->push( $cmt ) if( defined( $cmt ) );
Branch: 1 branch
BranchTrueFalseTotal
if defined $cmt 0 0 0
78 0 });
79 }
80 0 ▶ if( $val->comment_before->length )
Branch: 1 branch
BranchTrueFalseTotal
if ($val->comment_before->length) 0 0 0
81 {
82 $val->comment_before->foreach(sub
83 0 ▶ {
Subroutine __ANON__: not called CC=2 SCAR=17.9
84 0 my $cmt = $self->_comment_data_to_object( $_ );
85 0 ▶ $self->comment_before->push( $cmt ) if( defined( $cmt ) );
Branch: 1 branch
BranchTrueFalseTotal
if defined $cmt 0 0 0
86 0 });
87 }
88 0 $val = $val->value->scalar;
89 }
90 else
91 {
92 44 ▶ while( $val =~ s/^[[:blank:]\h]*\/\*[[:blank:]\h]*(.*?)[[:blank:]\h]*\*\///s )
Branch: 1 branch
BranchTrueFalseTotal
if ($val =~ s[^[[:blank:]\h]*/\*[[:blank:]\h]*(.*?)[[:blank:]\h]*\*/][]s) 2 44 46
93 {
94 2 ▶ my $cmt = CSS::Object::Comment->new( [split( /\r\n/, $1 )] ) ||
Condition50%1/2
'CSS::Object::Comment'->new([split(/\r\n/, $1, 0)]) || (return $self->error('Cannot create comment object: ', 'CSS::Object::Comment'->error))
l!l
20
MC/DC0%0/1
'CSS::Object::Comment'->new([split(/\r\n/, $1, 0)]) || (return $self->error('Cannot create comment object: ', 'CSS::Object::Comment'->error))
'CSS::Object::Comment'->new([split(/\r\n/, $1, 0)])
Truth table50%1/2
A
A= 'CSS::Object::Comment'->new([split(/\r\n/, $1, 0)])
Aresult
11
00
95 return( $self->error( "Cannot create comment object: ", CSS::Object::Comment->error ) );
96 2 $self->comment_before->push( $cmt );
97 }
98 44 ▶ while( $val =~ s/[[:blank:]\h]*\/\*[[:blank:]\h]*(.*?)[[:blank:]\h]*\*\/$//s )
Branch: 1 branch
BranchTrueFalseTotal
if ($val =~ s[[[:blank:]\h]*/\*[[:blank:]\h]*(.*?)[[:blank:]\h]*\*/$][]s) 0 44 44
99 {
100 0 ▶ my $cmt = CSS::Object::Comment->new( [split( /\r\n/, $1 )] ) ||
Condition0%0/2
'CSS::Object::Comment'->new([split(/\r\n/, $1, 0)]) || (return $self->error('Cannot create comment object: ', 'CSS::Object::Comment'->error))
l!l
00
MC/DC0%0/1
'CSS::Object::Comment'->new([split(/\r\n/, $1, 0)]) || (return $self->error('Cannot create comment object: ', 'CSS::Object::Comment'->error))
'CSS::Object::Comment'->new([split(/\r\n/, $1, 0)])
Truth table0%0/2
A
A= 'CSS::Object::Comment'->new([split(/\r\n/, $1, 0)])
Aresult
11
00
101 return( $self->error( "Cannot create comment object: ", CSS::Object::Comment->error ) );
102 0 $self->comment_after->push( $cmt );
103 }
104 44 $val =~ s/^[[:blank:]\h]*|[[:blank:]\h]*$//gs;
105 }
106 44 return( $self->_set_get_scalar_as_object( 'value', $val ) );
107 }
108 145 return( $self->_set_get_scalar_as_object( 'value' ) );
109 }
110  
111 sub with_comment
112 0 ▶{
Subroutine with_comment: not called CC=10 SCAR=47.0
Pod documented
113 0 my $self = shift( @_ );
114 0 my $opts = {};
115 0 ▶ $opts = shift( @_ ) if( $self->_is_hash( $_[0] ) );
Branch: 1 branch
BranchTrueFalseTotal
if $self->_is_hash($_[0]) 0 0 0
116 0 ▶ if( $opts->{before} )
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->{"before"}) 0 0 0
117 {
118 0 my $cmt = $self->_comment_data_to_object( $opts->{before} );
119 0 ▶ defined( $cmt ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
defined $cmt or return $self->pass_error 0 0 0
120 0 ▶ $self->comment_before->push( $cmt ) if( defined( $cmt ) && CORE::length( $cmt ) );
Branch: 1 branch
BranchTrueFalseTotal
if defined $cmt and length $cmt 0 0 0
Condition0%0/3
defined $cmt and length $cmt
!ll&&!rl&&r
000
MC/DC0%0/2
defined $cmt and length $cmt
defined $cmt length $cmt
Truth table0%0/3
A and B
A= defined $cmtB= length $cmt
ABresult
0X0
100
111
121 }
122 0 ▶ if( $opts->{after} )
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->{"after"}) 0 0 0
123 {
124 0 my $cmt = $self->_comment_data_to_object( $opts->{after} );
125 0 ▶ defined( $cmt ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
defined $cmt or return $self->pass_error 0 0 0
126 0 ▶ $self->comment_after->push( $cmt ) if( defined( $cmt ) && CORE::length( $cmt ) );
Branch: 1 branch
BranchTrueFalseTotal
if defined $cmt and length $cmt 0 0 0
Condition0%0/3
defined $cmt and length $cmt
!ll&&!rl&&r
000
MC/DC0%0/2
defined $cmt and length $cmt
defined $cmt length $cmt
Truth table0%0/3
A and B
A= defined $cmtB= length $cmt
ABresult
0X0
100
111
127 }
128 0 return( $self );
129 }
130  
131 sub _comment_data_to_object
132 0 ▶{
Subroutine _comment_data_to_object: not called CC=6 SCAR=37.4
133 0 my $self = shift( @_ );
134 # No data received, we silently return false
135 0 ▶ my $this = shift( @_ ) || return( '' );
Condition0%0/2
shift @_ || (return '')
l!l
00
MC/DC0%0/1
shift @_ || (return '')
shift @_
Truth table0%0/2
A
A= shift @_
Aresult
11
00
136 0 ▶ if( $self->_is_a( $this, 'CSS::Objet::Comment' ) )
Branch: 2 branches
BranchTrueFalseTotal
if ($self->_is_a($this, 'CSS::Objet::Comment')) { } 0 0 0
elsif ($self->_is_array($this) or not ref $this) { } 0 0 0
137 {
138 0 return( $this );
139 }
140 ▶ elsif( $self->_is_array( $this ) || !ref( $this ) )
Condition0%0/3
$self->_is_array($this) or not ref $this
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->_is_array($this) or not ref $this
$self->_is_array($this) not ref $this
Truth table0%0/3
A or not(B)
A= $self->_is_array($this)B= not ref $this
ABresult
1X1
011
000
141 {
142 0 ▶ my $cmt = CSS::Object::Comment->new( $this, debug => $self->debug ) ||
Condition0%0/2
'CSS::Object::Comment'->new($this, 'debug', $self->debug) || (return $self->error('Cannot create a new comment from array provided in this property value: ', 'CSS::Object::Comment'->error))
l!l
00
MC/DC0%0/1
'CSS::Object::Comment'->new($this, 'debug', $self->debug) || (return $self->error('Cannot create a new comment from array provided in this property value: ', 'CSS::Object::Comment'->error))
'CSS::Object::Comment'->new($this, 'debug', $self->debug)
Truth table0%0/2
A
A= 'CSS::Object::Comment'->new($this, 'debug', $self->debug)
Aresult
11
00
143 return( $self->error( "Cannot create a new comment from array provided in this property value: ", CSS::Object::Comment->error ) );
144 0 return( $cmt );
145 }
146 else
147 {
148 0 return( $self->error( "I do not know what to do with comment data \"$this\"." ) );
149 }
150 }
151  
152 6 1;
153 # NOTE: POD
154 __END__
« Object/Parser/Enhanced.pm ↑ Summary Object.pm »