| 1 | ##---------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 2 | ## CSS Object Oriented - ~/lib/CSS/Object/Value.pm | ||||||||||||||||||||||||||||
| 3 | ## Version v0.1.0 | ||||||||||||||||||||||||||||
| 4 | ## Copyright(c) 2020 DEGUEST Pte. Ltd. | ||||||||||||||||||||||||||||
| 5 | ## Author: Jacques Deguest <@sitael.local> | ||||||||||||||||||||||||||||
| 6 | ## Created 2020/06/21 | ||||||||||||||||||||||||||||
| 7 | ## Modified 2020/06/21 | ||||||||||||||||||||||||||||
| 8 | ## | ||||||||||||||||||||||||||||
| 9 | ##---------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 10 | package CSS::Object::Value; | ||||||||||||||||||||||||||||
| 11 | BEGIN | ||||||||||||||||||||||||||||
| 12 | { | ||||||||||||||||||||||||||||
| 13 | 6 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | 6 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | 6 | ▶ | use parent qw( CSS::Object::Element ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 16 | 6 | ▶ | use CSS::Object::Comment; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 17 | 6 | ▶ | use CSS::Object::Format; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 18 | 6 | ▶ | use Devel::Confess; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 19 | use overload ( | ||||||||||||||||||||||||||||
| 20 | 6 | '""' => 'as_string', | |||||||||||||||||||||||||||
| 21 | fallback => 1, | ||||||||||||||||||||||||||||
| 22 | 6 | ▶ | ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 23 | 6 | ▶ | our $VERSION = 'v0.1.0'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 24 | }; | ||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | sub init | ||||||||||||||||||||||||||||
| 27 | { | ||||||||||||||||||||||||||||
| 28 | 45 | ▶ | my $self = shift( @_ ); | ||||||||||||||||||||||||||
|
Subroutine
init: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 29 | 45 | my $val; | |||||||||||||||||||||||||||
| 30 | 45 | ▶ | $val = shift( @_ ) if( ( scalar( @_ ) % 2 ) ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 31 | 45 | $self->{format} = ''; | |||||||||||||||||||||||||||
| 32 | 45 | $self->{value} = ''; | |||||||||||||||||||||||||||
| 33 | 45 | $self->{_init_strict_use_sub} = 1; | |||||||||||||||||||||||||||
| 34 | 45 | $self->SUPER::init( @_ ); | |||||||||||||||||||||||||||
| 35 | 45 | ▶ | $self->value( $val ) if( defined( $val ) ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 36 | # $self->message( 3, "Returning value object for value '", $self->value, "'." ); | ||||||||||||||||||||||||||||
| 37 | 45 | return( $self ); | |||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | ## Inherited | ||||||||||||||||||||||||||||
| 41 | ## sub format | ||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | sub as_string | ||||||||||||||||||||||||||||
| 44 | { | ||||||||||||||||||||||||||||
| 45 | 268 | ▶ | my $self = shift( @_ ); | ||||||||||||||||||||||||||
|
Subroutine
as_string: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||||||||||||||||||||
| 46 | 268 | ▶ | return( '' ) if( !$self->format ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 47 | 268 | return( $self->format->value_as_string( $self ) ); | |||||||||||||||||||||||||||
| 48 | # return( | ||||||||||||||||||||||||||||
| 49 | # $self->comment_before->map(sub{ $_->as_string })->scalar . ( $self->comment_before->length ? ' ' : '' ) . | ||||||||||||||||||||||||||||
| 50 | # $self->format->value_as_string( $self ) . | ||||||||||||||||||||||||||||
| 51 | # ( $self->comment_after->length ? ' ' : '' ) . $self->comment_after->map(sub{ $_->as_string })->scalar | ||||||||||||||||||||||||||||
| 52 | # ); | ||||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | 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
| |||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | 536 | ▶ | 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
| |||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | 538 | ▶ | 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
| |||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | sub value | ||||||||||||||||||||||||||||
| 62 | { | ||||||||||||||||||||||||||||
| 63 | 312 | ▶ | my $self = shift( @_ ); | ||||||||||||||||||||||||||
|
Subroutine
value: called CC=9 SCAR=31.7
Pod
documented
| |||||||||||||||||||||||||||||
| 64 | 312 | ▶ | if( @_ ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 65 | { | ||||||||||||||||||||||||||||
| 66 | 44 | my $val = shift( @_ ); | |||||||||||||||||||||||||||
| 67 | 44 | ▶ | if( $self->_is_a( $val, 'CSS::Object::Value' ) ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 68 | { | ||||||||||||||||||||||||||||
| 69 | ## If the value object provided has some comments attached to it | ||||||||||||||||||||||||||||
| 70 | ## Make sure each data stored is an object, or else we create an object before adding it | ||||||||||||||||||||||||||||
| 71 | 0 | ▶ | if( $val->comment_after->length ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 72 | { | ||||||||||||||||||||||||||||
| 73 | $val->comment_after->foreach(sub | ||||||||||||||||||||||||||||
| 74 | { | ||||||||||||||||||||||||||||
| 75 | 0 | ▶ | my $cmt = $self->_comment_data_to_object( $_ ); | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 76 | 0 | ▶ | $self->comment_after->push( $cmt ) if( defined( $cmt ) ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 77 | 0 | }); | |||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||
| 79 | 0 | ▶ | if( $val->comment_before->length ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 80 | { | ||||||||||||||||||||||||||||
| 81 | $val->comment_before->foreach(sub | ||||||||||||||||||||||||||||
| 82 | { | ||||||||||||||||||||||||||||
| 83 | 0 | ▶ | my $cmt = $self->_comment_data_to_object( $_ ); | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 84 | 0 | ▶ | $self->comment_before->push( $cmt ) if( defined( $cmt ) ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 85 | 0 | }); | |||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||
| 87 | 0 | $val = $val->value->scalar; | |||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||
| 89 | else | ||||||||||||||||||||||||||||
| 90 | { | ||||||||||||||||||||||||||||
| 91 | 44 | ▶ | while( $val =~ s/^[[:blank:]\h]*\/\*[[:blank:]\h]*(.*?)[[:blank:]\h]*\*\///s ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 92 | { | ||||||||||||||||||||||||||||
| 93 | 2 | $self->message( 3, "Adding comment found before value: '$1'." ); | |||||||||||||||||||||||||||
| 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))
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)])
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 99 | { | ||||||||||||||||||||||||||||
| 100 | 0 | $self->message( 3, "Adding comment found after value: '$1'." ); | |||||||||||||||||||||||||||
| 101 | 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))
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)])
| |||||||||||||||||||||||||||||
| 102 | return( $self->error( "Cannot create comment object: ", CSS::Object::Comment->error ) ); | ||||||||||||||||||||||||||||
| 103 | 0 | $self->comment_after->push( $cmt ); | |||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||
| 105 | 44 | $val =~ s/^[[:blank:]\h]*|[[:blank:]\h]*$//gs; | |||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||
| 107 | 44 | return( $self->_set_get_scalar_as_object( 'value', $val ) ); | |||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||
| 109 | 268 | return( $self->_set_get_scalar_as_object( 'value' ) ); | |||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||
| 112 | sub with_comment | ||||||||||||||||||||||||||||
| 113 | { | ||||||||||||||||||||||||||||
| 114 | 0 | ▶ | my $self = shift( @_ ); | ||||||||||||||||||||||||||
|
Subroutine
with_comment: not called CC=10 SCAR=47.0
Pod
documented
| |||||||||||||||||||||||||||||
| 115 | 0 | my $opts = {}; | |||||||||||||||||||||||||||
| 116 | 0 | ▶ | $opts = shift( @_ ) if( $self->_is_hash( $_[0] ) ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 117 | 0 | ▶ | if( $opts->{before} ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 118 | { | ||||||||||||||||||||||||||||
| 119 | 0 | my $cmt = $self->_comment_data_to_object( $opts->{before} ); | |||||||||||||||||||||||||||
| 120 | 0 | ▶ | defined( $cmt ) || return( $self->pass_error ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 121 | 0 | ▶ | $self->comment_before->push( $cmt ) if( defined( $cmt ) && CORE::length( $cmt ) ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $cmt and length $cmt
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
| |||||||||||||||||||||||||||||
| 122 | } | ||||||||||||||||||||||||||||
| 123 | 0 | ▶ | if( $opts->{after} ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 124 | { | ||||||||||||||||||||||||||||
| 125 | 0 | my $cmt = $self->_comment_data_to_object( $opts->{after} ); | |||||||||||||||||||||||||||
| 126 | 0 | ▶ | defined( $cmt ) || return( $self->pass_error ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 127 | 0 | ▶ | $self->comment_after->push( $cmt ) if( defined( $cmt ) && CORE::length( $cmt ) ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $cmt and length $cmt
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
| |||||||||||||||||||||||||||||
| 128 | } | ||||||||||||||||||||||||||||
| 129 | 0 | return( $self ); | |||||||||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||
| 132 | sub _comment_data_to_object | ||||||||||||||||||||||||||||
| 133 | { | ||||||||||||||||||||||||||||
| 134 | 0 | ▶ | my $self = shift( @_ ); | ||||||||||||||||||||||||||
|
Subroutine
_comment_data_to_object: not called CC=6 SCAR=37.4
| |||||||||||||||||||||||||||||
| 135 | # No data received, we silently return false | ||||||||||||||||||||||||||||
| 136 | 0 | ▶ | my $this = shift( @_ ) || return( '' ); | ||||||||||||||||||||||||||
|
Condition0%0/2
shift @_ || (return '')
MC/DC0%0/1
shift @_ || (return '')
shift @_
Truth table0%0/2
A
A= shift @_
| |||||||||||||||||||||||||||||
| 137 | 0 | ▶ | if( $self->_is_a( $this, 'CSS::Objet::Comment' ) ) | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 138 | { | ||||||||||||||||||||||||||||
| 139 | 0 | return( $this ); | |||||||||||||||||||||||||||
| 140 | } | ||||||||||||||||||||||||||||
| 141 | ▶ | elsif( $self->_is_array( $this ) || !ref( $this ) ) | |||||||||||||||||||||||||||
|
Condition0%0/3
$self->_is_array($this) or not ref $this
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
| |||||||||||||||||||||||||||||
| 142 | { | ||||||||||||||||||||||||||||
| 143 | 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))
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)
| |||||||||||||||||||||||||||||
| 144 | return( $self->error( "Cannot create a new comment from array provided in this property value: ", CSS::Object::Comment->error ) ); | ||||||||||||||||||||||||||||
| 145 | 0 | return( $cmt ); | |||||||||||||||||||||||||||
| 146 | } | ||||||||||||||||||||||||||||
| 147 | else | ||||||||||||||||||||||||||||
| 148 | { | ||||||||||||||||||||||||||||
| 149 | 0 | return( $self->error( "I do not know what to do with comment data \"$this\"." ) ); | |||||||||||||||||||||||||||
| 150 | } | ||||||||||||||||||||||||||||
| 151 | } | ||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||
| 153 | 6 | 1; | |||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||
| 155 | __END__ | ||||||||||||||||||||||||||||