| 1 | ##---------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | ## CSS Object Oriented - ~/lib/CSS/Object/Parser/Enhanced.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::Parser::Enhanced; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | BEGIN | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 1 | ▶ | use Module::Generic; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 1 | ▶ | use parent qw( CSS::Object::Parser ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 1 | ▶ | use CSS::Object::Rule; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 1 | ▶ | use CSS::Object::Selector; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 1 | ▶ | use CSS::Object::Property; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 1 | ▶ | use Devel::Confess; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 1 | ▶ | our $VERSION = 'v0.1.0'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | sub parse_string | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 0 | ▶ | my $self = shift( @_ ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
parse_string: not called CC=24 SCAR=64.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 0 | ▶ | my $string = shift( @_ ) || return; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
shift @_ || (return)
MC/DC0%0/1
shift @_ || (return)
shift @_
Truth table0%0/2
A
A= shift @_
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 0 | ▶ | my $css = $self->css || return( $self->error( "Our css object is gone!" ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$self->css || (return $self->error('Our css object is gone!'))
MC/DC0%0/1
$self->css || (return $self->error('Our css object is gone!'))
$self->css
Truth table0%0/2
A
A= $self->css
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 0 | my $this = {}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 0 | ▶ | for( my $pos = 0; $pos < length( $string ); $pos++ ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 0 | my $c = substr( $string, $pos, 1 ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 0 | my $next = substr( $string, $pos + 1, 1 ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 0 | ▶ | my $prev = $pos > 0 ? substr( $string, $pos - 1, 1 ) : ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 0 | ▶ | if( $c eq '*' && $next eq '/' ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 5 branches
Condition0%0/3
$c eq "*" and $next eq "/"
MC/DC0%0/2
$c eq "*" and $next eq "/"
$c eq "*"
$next eq "/"
Truth table0%0/3
A and B
A= $c eq "*"B= $next eq "/"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 0 | $css->new_comment( [ split( /\r?\n/, $this->{line} ) ] )->add_to( $css ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 0 | $this->{line} = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 0 | $this->{inside_comment} = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | ## We found a comment in between rules. Comments within rules are processed separately in parse_element | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | ▶ | elsif( $c eq '/' && $next eq '*' ) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$c eq "/" and $next eq "*"
MC/DC0%0/2
$c eq "/" and $next eq "*"
$c eq "/"
$next eq "*"
Truth table0%0/3
A and B
A= $c eq "/"B= $next eq "*"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 0 | $this->{inside_comment}++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | elsif( $this->{inside_comment} ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 0 | $this->{line} .= $c; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | elsif( $this->{inside_statement} ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | ## If we found a space and the next character is an opening brace, we are inside the element definition | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 0 | ▶ | if( $c =~ /^[[:space:]\h]$/ && | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
Condition0%0/6
$c =~ /^[[:space:]\h]$/ and not $this->{"inside_quote"} and $next eq "{"
$c =~ /^[[:space:]\h]$/ and not $this->{"inside_quote"}
MC/DC0%0/3
$c =~ /^[[:space:]\h]$/ and not $this->{"inside_quote"} and $next eq "{"
$c =~ /^[[:space:]\h]$/
not $this->{"inside_quote"}
$next eq "{"
Truth table0%0/4
A and not(B) and C
A= $c =~ /^[[:space:]\h]$/B= not $this->{"inside_quote"}C= $next eq "{"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | !$this->{inside_quote} && | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | $next eq '{' ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 0 | $this->{name} = $this->{buffer}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 0 | $this->{name} = $self->_trim( $this->{name} ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | ## $pos + 1 because we skip the opening brace | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | $pos = $self->parse_element({ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | data => \$string, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | pos => $pos + 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | name => $this->{name}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 0 | }); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | elsif( $this->{inside_quote} ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 0 | ▶ | if( $c eq $this->{inside_quote} && $prev ne '\\' ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$c eq $this->{"inside_quote"} and $prev ne "\\"
MC/DC0%0/2
$c eq $this->{"inside_quote"} and $prev ne "\\"
$c eq $this->{"inside_quote"}
$prev ne "\\"
Truth table0%0/3
A and B
A= $c eq $this->{"inside_quote"}B= $prev ne "\\"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 0 | $this->{inside_quote} = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 0 | $this->{buffer} .= $c; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | ▶ | elsif( ( $c eq '"' || $c eq "'" ) && $prev ne '\\' ) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/6
$c eq "\"" || $c eq "'" and $prev ne "\\"
$c eq "\"" or $c eq "'"
MC/DC0%0/3
$c eq "\"" || $c eq "'" and $prev ne "\\"
$c eq "\""
$c eq "'"
$prev ne "\\"
Truth table0%0/5
A or B and C
A= $c eq "\""B= $c eq "'"C= $prev ne "\\"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 0 | ▶ | if( $this->{inside_quote} ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 0 | $this->{inside_quote} = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | else | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 0 | $this->{inside_quote} = $c; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 0 | $this->{buffer} .= $c; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | elsif( $this->{inside_quote} ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 0 | $this->{buffer} .= $c; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | else | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 0 | $this->{buffer} .= $c; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | ## We may have found an element, check the first character | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | ## NOTE: Confirm with rfc for the lawful characters | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | ▶ | elsif( !$this->{inside_statement} && $c =~ /^[\@\:\[\#\.a-zA-Z0-9]$/ ) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
not $this->{"inside_statement"} and $c =~ /^[\@\:\[\#\.a-zA-Z0-9]$/
MC/DC0%0/2
not $this->{"inside_statement"} and $c =~ /^[\@\:\[\#\.a-zA-Z0-9]$/
not $this->{"inside_statement"}
$c =~ /^[\@\:\[\#\.a-zA-Z0-9]$/
Truth table0%0/3
not(A) and B
A= not $this->{"inside_statement"}B= $c =~ /^[\@\:\[\#\.a-zA-Z0-9]$/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 0 | $this->{inside_statement}++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 0 | $this->{buffer} = $c; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | sub parse_element | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 0 | ▶ | my $self = shift( @_ ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
parse_element: not called CC=17 SCAR=57.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 0 | my $opts = {}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 0 | ▶ | $opts = shift( @_ ) if( $self->_is_hash( $_[0] ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | ## String reference | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 0 | my $sref = $opts->{data}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 0 | my $pos = $opts->{pos}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | 0 | ▶ | die( "Value provided is not a scalar reference\n" ) if( ref( $sref ) ne 'SCALAR' ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 0 | ▶ | die( "Position provided is not an integer\n" ) if( $pos !~ /^\-?\d+$/ ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 0 | ▶ | my $css = $self->css || return( $self->error( "Our css object is gone!" ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$self->css || (return $self->error('Our css object is gone!'))
MC/DC0%0/1
$self->css || (return $self->error('Our css object is gone!'))
$self->css
Truth table0%0/2
A
A= $self->css
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 0 | ▶ | my $rule = $self->rule_from_token( $opts->{name} ) || return( $self->pass_error ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$self->rule_from_token($opts->{'name'}) || (return $self->pass_error)
MC/DC0%0/1
$self->rule_from_token($opts->{'name'}) || (return $self->pass_error)
$self->rule_from_token($opts->{'name'})
Truth table0%0/2
A
A= $self->rule_from_token($opts->{'name'})
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 0 | my $p; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 0 | my $this = {}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | 0 | ▶ | for( $p = $pos; $p < length( $$sref ); $p++ ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 0 | my $c = substr( $string, $p, 1 ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | 0 | my $next = substr( $string, $p + 1, 1 ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 0 | ▶ | my $prev = $p > 0 ? substr( $string, $p - 1, 1 ) : ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | 0 | ▶ | if( ( $c eq "'" || $c eq '"' ) && $prev ne '\\' ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
Condition0%0/6
$c eq "'" || $c eq "\"" and $prev ne "\\"
$c eq "'" or $c eq "\""
MC/DC0%0/3
$c eq "'" || $c eq "\"" and $prev ne "\\"
$c eq "'"
$c eq "\""
$prev ne "\\"
Truth table0%0/5
A or B and C
A= $c eq "'"B= $c eq "\""C= $prev ne "\\"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | 0 | ▶ | if( $this->{inside_quote} ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | 0 | $this->{inside_quote} = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | else | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | 0 | $this->{inside_quote} = $c; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | 0 | $this->{buffer} .= $c; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | elsif( $this->{inside_quote} ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | 0 | $this->{buffer} .= $c; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | elsif( !length( $this->{prop} ) ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | 0 | $this->{prop} = $c; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | ## We are done with this property, and either this is the start of a sub element, such as with keyframes containing braces for the definitions of each frames | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | ▶ | elsif( $c eq '{' && $prev ne '\\' ) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$c eq "{" and $prev ne "\\"
MC/DC0%0/2
$c eq "{" and $prev ne "\\"
$c eq "{"
$prev ne "\\"
Truth table0%0/3
A and B
A= $c eq "{"B= $prev ne "\\"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | 0 | $this->{prop} .= $this->{buffer}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | 0 | $this->{buffer} = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | 0 | $this->{prop} = $self->_trim( $this->{prop} ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | my $res = $self->parse_element({ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | name => $this->{prop}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | 0 | ▶ | data => $sref, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$self->parse_element({'name', $this->{'prop'}, 'data', $sref, 'pos', $p + 1}) || (return $self->pass_error)
MC/DC0%0/1
$self->parse_element({'name', $this->{'prop'}, 'data', $sref, 'pos', $p + 1}) || (return $self->pass_error)
$self->parse_element({'name', $this->{'prop'}, 'data', $sref, 'pos', $p + 1})
Truth table0%0/2
A
A= $self->parse_element({'name', $this->{'prop'}, 'data', $sref, 'pos', $p + 1})
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | ## After the opening brace we just found | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | pos => $p + 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | }) || return( $self->pass_error ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | 0 | my $props = $res->{properties}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | 0 | $p = $res->{pos}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | ## or we found semicolon which signals the start of the property value | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | else | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | 0 | $this->{buffer} .= $c; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | 0 | $pos = $p; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | 0 | return({ pos => $pos }); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | ## "There are two kinds of statements" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | ## https://developer.mozilla.org/en-US/docs/Web/CSS/Syntax#CSS_statements | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | sub rule_from_token | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | 0 | ▶ | my $self = shift( @_ ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
rule_from_token: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | 0 | ▶ | my $token = shift( @_ ) || return( $self->error( "No token was provided to create associated rule" ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
shift @_ || (return $self->error('No token was provided to create associated rule'))
MC/DC0%0/1
shift @_ || (return $self->error('No token was provided to create associated rule'))
shift @_
Truth table0%0/2
A
A= shift @_
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | ## If it's an at-rule | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | 0 | ▶ | if( substr( $token, 0, 1 ) eq '@' ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | else | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | 0 | my $selectors = $self->_split( $token ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | sub _split | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | 0 | ▶ | my $self = shift( @_ ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_split: not called CC=7 SCAR=40.3
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | 0 | my $token = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | 0 | ▶ | return( [] ) if( !length( $token ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | 0 | my $this = {}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | 0 | ▶ | for( my $i = 0; $i < length( $token ); $i++ ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | 0 | my $c = substr( $token, $i, 1 ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | 0 | my $next = substr( $token, $i + 1, 1 ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | 0 | ▶ | my $prev = $i > 0 ? substr( $token, $i - 1, 1 ) : ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | 0 | ▶ | if( $this->{inside_quote} ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | 0 | ▶ | if( $c eq $this->{inside_quote} && $prev ne '\\' ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$c eq $this->{"inside_quote"} and $prev ne "\\"
MC/DC0%0/2
$c eq $this->{"inside_quote"} and $prev ne "\\"
$c eq $this->{"inside_quote"}
$prev ne "\\"
Truth table0%0/3
A and B
A= $c eq $this->{"inside_quote"}B= $prev ne "\\"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | 0 | $this->{inside_quote} = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | 0 | $this->{buffer} .= $c; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | sub _trim | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | 0 | ▶ | my $self = shift( @_ ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_trim: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | 0 | my $text = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | 0 | ▶ | return if( !length( $text ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | 0 | $text =~ s/^[[:blank:]\h\r\n\v]+|[[:blank:]\h\r\n\v]+$//gs; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | 0 | return( $text ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | 1 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||