Object/Rule/Keyframes.pm

filter: Statementstmt 97.8% 45 / 46 Branchbran 70.0% 7 / 10 Conditioncond 40.0% 2 / 5 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 91.6% 11 / 12 Podpod 80.0% 4 / 5 totaltotal 85.1% 69 / 81 CC 9 SCAR 14.0
CC
9
Cov
89%
frame
8.3
init
2.0
rules
2.0
CRAP 4.1
« Object/Format.pm ↑ Summary Object/Rule.pm »
1 ##----------------------------------------------------------------------------
2 ## CSS Object Oriented - ~/lib/CSS/Object/Rule.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::Rule::Keyframes;
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 ## We add CSS::Object in our @ISA so that we can add rule to our KeyframesRule package
16 ## KeyFrames are special rules that are blocks of further rules
17 6 ▶ use parent qw( CSS::Object::Rule::At CSS::Object );
Subroutine BEGIN: called CC=1 SCAR=0.0
18 6 ▶ use Devel::Confess;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 6 ▶ use Want ();
Subroutine BEGIN: called CC=1 SCAR=0.0
20 use overload (
21 6 '""' => 'as_string',
22 fallback => 1,
23 6 ▶ );
Subroutine BEGIN: called CC=1 SCAR=0.0
24 6 ▶ our $VERSION = 'v0.1.0';
Subroutine BEGIN: called CC=1 SCAR=0.0
25 };
26  
27 sub init
28 {
29 1 ▶ my $self = shift( @_ );
Subroutine init: called CC=2 SCAR=7.0
Pod documented
30 1 ▶ $self->SUPER::init( @_ ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->SUPER::init(@_) or return $self->pass_error 0 1 1
31 1 $self->format->indent( ' ' );
32 1 return( $self );
33 }
34  
35 sub as_string
36 {
37 19 ▶ my $self = shift( @_ );
Subroutine as_string: called CC=1 SCAR=0.0
Pod documented
38 # $self->messagef( 3, "There are %d elements for this keyframes.", $self->elements->length );
39 19 return( $self->format->keyframes_as_string( $self ) );
40 }
41  
42 sub frame
43 {
44 7 ▶ my $self = shift( @_ );
Subroutine frame: called CC=8 SCAR=21.1
Pod undocumented
45 # no overloading;
46 ## $offset can be a scalar or an array reference
47 7 my( $offset, @props ) = @_;
48 ## If we are given an hash reference, we make it an array with hash keys sorted
49 7 ▶ if( scalar( @props ) == 1 && $self->_is_hash( $props[0] ) )
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @props == 1 and $self->_is_hash($props[0])) 7 0 7
Condition33%1/3
scalar @props == 1 and $self->_is_hash($props[0])
!ll&&!rl&&r
007
MC/DC0%0/2
scalar @props == 1 and $self->_is_hash($props[0])
scalar @props == 1 $self->_is_hash($props[0])
Truth table33%1/3
A and B
A= scalar @props == 1B= $self->_is_hash($props[0])
ABresult
0X0
100
111
50 {
51 7 @props = map{ $_ => $props[0]->{ $_ } } sort( keys( %{$props[0]} ) );
52 }
53 7 ▶ return( $self->error( "Uneven number of parameters to set keyframes" ) ) if( scalar( @props ) % 2 );
Branch: 1 branch
BranchTrueFalseTotal
if scalar(@props) % 2 0 7 7
54 7 my $css = $self->css;
55 7 ▶ my $frame_rule = $css->new_rule->add_to( $self ) ||
Condition50%1/2
$css->new_rule->add_to($self) || (return $self->error('Cannot add new rule: ', 'CSS::Object::Rule::Keyframes'->error))
l!l
70
MC/DC0%0/1
$css->new_rule->add_to($self) || (return $self->error('Cannot add new rule: ', 'CSS::Object::Rule::Keyframes'->error))
$css->new_rule->add_to($self)
Truth table50%1/2
A
A= $css->new_rule->add_to($self)
Aresult
11
00
56 return( $self->error( "Cannot add new rule: ", CSS::Object::Rule::Keyframes->error ) );
57 7 $frame_rule->format->indent( ' ' );
58 ## $self->message( 3, "Frame rule indent is now '", $frame_rule->format->indent->scalar, "'." );
59 7 ▶ if( $self->_is_array( $offset ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_is_array($offset)) { } 1 6 7
60 {
61 1 foreach my $this ( @$offset )
62 {
63 6 $css->new_selector( name => "${this}\%" )->add_to( $frame_rule );
64 }
65 }
66 else
67 {
68 6 $css->new_selector( name => "${offset}\%" )->add_to( $frame_rule );
69 }
70 7 ▶ while( my( $prop, $val ) = CORE::splice( @props, 0, 2 ) )
Branch: 1 branch
BranchTrueFalseTotal
if (() = splice(@props, 0, 2)) 7 7 14
71 {
72 # $self->message( 3, "Adding property '$prop' with value '$val' to keyframes." );
73 7 $prop =~ tr/_/-/;
74 7 $css->new_property( name => $prop, value => $val )->add_to( $frame_rule )->format->indent( ' ' );
75 }
76 # $self->messagef( 3, "Frame rules completed registering %d elements.", $frame_rule->elements->length );
77 ## For chaining
78 7 return( $self );
79 }
80  
81 # In our @ rule, we hold all the rules. This makes our @ rule special, because it is a rule that contains a set of rules
82 # Array of CSS::Object::Rule::Keyframes objects
83 0 ▶sub rules { return( shift->_set_get_array_as_object( 'rules', @_ ) ); }
Subroutine rules: not called CC=1 SCAR=6.9
Pod documented
84  
85 20 ▶sub type { return( shift->_set_get_scalar_as_object( 'type', @_ ) ); }
Subroutine type: called CC=1 SCAR=0.0
Pod documented
86  
87  
88 6 1;
89  
90 __END__
« Object/Format.pm ↑ Summary Object/Rule.pm »