Object/Format/Inline.pm

filter: Statementstmt 100% 63 / 63 Branchbran 42.8% 6 / 14 Conditioncond 50.0% 1 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 100% 15 / 15 Podpod 100% 5 / 5 totaltotal 90.0% 90 / 100 CC 10 SCAR 10.0
CC
10
Cov
89%
copy_parameters_from
5.3
rule_as_string
4.5
comment_as_string
3.1
CRAP 2.7
« Object/Rule.pm ↑ Summary Object/Parser.pm »
1 ##----------------------------------------------------------------------------
2 ## CSS Object Oriented - ~/lib/CSS/Object/Format/Inline.pm
3 ## Version v0.1.0
4 ## Copyright(c) 2020 DEGUEST Pte. Ltd.
5 ## Author: Jacques Deguest <@sitael.tokyo.deguest.jp>
6 ## Created 2020/08/09
7 ## Modified 2020/08/09
8 ##
9 ##----------------------------------------------------------------------------
10 package CSS::Object::Format::Inline;
11 BEGIN
12 {
13 2 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 2 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 2 ▶ use parent qw( CSS::Object::Format );
Subroutine BEGIN: called CC=1 SCAR=0.0
16 2 ▶ use Devel::Confess;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 2 ▶ our $VERSION = 'v0.1.0';
Subroutine BEGIN: called CC=1 SCAR=0.0
18 };
19  
20 sub init
21 {
22 1 ▶ my $self = shift( @_ );
Subroutine init: called CC=1 SCAR=0.0
Pod documented
23 1 $self->{new_line} = "\n";
24 1 $self->{open_brace_on_new_line} = 0;
25 1 $self->{close_brace_on_new_line} = 0;
26 1 $self->{open_brace_and_new_line} = 0;
27 1 $self->{indent} = '';
28 1 $self->{property_separator} = ' ';
29 1 $self->{_init_strict_use_sub} = 1;
30 1 $self->SUPER::init( @_ );
31 1 return( $self );
32 }
33  
34 sub comment_as_string
35 {
36 5 ▶ my( $self, $elem ) = @_;
Subroutine comment_as_string: called CC=3 SCAR=11.2
Pod documented
37 2 ▶ no overloading;
Subroutine BEGIN: called CC=1 SCAR=0.0
38 5 ▶ return( $self->error( "No comment object was provided." ) ) if( !$elem );
Branch: 1 branch
BranchTrueFalseTotal
unless $elem 0 5 5
39 5 ▶ return( $self->error( "Comment object provied is not a CSS::Object::Comment object." ) ) if( !$self->_is_a( $elem, 'CSS::Object::Comment' ) );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_is_a($elem, "CSS::Object::Comment") 0 5 5
40 ## Because this is inline, there is no carriage returns
41 5 return( '/* ' . $elem->values->join( ' ' )->scalar . ' */' );
42 }
43  
44 sub copy_parameters_from
45 {
46 8 ▶ my $self = shift( @_ );
Subroutine copy_parameters_from: called CC=5 SCAR=16.7
Pod documented
47 8 ▶ my $fmt = shift( @_ ) || return( $self->error( "No formatter object was provided to copy the parameters from." ) );
Condition50%1/2
shift @_ || (return $self->error('No formatter object was provided to copy the parameters from.'))
l!l
80
MC/DC0%0/1
shift @_ || (return $self->error('No formatter object was provided to copy the parameters from.'))
shift @_
Truth table50%1/2
A
A= shift @_
Aresult
11
00
48 8 ▶ return( $self->error( "Formatter object provided is actually not a formatter object." ) ) if( !$self->_is_a( $fmt, 'CSS::Object::Format' ) );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_is_a($fmt, "CSS::Object::Format") 0 8 8
49 # my( $p, $f, $l ) = caller();
50 # $self->message( 3, "copy_parameters_from called from package $p at line $l in file $f to set indent from '", $self->indent->scalar, "' to '", $fmt->indent->scalar, "'." );
51 ## We only copy the property separator, and ignore all other possible parameters
52 8 my @ok_params = qw(
53 property_separator
54 );
55 8 for( @ok_params )
56 {
57 8 ▶ $self->$_( $fmt->$_ ) if( $fmt->can( $_ ) );
Branch: 1 branch
BranchTrueFalseTotal
if $fmt->can($_) 8 0 8
58 }
59 8 return( $self );
60 }
61  
62 sub elements_as_string
63 {
64 3 ▶ my( $self, $elems ) = @_;
Subroutine elements_as_string: called CC=1 SCAR=0.0
Pod documented
65 2 ▶ no overloading;
Subroutine BEGIN: called CC=1 SCAR=0.0
66 ## Make a backup of parameters and we'll restore them after
67 3 my $backup = $self->backup_parameters;
68 ## new_array() from Module::Generic
69 3 my $all = $backup->{elements} = $self->new_array;
70 $elems->foreach(sub
71 {
72 15 ▶ $all->push( $_->format->backup_parameters );
Subroutine __ANON__: called CC=1 SCAR=0.0
73 15 $_->format->indent( '' );
74 15 $_->format->property_separator( ' ' );
75 3 });
76
77 3 $self->property_separator( ' ' );
78 3 $self->indent( '' );
79 3 my $res = $self->SUPER::elements_as_string( $elems );
80 3 $self->restore_parameters( $backup );
81 $elems->for(sub
82 {
83 15 ▶ my( $i, $this ) = @_;
Subroutine __ANON__: called CC=1 SCAR=0.0
84 15 $this->format->restore_parameters( $all->get( $i ) );
85 3 });
86 3 return( $res );
87 }
88  
89 sub rule_as_string
90 {
91 3 ▶ my( $self, $rule ) = @_;
Subroutine rule_as_string: called CC=4 SCAR=15.0
Pod documented
92 2 ▶ no overloading;
Subroutine BEGIN: called CC=1 SCAR=0.0
93 # $self->message( 3, "Stringifying rule for inline style" );
94 3 ▶ return( $self->error( "No rule object was provided." ) ) if( !$rule );
Branch: 1 branch
BranchTrueFalseTotal
unless $rule 0 3 3
95 3 ▶ return( $self->error( "Rule object provided (", overload::Overloaded( $rule ) ? overload::StrVal( $rule ) : $rule ,") is not an actual rule object." ) ) if( !$self->_is_a( $rule, 'CSS::Object::Rule' ) );
Branch: 2 branches
BranchTrueFalseTotal
unless $self->_is_a($rule, "CSS::Object::Rule") 0 3 3
overload::Overloaded($rule) ? : 0 0 0
96 3 return( $rule->elements_as_string );
97 }
98  
99 2 1;
100  
101 __END__
« Object/Rule.pm ↑ Summary Object/Parser.pm »