Object/Element.pm

filter: Statementstmt 74.4% 35 / 47 Branchbran 50.0% 7 / 14 Conditioncond 11.1% 1 / 9 MC/DCmcdc 0.0% 0 / 5 Subroutinesub 70.0% 7 / 10 Podpod 100% 5 / 5 totaltotal 61.1% 55 / 90 CC 12 SCAR 22.2
CC
12
Cov
61%
format
16.0
add_to
12.0
init
2.0
CRAP 9.2
« Object.pm ↑ Summary Object/Parser/Default.pm »
1 ##----------------------------------------------------------------------------
2 ## CSS Object Oriented - ~/lib/CSS/Object/Element.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::Element;
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( Module::Generic );
Subroutine BEGIN: called CC=1 SCAR=0.0
19 6 ▶ use CSS::Object::Format;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 6 our $VERSION = 'v0.2.0';
21 };
22  
23 sub init
24 175 ▶{
Subroutine init: called CC=2 SCAR=6.9
Pod documented
25 175 my $self = shift( @_ );
26 175 $self->{format} = '';
27 175 $self->{_init_strict_use_sub} = 1;
28 175 $self->SUPER::init( @_ );
29 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
30 {
31 7 my $format = CSS::Object::Format->new(
32 debug => $self->debug
33 );
34 7 $self->format( $format );
35 }
36 175 return( $self );
37 }
38  
39 sub add_to
40 0 ▶{
Subroutine add_to: not called CC=3 SCAR=24.8
Pod documented
41 0 my $self = shift( @_ );
42 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
43 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
44 0 $self->format->indent( $css->format->indent );
45 0 $css->add_element( $self );
46 0 return( $self );
47 }
48  
49 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
50  
51 0 ▶sub class { return( ref( $_[0] ) ); }
Subroutine class: not called CC=1 SCAR=6.9
Pod documented
52  
53 sub format
54 644 ▶{
Subroutine format: called CC=9 SCAR=27.7
Pod documented
55 644 my $self = shift( @_ );
56 644 my $format;
57 644 ▶ if( @_ )
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 161 483 644
58 {
59 # $format = $self->_set_get_object( 'format', 'CSS::Object::Format', @_ ) || return;
60 161 my $val = shift( @_ );
61 161 my $format;
62 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
63 {
64 161 my $clone = $val->clone;
65 ## Make a copy for ourself
66 161 ▶ if( $self->format )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->format) 30 131 161
67 {
68 30 my( $p, $f, $l ) = caller();
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 483 return( $self->_set_get_object( 'format', 'CSS::Object::Format' ) );
89 }
90  
91 6 1;
92 # NOTE: POD
93 __END__
« Object.pm ↑ Summary Object/Parser/Default.pm »