| 1 | # Based in large part on the CSS::Tiny CPAN Module | ||||||||||||||||||||||||||||||||||||||||||
| 2 | # http://search.cpan.org/~adamk/CSS-Tiny/ | ||||||||||||||||||||||||||||||||||||||||||
| 3 | # | ||||||||||||||||||||||||||||||||||||||||||
| 4 | # This is version 2 of this module, which concerns itself with very strictly preserving ordering of rules, | ||||||||||||||||||||||||||||||||||||||||||
| 5 | # something that has been the focus of this module series from the beginning. We focus more on preservation | ||||||||||||||||||||||||||||||||||||||||||
| 6 | # of rule ordering than we do on ease of modifying enclosed rules. If you are attempting to modify | ||||||||||||||||||||||||||||||||||||||||||
| 7 | # rules through an API please see CSS::Simple | ||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||
| 9 | package CSS::Inliner::Parser; | ||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||
| 11 | 31 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 12 | 31 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||
| 14 | 31 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||
| 16 | 31 | ▶ | use Storable qw(dclone); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||
| 18 | =pod | ||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||
| 20 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||
| 22 | CSS::Inliner::Parser - Interface through which to read/write CSS files while respecting the cascade order | ||||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||
| 24 | NOTE: This sub-module very seriously focuses on respecting cascade order. As such this module is not for you | ||||||||||||||||||||||||||||||||||||||||||
| 25 | if you want to modified a stylesheet once it's read. If you are looking for that functionality you may | ||||||||||||||||||||||||||||||||||||||||||
| 26 | want to look at the sister module, CSS::Simple | ||||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||
| 28 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||
| 30 | use CSS::Inliner::Parser; | ||||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||
| 32 | my $css = new CSS::Inliner::Parser(); | ||||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||
| 34 | $css->read({ filename => 'input.css' }); | ||||||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||||
| 36 | #perform manipulations... | ||||||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||||||
| 38 | $css->write({ filename => 'output.css' }); | ||||||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||||||
| 40 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||
| 42 | Class for reading and writing CSS. Unlike other CSS classes on CPAN this particular module | ||||||||||||||||||||||||||||||||||||||||||
| 43 | focuses on respecting the order of selectors. This is very useful for things like... inlining | ||||||||||||||||||||||||||||||||||||||||||
| 44 | CSS, or for similar "strict" CSS work. | ||||||||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||||||||
| 46 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||||||
| 48 | BEGIN { | ||||||||||||||||||||||||||||||||||||||||||
| 49 | 31 | ▶ | my $members = ['ordered','stylesheet','warns_as_errors','content_warnings']; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||||||||
| 51 | #generate all the getter/setter we need | ||||||||||||||||||||||||||||||||||||||||||
| 52 | 31 | foreach my $member (@{$members}) { | |||||||||||||||||||||||||||||||||||||||||
| 53 | 31 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||||
| 55 | 124 | *{'_' . $member} = sub { | |||||||||||||||||||||||||||||||||||||||||
| 56 | 300 | ▶ | my ($self,$value) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||||||||
| 58 | 300 | $self->_check_object(); | |||||||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||||||
| 60 | 300 | ▶ | $self->{$member} = $value if defined($value); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||||||
| 62 | 300 | return $self->{$member}; | |||||||||||||||||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||||||||||||||||
| 64 | 124 | } | |||||||||||||||||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||||||
| 68 | =pod | ||||||||||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||||||||||
| 70 | =head1 CONSTRUCTOR | ||||||||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||||||
| 72 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||||||
| 74 | =item new ([ OPTIONS ]) | ||||||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||||||
| 76 | Instantiates the CSS::Inliner::Parser object. Sets up class variables that are used during file parsing/processing. | ||||||||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||||||||
| 78 | B<warns_as_errors> (optional). Boolean value to indicate whether fatal errors should occur during parse failures. | ||||||||||||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||||||||||
| 80 | =back | ||||||||||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||||||||||
| 82 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||||||
| 84 | sub new { | ||||||||||||||||||||||||||||||||||||||||||
| 85 | 35 | ▶ | my ($proto, $params) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=4 SCAR=14.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||||||||
| 87 | 35 | ▶ | my $class = ref($proto) || $proto; | ||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
ref $proto || $proto
MC/DC0%0/2
ref $proto || $proto
ref $proto
$proto
Truth table33%1/3
A || B
A= ref $protoB= $proto
| |||||||||||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||||||||
| 89 | 35 | my $rules = []; | |||||||||||||||||||||||||||||||||||||||||
| 90 | 35 | my $selectors = {}; | |||||||||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||||||||||
| 92 | my $self = { | ||||||||||||||||||||||||||||||||||||||||||
| 93 | stylesheet => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 94 | ordered => $rules, | ||||||||||||||||||||||||||||||||||||||||||
| 95 | selectors => $selectors, | ||||||||||||||||||||||||||||||||||||||||||
| 96 | content_warnings => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 97 | 35 | ▶ | warns_as_errors => (defined($$params{warns_as_errors}) && $$params{warns_as_errors}) ? 1 : 0 | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $params->{"warns_as_errors"} and $params->{"warns_as_errors"}
MC/DC50%1/2
defined $params->{"warns_as_errors"} and $params->{"warns_as_errors"}
defined $params->{"warns_as_errors"}
$params->{"warns_as_errors"}
Truth table66%2/3
A and B
A= defined $params->{"warns_as_errors"}B= $params->{"warns_as_errors"}
| |||||||||||||||||||||||||||||||||||||||||||
| 98 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||||||||||
| 100 | 35 | bless $self, $class; | |||||||||||||||||||||||||||||||||||||||||
| 101 | 35 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||||||||
| 104 | =head1 METHODS | ||||||||||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||||||||||
| 106 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||||||||||||
| 108 | =pod | ||||||||||||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||||||||||||
| 110 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||||||||||||
| 112 | =item read_file( params ) | ||||||||||||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||||||||||||
| 114 | Opens and reads a CSS file, then subsequently performs the parsing of the CSS file | ||||||||||||||||||||||||||||||||||||||||||
| 115 | necessary for later manipulation. | ||||||||||||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||||||||||||
| 117 | This method requires you to pass in a params hash that contains a | ||||||||||||||||||||||||||||||||||||||||||
| 118 | filename argument. For example: | ||||||||||||||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||||||||||||||
| 120 | $self->read_file({ filename => 'myfile.css' }); | ||||||||||||||||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||||||||||||||||
| 122 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||||||||||||
| 124 | sub read_file { | ||||||||||||||||||||||||||||||||||||||||||
| 125 | 0 | ▶ | my ($self,$params) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
read_file: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||||||||||||||
| 127 | 0 | $self->_check_object(); | |||||||||||||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||||||||||||
| 129 | 0 | ▶ | unless ($params && $$params{filename}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$params and $params->{"filename"}
MC/DC0%0/2
$params and $params->{"filename"}
$params
$params->{"filename"}
Truth table0%0/3
A and B
A= $paramsB= $params->{"filename"}
| |||||||||||||||||||||||||||||||||||||||||||
| 130 | 0 | croak "You must pass in hash params that contain a filename argument"; | |||||||||||||||||||||||||||||||||||||||||
| 131 | } | ||||||||||||||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||||||||||||||
| 133 | 0 | ▶ | open FILE, "<", $$params{filename} or croak $!; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 134 | 0 | my $css = do { local( $/ ) ; <FILE> } ; | |||||||||||||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||||||||||||||
| 136 | 0 | $self->read({ css => $css }); | |||||||||||||||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||||||||||||||||
| 138 | 0 | return(); | |||||||||||||||||||||||||||||||||||||||||
| 139 | } | ||||||||||||||||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||||||||||||||||
| 141 | =pod | ||||||||||||||||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||||||||||||||||
| 143 | =item read( params ) | ||||||||||||||||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||||||||||||||||
| 145 | Reads css data and parses it. The intermediate data is stored in class variables. | ||||||||||||||||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||||||||||||||||
| 147 | Compound selectors (i.e. "a, span") are split apart during parsing and stored | ||||||||||||||||||||||||||||||||||||||||||
| 148 | separately, so the output of any given stylesheet may not match the output 100%, but the | ||||||||||||||||||||||||||||||||||||||||||
| 149 | rules themselves should apply as expected. | ||||||||||||||||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||||||||||||||||
| 151 | This method requires you to pass in a params hash that contains scalar | ||||||||||||||||||||||||||||||||||||||||||
| 152 | css data. For example: | ||||||||||||||||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||||||||||||||||
| 154 | $self->read({ css => $css }); | ||||||||||||||||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||||||||||||||||
| 156 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||||||||||||||||
| 158 | sub read { | ||||||||||||||||||||||||||||||||||||||||||
| 159 | 33 | ▶ | my ($self,$params) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
read: called CC=16 SCAR=27.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||||||||||||||||
| 161 | 33 | $self->_check_object(); | |||||||||||||||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||||||||||||||||
| 163 | 33 | $self->_content_warnings({}); # overwrite any existing warnings | |||||||||||||||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||||||||||||||||
| 165 | 33 | ▶ | unless (exists $$params{css}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 166 | 0 | croak 'You must pass in hash params that contains the css data'; | |||||||||||||||||||||||||||||||||||||||||
| 167 | } | ||||||||||||||||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||||||||||||||||
| 169 | 33 | ▶ | if ($params && $$params{css}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$params and $params->{"css"}
MC/DC50%1/2
$params and $params->{"css"}
$params
$params->{"css"}
Truth table66%2/3
A and B
A= $paramsB= $params->{"css"}
| |||||||||||||||||||||||||||||||||||||||||||
| 170 | # Flatten whitespace and remove /* comment */ style comments | ||||||||||||||||||||||||||||||||||||||||||
| 171 | 32 | my $string = $$params{css}; | |||||||||||||||||||||||||||||||||||||||||
| 172 | 32 | $string =~ tr/\n\t/ /; | |||||||||||||||||||||||||||||||||||||||||
| 173 | 32 | $string =~ s!/\*.*?\*\/!!g; | |||||||||||||||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||||||||||||||||
| 175 | # Split into styles | ||||||||||||||||||||||||||||||||||||||||||
| 176 | 32 | my @tokens = grep { /\S/ } (split /(?<=\})/, $string); | |||||||||||||||||||||||||||||||||||||||||
| 177 | 32 | ▶ | while (my $token = shift @tokens) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 178 | 194 | ▶ | if ($token =~ /^\s*@[\w-]+\s+(?:url\()?"/) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 179 | # simple at-rules consisting of a rule name and prelude, but no block - we have to jump through some | ||||||||||||||||||||||||||||||||||||||||||
| 180 | # hoops as we can accidentally capture multi-line rules here. If such a thing happens we capture | ||||||||||||||||||||||||||||||||||||||||||
| 181 | # any inadvertently trapped content and push it back for parsing later | ||||||||||||||||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||||||||||||||||
| 183 | 6 | my $atrule = $token; | |||||||||||||||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||||||||||||||||
| 185 | 6 | $atrule =~ /^\s*(@[\w-]+)\s*((?:url\()?"[^;]*;)(.*)/; | |||||||||||||||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||||||||||||||||
| 187 | 6 | $self->add_at_rule({ type => $1, prelude => $2, block => undef }); | |||||||||||||||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||||||||||||||||
| 189 | 6 | unshift(@tokens, $3); | |||||||||||||||||||||||||||||||||||||||||
| 190 | } | ||||||||||||||||||||||||||||||||||||||||||
| 191 | elsif ($token =~ /^\s*(\@[\w-]+)\s+{\s*([^{]*)}$/) { | ||||||||||||||||||||||||||||||||||||||||||
| 192 | # multiline at-rules without a prelude, nothing to protect here | ||||||||||||||||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||||||||||||||||
| 194 | 2 | $self->add_at_rule({ type => $1, prelude => undef, block => $2 }); | |||||||||||||||||||||||||||||||||||||||||
| 195 | } | ||||||||||||||||||||||||||||||||||||||||||
| 196 | elsif ($token =~ /^\s*\@/) { | ||||||||||||||||||||||||||||||||||||||||||
| 197 | # multiline at-rules with a prelude, nothing to protect here | ||||||||||||||||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||||||||||||||||
| 199 | 11 | my $atrule = $token; | |||||||||||||||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||||||||||||||||
| 201 | 11 | ▶ | for (my $attoken = shift(@tokens); defined($attoken); $attoken = shift(@tokens)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 202 | 28 | ▶ | if ($attoken !~ /^\s*\}\s*$/) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 203 | 17 | $atrule .= "\n$attoken\n"; | |||||||||||||||||||||||||||||||||||||||||
| 204 | } | ||||||||||||||||||||||||||||||||||||||||||
| 205 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 206 | 11 | last; | |||||||||||||||||||||||||||||||||||||||||
| 207 | } | ||||||||||||||||||||||||||||||||||||||||||
| 208 | } | ||||||||||||||||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||||||||||||||||
| 210 | 11 | $atrule =~ /^\s*(@[\w-]+)\s*([^{]*)\{\s*(.*?})$/s; | |||||||||||||||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||||||||||||||||
| 212 | 11 | $self->add_at_rule({ type => $1, prelude => $2, block => $3 }); | |||||||||||||||||||||||||||||||||||||||||
| 213 | } | ||||||||||||||||||||||||||||||||||||||||||
| 214 | elsif ($token =~ /^\s*([^{]+?)\s*{\s*(.*)}\s*$/) { | ||||||||||||||||||||||||||||||||||||||||||
| 215 | # Split in such a way as to support grouped styles | ||||||||||||||||||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||||||||||||||||
| 217 | 175 | my $rule = $1; | |||||||||||||||||||||||||||||||||||||||||
| 218 | 175 | my $props = $2; | |||||||||||||||||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||||||||||||||||
| 220 | 175 | $rule =~ s/\s{2,}/ /g; | |||||||||||||||||||||||||||||||||||||||||
| 221 | |||||||||||||||||||||||||||||||||||||||||||
| 222 | # Split into properties | ||||||||||||||||||||||||||||||||||||||||||
| 223 | 175 | my $properties = {}; | |||||||||||||||||||||||||||||||||||||||||
| 224 | 175 | foreach (grep { /\S/ } split /\;/, $props) { | |||||||||||||||||||||||||||||||||||||||||
| 225 | # skip over browser specific properties | ||||||||||||||||||||||||||||||||||||||||||
| 226 | 290 | ▶ | if ((/^\s*[\*\-\_]/) || (/\\/)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
/^\s*[\*\-\_]/ or /\\/
MC/DC100%2/2
/^\s*[\*\-\_]/ or /\\/
/^\s*[\*\-\_]/
/\\/
Truth table100%3/3
A or B
A= /^\s*[\*\-\_]/B= /\\/
| |||||||||||||||||||||||||||||||||||||||||||
| 227 | 4 | next; | |||||||||||||||||||||||||||||||||||||||||
| 228 | } | ||||||||||||||||||||||||||||||||||||||||||
| 229 | |||||||||||||||||||||||||||||||||||||||||||
| 230 | # check if properties are valid, reporting error as configured | ||||||||||||||||||||||||||||||||||||||||||
| 231 | 286 | ▶ | unless (/^\s*([\w._-]+)\s*:\s*(.*?)\s*$/) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 232 | 3 | $self->_report_warning({ info => "Invalid or unexpected property '$_' in style '$rule'" }); | |||||||||||||||||||||||||||||||||||||||||
| 233 | 2 | next; | |||||||||||||||||||||||||||||||||||||||||
| 234 | } | ||||||||||||||||||||||||||||||||||||||||||
| 235 | |||||||||||||||||||||||||||||||||||||||||||
| 236 | #store the property for later | ||||||||||||||||||||||||||||||||||||||||||
| 237 | 283 | $$properties{lc $1} = $2; | |||||||||||||||||||||||||||||||||||||||||
| 238 | } | ||||||||||||||||||||||||||||||||||||||||||
| 239 | |||||||||||||||||||||||||||||||||||||||||||
| 240 | 174 | my @selectors = split /,/, $rule; # break the rule into the component selector(s) | |||||||||||||||||||||||||||||||||||||||||
| 241 | |||||||||||||||||||||||||||||||||||||||||||
| 242 | #apply the found rules to each selector | ||||||||||||||||||||||||||||||||||||||||||
| 243 | 174 | foreach my $selector (@selectors) { | |||||||||||||||||||||||||||||||||||||||||
| 244 | 184 | $selector =~ s/^\s+|\s+$//g; | |||||||||||||||||||||||||||||||||||||||||
| 245 | |||||||||||||||||||||||||||||||||||||||||||
| 246 | 184 | $self->add_qualified_rule({ selector => $selector, declarations => $properties }); | |||||||||||||||||||||||||||||||||||||||||
| 247 | } | ||||||||||||||||||||||||||||||||||||||||||
| 248 | } | ||||||||||||||||||||||||||||||||||||||||||
| 249 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 250 | 0 | $self->_report_warning({ info => "Invalid or unexpected style data '$_'" }); | |||||||||||||||||||||||||||||||||||||||||
| 251 | } | ||||||||||||||||||||||||||||||||||||||||||
| 252 | } | ||||||||||||||||||||||||||||||||||||||||||
| 253 | } | ||||||||||||||||||||||||||||||||||||||||||
| 254 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 255 | 1 | $self->_report_warning({ info => 'No stylesheet data was found in the document'}); | |||||||||||||||||||||||||||||||||||||||||
| 256 | } | ||||||||||||||||||||||||||||||||||||||||||
| 257 | |||||||||||||||||||||||||||||||||||||||||||
| 258 | 32 | return(); | |||||||||||||||||||||||||||||||||||||||||
| 259 | } | ||||||||||||||||||||||||||||||||||||||||||
| 260 | |||||||||||||||||||||||||||||||||||||||||||
| 261 | =pod | ||||||||||||||||||||||||||||||||||||||||||
| 262 | |||||||||||||||||||||||||||||||||||||||||||
| 263 | =item write_file() | ||||||||||||||||||||||||||||||||||||||||||
| 264 | |||||||||||||||||||||||||||||||||||||||||||
| 265 | Write the parsed and manipulated CSS out to a file parameter | ||||||||||||||||||||||||||||||||||||||||||
| 266 | |||||||||||||||||||||||||||||||||||||||||||
| 267 | This method requires you to pass in a params hash that contains a | ||||||||||||||||||||||||||||||||||||||||||
| 268 | filename argument. For example: | ||||||||||||||||||||||||||||||||||||||||||
| 269 | |||||||||||||||||||||||||||||||||||||||||||
| 270 | $self->write_file({ filename => 'myfile.css' }); | ||||||||||||||||||||||||||||||||||||||||||
| 271 | |||||||||||||||||||||||||||||||||||||||||||
| 272 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 273 | |||||||||||||||||||||||||||||||||||||||||||
| 274 | sub write_file { | ||||||||||||||||||||||||||||||||||||||||||
| 275 | 0 | ▶ | my ($self,$params) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
write_file: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 276 | |||||||||||||||||||||||||||||||||||||||||||
| 277 | 0 | $self->_check_object(); | |||||||||||||||||||||||||||||||||||||||||
| 278 | |||||||||||||||||||||||||||||||||||||||||||
| 279 | 0 | ▶ | unless (exists $$params{filename}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 280 | 0 | croak "No filename specified for write operation"; | |||||||||||||||||||||||||||||||||||||||||
| 281 | } | ||||||||||||||||||||||||||||||||||||||||||
| 282 | |||||||||||||||||||||||||||||||||||||||||||
| 283 | # Write the file | ||||||||||||||||||||||||||||||||||||||||||
| 284 | 0 | ▶ | open( CSS, '>'. $$params{filename} ) or croak "Failed to open file '$$params{filename}' for writing: $!"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 285 | 0 | print CSS $self->write(); | |||||||||||||||||||||||||||||||||||||||||
| 286 | 0 | close( CSS ); | |||||||||||||||||||||||||||||||||||||||||
| 287 | |||||||||||||||||||||||||||||||||||||||||||
| 288 | 0 | return(); | |||||||||||||||||||||||||||||||||||||||||
| 289 | } | ||||||||||||||||||||||||||||||||||||||||||
| 290 | |||||||||||||||||||||||||||||||||||||||||||
| 291 | =pod | ||||||||||||||||||||||||||||||||||||||||||
| 292 | |||||||||||||||||||||||||||||||||||||||||||
| 293 | =item write() | ||||||||||||||||||||||||||||||||||||||||||
| 294 | |||||||||||||||||||||||||||||||||||||||||||
| 295 | Write the parsed and manipulated CSS out to a scalar and return it | ||||||||||||||||||||||||||||||||||||||||||
| 296 | |||||||||||||||||||||||||||||||||||||||||||
| 297 | This code makes some assumptions about the nature of the prelude and data portions of the stored css rules | ||||||||||||||||||||||||||||||||||||||||||
| 298 | and possibly is insufficient. | ||||||||||||||||||||||||||||||||||||||||||
| 299 | |||||||||||||||||||||||||||||||||||||||||||
| 300 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 301 | |||||||||||||||||||||||||||||||||||||||||||
| 302 | sub write { | ||||||||||||||||||||||||||||||||||||||||||
| 303 | 4 | ▶ | my ($self,$params) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
write: called CC=12 SCAR=25.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 304 | |||||||||||||||||||||||||||||||||||||||||||
| 305 | 4 | $self->_check_object(); | |||||||||||||||||||||||||||||||||||||||||
| 306 | |||||||||||||||||||||||||||||||||||||||||||
| 307 | 4 | my $contents = ''; | |||||||||||||||||||||||||||||||||||||||||
| 308 | |||||||||||||||||||||||||||||||||||||||||||
| 309 | 4 | foreach my $rule ( @{$self->_ordered()} ) { | |||||||||||||||||||||||||||||||||||||||||
| 310 | 20 | ▶ | if ($$rule{selector} && $$rule{declarations}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
Condition66%2/3
$rule->{"selector"} and $rule->{"declarations"}
MC/DC50%1/2
$rule->{"selector"} and $rule->{"declarations"}
$rule->{"selector"}
$rule->{"declarations"}
Truth table66%2/3
A and B
A= $rule->{"selector"}B= $rule->{"declarations"}
| |||||||||||||||||||||||||||||||||||||||||||
| 311 | #grab the properties that make up this particular selector | ||||||||||||||||||||||||||||||||||||||||||
| 312 | 12 | my $selector = $$rule{selector}; | |||||||||||||||||||||||||||||||||||||||||
| 313 | 12 | my $declarations = $$rule{declarations}; | |||||||||||||||||||||||||||||||||||||||||
| 314 | |||||||||||||||||||||||||||||||||||||||||||
| 315 | 12 | $contents .= "$selector {\n"; | |||||||||||||||||||||||||||||||||||||||||
| 316 | 12 | foreach my $property ( sort keys %{ $declarations } ) { | |||||||||||||||||||||||||||||||||||||||||
| 317 | 13 | $contents .= " " . lc($property) . ": ".$$declarations{$property}. ";\n"; | |||||||||||||||||||||||||||||||||||||||||
| 318 | } | ||||||||||||||||||||||||||||||||||||||||||
| 319 | 12 | $contents .= "}\n"; | |||||||||||||||||||||||||||||||||||||||||
| 320 | } | ||||||||||||||||||||||||||||||||||||||||||
| 321 | ▶ | elsif ($$rule{type} && $$rule{prelude} && $$rule{block}) { | |||||||||||||||||||||||||||||||||||||||||
|
Condition83%5/6
$rule->{"type"} and $rule->{"prelude"} and $rule->{"block"}
$rule->{"type"} and $rule->{"prelude"}
MC/DC66%2/3
$rule->{"type"} and $rule->{"prelude"} and $rule->{"block"}
$rule->{"type"}
$rule->{"prelude"}
$rule->{"block"}
Truth table75%3/4
A and B and C
A= $rule->{"type"}B= $rule->{"prelude"}C= $rule->{"block"}
| |||||||||||||||||||||||||||||||||||||||||||
| 322 | 4 | $$rule{block} =~ s/([;{])\s*([^;{])/$1\n$2/mg; # attempt to restrict whitespace | |||||||||||||||||||||||||||||||||||||||||
| 323 | 4 | $$rule{block} =~ s/^\s+|\s+$//mg; | |||||||||||||||||||||||||||||||||||||||||
| 324 | 4 | $$rule{block} =~ s/[^\S\r\n]+/ /mg; | |||||||||||||||||||||||||||||||||||||||||
| 325 | 4 | $$rule{block} =~ s/^([\w-]+:)/ $1/mg; | |||||||||||||||||||||||||||||||||||||||||
| 326 | 4 | $$rule{block} =~ s/^/ /mg; | |||||||||||||||||||||||||||||||||||||||||
| 327 | |||||||||||||||||||||||||||||||||||||||||||
| 328 | 4 | $contents .= $$rule{type} . " " . $$rule{prelude} . "{\n" . $$rule{block} . "\n}\n"; | |||||||||||||||||||||||||||||||||||||||||
| 329 | } | ||||||||||||||||||||||||||||||||||||||||||
| 330 | ▶ | elsif ($$rule{type} && $$rule{prelude}) { | |||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$rule->{"type"} and $rule->{"prelude"}
MC/DC50%1/2
$rule->{"type"} and $rule->{"prelude"}
$rule->{"type"}
$rule->{"prelude"}
Truth table66%2/3
A and B
A= $rule->{"type"}B= $rule->{"prelude"}
| |||||||||||||||||||||||||||||||||||||||||||
| 331 | 3 | $contents .= $$rule{type} . " " . $$rule{prelude} . "\n"; | |||||||||||||||||||||||||||||||||||||||||
| 332 | } | ||||||||||||||||||||||||||||||||||||||||||
| 333 | ▶ | elsif ($$rule{type} && $$rule{block}) { | |||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$rule->{"type"} and $rule->{"block"}
MC/DC0%0/2
$rule->{"type"} and $rule->{"block"}
$rule->{"type"}
$rule->{"block"}
Truth table33%1/3
A and B
A= $rule->{"type"}B= $rule->{"block"}
| |||||||||||||||||||||||||||||||||||||||||||
| 334 | 1 | $$rule{block} =~ s/;\s*([\w-]+)/;\n$1/mg; # attempt to restrict whitespace | |||||||||||||||||||||||||||||||||||||||||
| 335 | 1 | $$rule{block} =~ s/^\s+|\s+$//mg; | |||||||||||||||||||||||||||||||||||||||||
| 336 | 1 | $$rule{block} =~ s/[^\S\r\n]+/ /mg; | |||||||||||||||||||||||||||||||||||||||||
| 337 | 1 | $$rule{block} =~ s/([\w-]+:)/ $1/mg; | |||||||||||||||||||||||||||||||||||||||||
| 338 | |||||||||||||||||||||||||||||||||||||||||||
| 339 | 1 | $contents .= $$rule{type} . " {\n" . $$rule{block} . "\n}\n"; | |||||||||||||||||||||||||||||||||||||||||
| 340 | } | ||||||||||||||||||||||||||||||||||||||||||
| 341 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 342 | 0 | $self->_report_warning({ info => "Invalid or unexpected rule encountered while writing out stylesheet" }); | |||||||||||||||||||||||||||||||||||||||||
| 343 | } | ||||||||||||||||||||||||||||||||||||||||||
| 344 | } | ||||||||||||||||||||||||||||||||||||||||||
| 345 | |||||||||||||||||||||||||||||||||||||||||||
| 346 | 4 | return $contents; | |||||||||||||||||||||||||||||||||||||||||
| 347 | } | ||||||||||||||||||||||||||||||||||||||||||
| 348 | |||||||||||||||||||||||||||||||||||||||||||
| 349 | =pod | ||||||||||||||||||||||||||||||||||||||||||
| 350 | |||||||||||||||||||||||||||||||||||||||||||
| 351 | =item content_warnings() | ||||||||||||||||||||||||||||||||||||||||||
| 352 | |||||||||||||||||||||||||||||||||||||||||||
| 353 | Return back any warnings thrown while parsing a given block of css | ||||||||||||||||||||||||||||||||||||||||||
| 354 | |||||||||||||||||||||||||||||||||||||||||||
| 355 | Note: content warnings are initialized at read time. In order to | ||||||||||||||||||||||||||||||||||||||||||
| 356 | receive back content feedback you must perform read() first. | ||||||||||||||||||||||||||||||||||||||||||
| 357 | |||||||||||||||||||||||||||||||||||||||||||
| 358 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 359 | |||||||||||||||||||||||||||||||||||||||||||
| 360 | sub content_warnings { | ||||||||||||||||||||||||||||||||||||||||||
| 361 | 28 | ▶ | my ($self,$params) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
content_warnings: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 362 | |||||||||||||||||||||||||||||||||||||||||||
| 363 | 28 | $self->_check_object(); | |||||||||||||||||||||||||||||||||||||||||
| 364 | |||||||||||||||||||||||||||||||||||||||||||
| 365 | 28 | my @content_warnings = keys %{$self->_content_warnings()}; | |||||||||||||||||||||||||||||||||||||||||
| 366 | |||||||||||||||||||||||||||||||||||||||||||
| 367 | 28 | return \@content_warnings; | |||||||||||||||||||||||||||||||||||||||||
| 368 | } | ||||||||||||||||||||||||||||||||||||||||||
| 369 | |||||||||||||||||||||||||||||||||||||||||||
| 370 | #################################################################### | ||||||||||||||||||||||||||||||||||||||||||
| 371 | # # | ||||||||||||||||||||||||||||||||||||||||||
| 372 | # The following are all get/set methods for manipulating the # | ||||||||||||||||||||||||||||||||||||||||||
| 373 | # stored stylesheet # | ||||||||||||||||||||||||||||||||||||||||||
| 374 | # # | ||||||||||||||||||||||||||||||||||||||||||
| 375 | #################################################################### | ||||||||||||||||||||||||||||||||||||||||||
| 376 | |||||||||||||||||||||||||||||||||||||||||||
| 377 | =pod | ||||||||||||||||||||||||||||||||||||||||||
| 378 | |||||||||||||||||||||||||||||||||||||||||||
| 379 | =item get_rules( params ) | ||||||||||||||||||||||||||||||||||||||||||
| 380 | |||||||||||||||||||||||||||||||||||||||||||
| 381 | Get an array of rules representing the composition of the stylesheet. These rules | ||||||||||||||||||||||||||||||||||||||||||
| 382 | are returned in the exact order that they were discovered. Both qualified and at | ||||||||||||||||||||||||||||||||||||||||||
| 383 | rules are returned by this method. It is left to the caller to pull out the kinds of | ||||||||||||||||||||||||||||||||||||||||||
| 384 | rules your application needs to accomplish your goals. | ||||||||||||||||||||||||||||||||||||||||||
| 385 | |||||||||||||||||||||||||||||||||||||||||||
| 386 | The structures returned match up with the fields set while adding the rules via the add_x_rule collection methods. | ||||||||||||||||||||||||||||||||||||||||||
| 387 | |||||||||||||||||||||||||||||||||||||||||||
| 388 | Specifically at-rules will contain a type, prelude and block while qualified rules will contain a selector and declarations. | ||||||||||||||||||||||||||||||||||||||||||
| 389 | |||||||||||||||||||||||||||||||||||||||||||
| 390 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 391 | |||||||||||||||||||||||||||||||||||||||||||
| 392 | sub get_rules { | ||||||||||||||||||||||||||||||||||||||||||
| 393 | 27 | ▶ | my ($self,$params) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_rules: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 394 | |||||||||||||||||||||||||||||||||||||||||||
| 395 | 27 | $self->_check_object(); | |||||||||||||||||||||||||||||||||||||||||
| 396 | |||||||||||||||||||||||||||||||||||||||||||
| 397 | 27 | return $self->_ordered(); | |||||||||||||||||||||||||||||||||||||||||
| 398 | } | ||||||||||||||||||||||||||||||||||||||||||
| 399 | |||||||||||||||||||||||||||||||||||||||||||
| 400 | =pod | ||||||||||||||||||||||||||||||||||||||||||
| 401 | |||||||||||||||||||||||||||||||||||||||||||
| 402 | =item add_qualified_rule( params ) | ||||||||||||||||||||||||||||||||||||||||||
| 403 | |||||||||||||||||||||||||||||||||||||||||||
| 404 | Add a qualified CSS rule to the ruleset store. | ||||||||||||||||||||||||||||||||||||||||||
| 405 | |||||||||||||||||||||||||||||||||||||||||||
| 406 | The most common type of CSS rule is a qualified rule. This term became more prominent with the rise of CSS3, but is still | ||||||||||||||||||||||||||||||||||||||||||
| 407 | relevant when handling earlier versions of the standard. These rules have a prelude consisting of a CSS selector, along | ||||||||||||||||||||||||||||||||||||||||||
| 408 | with a data block consisting of various rule declarations. | ||||||||||||||||||||||||||||||||||||||||||
| 409 | |||||||||||||||||||||||||||||||||||||||||||
| 410 | Adding a qualified rule is trivial, for example: | ||||||||||||||||||||||||||||||||||||||||||
| 411 | $self->add_qualified_rule({ selector => 'p > a', block => 'color: blue;' }); | ||||||||||||||||||||||||||||||||||||||||||
| 412 | |||||||||||||||||||||||||||||||||||||||||||
| 413 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 414 | |||||||||||||||||||||||||||||||||||||||||||
| 415 | sub add_qualified_rule { | ||||||||||||||||||||||||||||||||||||||||||
| 416 | 186 | ▶ | my ($self,$params) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
add_qualified_rule: called CC=3 SCAR=11.7
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 417 | |||||||||||||||||||||||||||||||||||||||||||
| 418 | 186 | $self->_check_object(); | |||||||||||||||||||||||||||||||||||||||||
| 419 | |||||||||||||||||||||||||||||||||||||||||||
| 420 | 186 | my $rule; | |||||||||||||||||||||||||||||||||||||||||
| 421 | 186 | ▶ | if (exists $$params{selector} && exists $$params{declarations}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
exists $params->{"selector"} and exists $params->{"declarations"}
MC/DC0%0/2
exists $params->{"selector"} and exists $params->{"declarations"}
exists $params->{"selector"}
exists $params->{"declarations"}
Truth table33%1/3
A and B
A= exists $params->{"selector"}B= exists $params->{"declarations"}
| |||||||||||||||||||||||||||||||||||||||||||
| 422 | 186 | $rule = { selector => $$params{selector}, declarations => $$params{declarations} }; | |||||||||||||||||||||||||||||||||||||||||
| 423 | |||||||||||||||||||||||||||||||||||||||||||
| 424 | 186 | push @{$self->_ordered()}, $rule; | |||||||||||||||||||||||||||||||||||||||||
| 425 | } | ||||||||||||||||||||||||||||||||||||||||||
| 426 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 427 | 0 | $self->_report_warning({ info => "Invalid or unexpected data '$_' encountered while trying to add stylesheet rule" }); | |||||||||||||||||||||||||||||||||||||||||
| 428 | } | ||||||||||||||||||||||||||||||||||||||||||
| 429 | |||||||||||||||||||||||||||||||||||||||||||
| 430 | 186 | return $rule; | |||||||||||||||||||||||||||||||||||||||||
| 431 | } | ||||||||||||||||||||||||||||||||||||||||||
| 432 | |||||||||||||||||||||||||||||||||||||||||||
| 433 | =pod | ||||||||||||||||||||||||||||||||||||||||||
| 434 | |||||||||||||||||||||||||||||||||||||||||||
| 435 | =item add_at_rule( params ) | ||||||||||||||||||||||||||||||||||||||||||
| 436 | |||||||||||||||||||||||||||||||||||||||||||
| 437 | Add an at-rule to the ruleset store. | ||||||||||||||||||||||||||||||||||||||||||
| 438 | |||||||||||||||||||||||||||||||||||||||||||
| 439 | The less common variants of CSS rules are know as at-rules. These rules implement various behaviours through various expressions | ||||||||||||||||||||||||||||||||||||||||||
| 440 | containing a rule type, prelude and associated data block. The standard is evolving here, so it is not easy to enumerate such | ||||||||||||||||||||||||||||||||||||||||||
| 441 | examples, but these rules always start with @. | ||||||||||||||||||||||||||||||||||||||||||
| 442 | |||||||||||||||||||||||||||||||||||||||||||
| 443 | At rules are a little more complex, an example: | ||||||||||||||||||||||||||||||||||||||||||
| 444 | $self->add_at_rule({ type => '@media', prelude => 'print', block => 'body { font-size: 10pt; }' }); | ||||||||||||||||||||||||||||||||||||||||||
| 445 | |||||||||||||||||||||||||||||||||||||||||||
| 446 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 447 | |||||||||||||||||||||||||||||||||||||||||||
| 448 | sub add_at_rule { | ||||||||||||||||||||||||||||||||||||||||||
| 449 | 19 | ▶ | my ($self,$params) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
add_at_rule: called CC=4 SCAR=15.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 450 | |||||||||||||||||||||||||||||||||||||||||||
| 451 | 19 | $self->_check_object(); | |||||||||||||||||||||||||||||||||||||||||
| 452 | |||||||||||||||||||||||||||||||||||||||||||
| 453 | 19 | my $rule; | |||||||||||||||||||||||||||||||||||||||||
| 454 | 19 | ▶ | if (exists $$params{type} && exists $$params{prelude} && exists $$params{block}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
exists $params->{"type"} and exists $params->{"prelude"} and exists $params->{"block"}
exists $params->{"type"} and exists $params->{"prelude"}
MC/DC0%0/3
exists $params->{"type"} and exists $params->{"prelude"} and exists $params->{"block"}
exists $params->{"type"}
exists $params->{"prelude"}
exists $params->{"block"}
Truth table25%1/4
A and B and C
A= exists $params->{"type"}B= exists $params->{"prelude"}C= exists $params->{"block"}
| |||||||||||||||||||||||||||||||||||||||||||
| 455 | 19 | $rule = { type => $$params{type}, prelude => $$params{prelude}, block => $$params{block} }; | |||||||||||||||||||||||||||||||||||||||||
| 456 | |||||||||||||||||||||||||||||||||||||||||||
| 457 | 19 | push @{$self->_ordered()}, $rule; | |||||||||||||||||||||||||||||||||||||||||
| 458 | } | ||||||||||||||||||||||||||||||||||||||||||
| 459 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 460 | 0 | $self->_report_warning({ info => "Invalid or unexpected data '$_' encountered while trying to add stylesheet rule" }); | |||||||||||||||||||||||||||||||||||||||||
| 461 | } | ||||||||||||||||||||||||||||||||||||||||||
| 462 | |||||||||||||||||||||||||||||||||||||||||||
| 463 | 19 | return $rule; | |||||||||||||||||||||||||||||||||||||||||
| 464 | } | ||||||||||||||||||||||||||||||||||||||||||
| 465 | |||||||||||||||||||||||||||||||||||||||||||
| 466 | #################################################################### | ||||||||||||||||||||||||||||||||||||||||||
| 467 | # # | ||||||||||||||||||||||||||||||||||||||||||
| 468 | # The following are all private methods and are not for normal use # | ||||||||||||||||||||||||||||||||||||||||||
| 469 | # I am working to finalize the get/set methods to make them public # | ||||||||||||||||||||||||||||||||||||||||||
| 470 | # # | ||||||||||||||||||||||||||||||||||||||||||
| 471 | #################################################################### | ||||||||||||||||||||||||||||||||||||||||||
| 472 | |||||||||||||||||||||||||||||||||||||||||||
| 473 | sub _check_object { | ||||||||||||||||||||||||||||||||||||||||||
| 474 | 601 | ▶ | my ($self,$params) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_check_object: called CC=3 SCAR=13.3
| |||||||||||||||||||||||||||||||||||||||||||
| 475 | |||||||||||||||||||||||||||||||||||||||||||
| 476 | 601 | ▶ | unless ($self && ref $self) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$self and ref $self
MC/DC0%0/2
$self and ref $self
$self
ref $self
Truth table33%1/3
A and B
A= $selfB= ref $self
| |||||||||||||||||||||||||||||||||||||||||||
| 477 | 0 | croak "You must instantiate this class in order to properly use it"; | |||||||||||||||||||||||||||||||||||||||||
| 478 | } | ||||||||||||||||||||||||||||||||||||||||||
| 479 | |||||||||||||||||||||||||||||||||||||||||||
| 480 | 601 | return(); | |||||||||||||||||||||||||||||||||||||||||
| 481 | } | ||||||||||||||||||||||||||||||||||||||||||
| 482 | |||||||||||||||||||||||||||||||||||||||||||
| 483 | sub _report_warning { | ||||||||||||||||||||||||||||||||||||||||||
| 484 | 4 | ▶ | my ($self,$params) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_report_warning: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 485 | |||||||||||||||||||||||||||||||||||||||||||
| 486 | 4 | $self->_check_object(); | |||||||||||||||||||||||||||||||||||||||||
| 487 | |||||||||||||||||||||||||||||||||||||||||||
| 488 | 4 | ▶ | if ($self->{warns_as_errors}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 489 | 1 | croak $$params{info}; | |||||||||||||||||||||||||||||||||||||||||
| 490 | } | ||||||||||||||||||||||||||||||||||||||||||
| 491 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 492 | 3 | my $warnings = $self->_content_warnings(); | |||||||||||||||||||||||||||||||||||||||||
| 493 | 3 | $$warnings{$$params{info}} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 494 | } | ||||||||||||||||||||||||||||||||||||||||||
| 495 | |||||||||||||||||||||||||||||||||||||||||||
| 496 | 3 | return(); | |||||||||||||||||||||||||||||||||||||||||
| 497 | } | ||||||||||||||||||||||||||||||||||||||||||
| 498 | |||||||||||||||||||||||||||||||||||||||||||
| 499 | 31 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 500 | |||||||||||||||||||||||||||||||||||||||||||
| 501 | =pod | ||||||||||||||||||||||||||||||||||||||||||
| 502 | |||||||||||||||||||||||||||||||||||||||||||
| 503 | =back | ||||||||||||||||||||||||||||||||||||||||||
| 504 | |||||||||||||||||||||||||||||||||||||||||||
| 505 | =head1 AUTHOR | ||||||||||||||||||||||||||||||||||||||||||
| 506 | |||||||||||||||||||||||||||||||||||||||||||
| 507 | Kevin Kamel <C<kamelkev@underprint.com>> | ||||||||||||||||||||||||||||||||||||||||||
| 508 | |||||||||||||||||||||||||||||||||||||||||||
| 509 | =head1 ATTRIBUTION | ||||||||||||||||||||||||||||||||||||||||||
| 510 | |||||||||||||||||||||||||||||||||||||||||||
| 511 | This module is directly based off of Adam Kennedy's <adamk@cpan.org> CSS::Tiny module. | ||||||||||||||||||||||||||||||||||||||||||
| 512 | |||||||||||||||||||||||||||||||||||||||||||
| 513 | This particular version differs in terms of interface and the ultimate ordering of the CSS. | ||||||||||||||||||||||||||||||||||||||||||
| 514 | |||||||||||||||||||||||||||||||||||||||||||
| 515 | =head1 LICENSE | ||||||||||||||||||||||||||||||||||||||||||
| 516 | |||||||||||||||||||||||||||||||||||||||||||
| 517 | This module is a derived version of Adam Kennedy's CSS::Tiny Module. | ||||||||||||||||||||||||||||||||||||||||||
| 518 | |||||||||||||||||||||||||||||||||||||||||||
| 519 | This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. | ||||||||||||||||||||||||||||||||||||||||||
| 520 | |||||||||||||||||||||||||||||||||||||||||||
| 521 | The full text of the license can be found in the LICENSE file included with this module. | ||||||||||||||||||||||||||||||||||||||||||
| 522 | |||||||||||||||||||||||||||||||||||||||||||
| 523 | =cut | ||||||||||||||||||||||||||||||||||||||||||