Object/Element.pm

filter: Statementstmt 76.0% 38 / 50 Branchbran 50.0% 7 / 14 Conditioncond 11.1% 1 / 9 MC/DCmcdc 0.0% 0 / 5 Subroutinesub 72.7% 8 / 11 Podpod 100% 5 / 5 totaltotal 62.7% 59 / 94 CC 12 SCAR 21.7
CC
12
Cov
63%
format
16.0
add_to
12.0
init
2.0
CRAP 8.8
« Object.pm ↑ Summary Object/Property.pm »
1 ##----------------------------------------------------------------------------
2 ## CSS Object Oriented - ~/lib/CSS/Object/Element.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::Element;
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( Module::Generic );
Subroutine BEGIN: called CC=1 SCAR=0.0
16 6 ▶ use CSS::Object::Format;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 6 ▶ use Devel::Confess;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 6 ▶ our $VERSION = 'v0.1.0';
Subroutine BEGIN: called CC=1 SCAR=0.0
19 };
20  
21 sub init
22 {
23 175 ▶ my $self = shift( @_ );
Subroutine init: called CC=2 SCAR=6.9
Pod documented
24 175 $self->{format} = '';
25 175 $self->{_init_strict_use_sub} = 1;
26 175 $self->SUPER::init( @_ );
27 175 ▶ unless( $self->_is_a( $self->{format}, 'CSS::Object::Format' ) )
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_is_a($self->{"format"}, "CSS::Object::Format")) 7 168 175
28 {
29 7 my $format = CSS::Object::Format->new(
30 debug => $self->debug
31 );
32 7 $self->format( $format );
33 }
34 175 return( $self );
35 }
36  
37 sub add_to
38 {
39 0 ▶ my $self = shift( @_ );
Subroutine add_to: not called CC=3 SCAR=24.8
Pod documented
40 0 ▶ my $css = shift( @_ ) || return( $self->error( "No css object was provided to add our element to it." ) );
Condition0%0/2
shift @_ || (return $self->error('No css object was provided to add our element to it.'))
l!l
00
MC/DC0%0/1
shift @_ || (return $self->error('No css object was provided to add our element to it.'))
shift @_
Truth table0%0/2
A
A= shift @_
Aresult
11
00
41 0 ▶ return( $self->error( "CSS object provided (", overload::StrVal( $css ), ") is not actually a CSS::Object object." ) ) if( !$self->_is_a( $css, 'CSS::Object' ) );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_is_a($css, "CSS::Object") 0 0 0
42 0 $self->format->indent( $css->format->indent );
43 0 $css->add_element( $self );
44 0 return( $self );
45 }
46  
47 0 ▶sub as_string { return( shift->error( "This method has not been implemented in this class." ) ); }
Subroutine as_string: not called CC=1 SCAR=6.9
Pod documented
48  
49 0 ▶sub class { return( ref( $_[0] ) ); }
Subroutine class: not called CC=1 SCAR=6.9
Pod documented
50  
51 sub format
52 {
53 928 ▶ my $self = shift( @_ );
Subroutine format: called CC=9 SCAR=27.7
Pod documented
54 928 my $format;
55 928 ▶ if( @_ )
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 161 767 928
56 {
57 # $format = $self->_set_get_object( 'format', 'CSS::Object::Format', @_ ) || return;
58 161 my $val = shift( @_ );
59 # $self->message( 3, "Setting new formatter '$val' for our class '", $self->class, "'." );
60 161 my $format;
61 161 ▶ if( $self->_is_a( $val, 'CSS::Object::Format' ) )
Branch: 2 branches
BranchTrueFalseTotal
if ($self->_is_a($val, 'CSS::Object::Format')) { } 161 0 161
elsif (not ref $val and index($val, '::') != -1) { } 0 0 0
62 {
63 161 my $clone = $val->clone;
64 ## Make a copy for ourself
65 161 ▶ if( $self->format )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->format) 30 131 161
66 {
67 30 my( $p, $f, $l ) = caller();
68 # $self->message( 3, "New formatter provided for our class '", $self->class, "' called from package $p at line $l in file $f to set indent from '", $self->format->indent->scalar, "' to '", $clone->indent->scalar, "'." );
69 30 $clone->copy_parameters_from( $self->format );
70 }
71 161 ▶ $format = $self->_set_get_object( 'format', 'CSS::Object::Format', $clone ) ||
Condition50%1/2
$self->_set_get_object('format', 'CSS::Object::Format', $clone) || (return $self->pass_error)
l!l
1610
MC/DC0%0/1
$self->_set_get_object('format', 'CSS::Object::Format', $clone) || (return $self->pass_error)
$self->_set_get_object('format', 'CSS::Object::Format', $clone)
Truth table50%1/2
A
A= $self->_set_get_object('format', 'CSS::Object::Format', $clone)
Aresult
11
00
72 return( $self->pass_error );
73 # die( "Provided value (", overload::StrVal( $val ), " and stored value (", overload::StrVal( $format ), ") are the same. It should have been cloned.\n" ) if( overload::StrVal( $val ) eq overload::StrVal( $format ) );
74 }
75 ## format as a class name
76 ▶ elsif( !ref( $val ) && CORE::index( $val, '::' ) != -1 )
Condition0%0/3
not ref $val and index($val, "::") != -1
!ll&&!rl&&r
000
MC/DC0%0/2
not ref $val and index($val, "::") != -1
not ref $val index($val, "::") != -1
Truth table0%0/3
not(A) and B
A= not ref $valB= index($val, "::") != -1
ABresult
0X0
100
111
77 {
78 0 ▶ $self->_load_class( $val ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class($val) or return $self->pass_error 0 0 0
79 0 ▶ $format = $val->new( debug => $self->debug ) || return( $self->pass_error( $val->error ) );
Condition0%0/2
$val->new('debug', $self->debug) || (return $self->pass_error($val->error))
l!l
00
MC/DC0%0/1
$val->new('debug', $self->debug) || (return $self->pass_error($val->error))
$val->new('debug', $self->debug)
Truth table0%0/2
A
A= $val->new('debug', $self->debug)
Aresult
11
00
80 0 $self->_set_get_object( 'format', 'CSS::Object::Format', $format );
81 }
82 else
83 {
84 0 return( $self->error( "Unknown format \"$val\". I do not know what to do with it." ) );
85 }
86 161 return( $format );
87 }
88 767 return( $self->_set_get_object( 'format', 'CSS::Object::Format' ) );
89 }
90  
91 6 1;
92  
93 __END__
« Object.pm ↑ Summary Object/Property.pm »