Object/Format/Inline.pm

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