| 1 | ##---------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 2 | ## CSS Object Oriented - ~/lib/CSS/Object/Rule/Keyframes.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::Rule::Keyframes; | ||||||||||||||||||||||||||||
| 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 | # We add CSS::Object in our @ISA so that we can add rule to our KeyframesRule package | ||||||||||||||||||||||||||||
| 19 | # KeyFrames are special rules that are blocks of further rules | ||||||||||||||||||||||||||||
| 20 | 6 | ▶ | use parent qw( CSS::Object::Rule::At CSS::Object ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 21 | 6 | ▶ | use Wanted (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 22 | 6 | ▶ | use overload ( | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 23 | 6 | '""' => 'as_string', | |||||||||||||||||||||||||||
| 24 | fallback => 1, | ||||||||||||||||||||||||||||
| 25 | 6 | ); | |||||||||||||||||||||||||||
| 26 | 6 | our $VERSION = 'v0.2.0'; | |||||||||||||||||||||||||||
| 27 | }; | ||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | sub init | ||||||||||||||||||||||||||||
| 30 | 1 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
init: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||
| 31 | 1 | my $self = shift( @_ ); | |||||||||||||||||||||||||||
| 32 | 1 | ▶ | $self->SUPER::init( @_ ) || return( $self->pass_error ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 33 | 1 | $self->format->indent( ' ' ); | |||||||||||||||||||||||||||
| 34 | 1 | return( $self ); | |||||||||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | sub as_string | ||||||||||||||||||||||||||||
| 38 | 10 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
as_string: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 39 | 10 | my $self = shift( @_ ); | |||||||||||||||||||||||||||
| 40 | 10 | return( $self->format->keyframes_as_string( $self ) ); | |||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | sub frame | ||||||||||||||||||||||||||||
| 44 | 7 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
frame: called CC=8 SCAR=21.1
Pod
undocumented
| |||||||||||||||||||||||||||||
| 45 | 7 | my $self = shift( @_ ); | |||||||||||||||||||||||||||
| 46 | # no overloading; | ||||||||||||||||||||||||||||
| 47 | ## $offset can be a scalar or an array reference | ||||||||||||||||||||||||||||
| 48 | 7 | my( $offset, @props ) = @_; | |||||||||||||||||||||||||||
| 49 | ## If we are given an hash reference, we make it an array with hash keys sorted | ||||||||||||||||||||||||||||
| 50 | 7 | ▶ | if( scalar( @props ) == 1 && $self->_is_hash( $props[0] ) ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
scalar @props == 1 and $self->_is_hash($props[0])
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])
| |||||||||||||||||||||||||||||
| 51 | { | ||||||||||||||||||||||||||||
| 52 | 7 | @props = map{ $_ => $props[0]->{ $_ } } sort( keys( %{$props[0]} ) ); | |||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||
| 54 | 7 | ▶ | return( $self->error( "Uneven number of parameters to set keyframes" ) ) if( scalar( @props ) % 2 ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 55 | 7 | my $css = $self->css; | |||||||||||||||||||||||||||
| 56 | 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))
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)
| |||||||||||||||||||||||||||||
| 57 | return( $self->error( "Cannot add new rule: ", CSS::Object::Rule::Keyframes->error ) ); | ||||||||||||||||||||||||||||
| 58 | 7 | $frame_rule->format->indent( ' ' ); | |||||||||||||||||||||||||||
| 59 | 7 | ▶ | if( $self->_is_array( $offset ) ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 71 | { | ||||||||||||||||||||||||||||
| 72 | 7 | $prop =~ tr/_/-/; | |||||||||||||||||||||||||||
| 73 | 7 | $css->new_property( name => $prop, value => $val )->add_to( $frame_rule )->format->indent( ' ' ); | |||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||
| 75 | ## For chaining | ||||||||||||||||||||||||||||
| 76 | 7 | return( $self ); | |||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | # In our @ rule, we hold all the rules. This makes our @ rule special, because it is a rule that contains a set of rules | ||||||||||||||||||||||||||||
| 80 | # Array of CSS::Object::Rule::Keyframes objects | ||||||||||||||||||||||||||||
| 81 | 0 | ▶ | sub rules { return( shift->_set_get_array_as_object( 'rules', @_ ) ); } | ||||||||||||||||||||||||||
|
Subroutine
rules: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | 11 | ▶ | sub type { return( shift->_set_get_scalar_as_object( 'type', @_ ) ); } | ||||||||||||||||||||||||||
|
Subroutine
type: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | 6 | 1; | |||||||||||||||||||||||||||
| 87 | # NOTE: POD | ||||||||||||||||||||||||||||
| 88 | __END__ | ||||||||||||||||||||||||||||