| 1 | package CSS::Simple; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | 6 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 6 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 6 | our $VERSION = '3223'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 6 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 6 | ▶ | use Tie::IxHash; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 6 | ▶ | use Storable qw(dclone); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | =pod | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | CSS::Simple - Interface through which to read/write/manipulate CSS files while respecting the cascade order | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | use CSS::Simple; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | my $css = new CSS::Simple(); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | $css->read_file({ filename => 'input.css' }); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | #perform manipulations... | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | $css->write_file({ filename => 'output.css' }); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | Class for reading, manipulating and writing CSS. Unlike other CSS classes on CPAN this particular module | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | focuses on respecting the order of selectors while providing a common sense API through which to manipulate the | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | rules. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | Please note that while ordering is respected, the exact order of selectors may change. I.e. the rules | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | implied by the styles and their ordering will not change, but the actual ordering of the styles may shift around. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | See the read method for more information. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | BEGIN { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 6 | ▶ | my $members = ['ordered','stylesheet','warns_as_errors','content_warnings','browser_specific_properties']; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | #generate all the getter/setter we need | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 6 | foreach my $member (@{$members}) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 6 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 30 | *{'_' . $member} = sub { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 240 | ▶ | my ($self,$value) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 240 | $self->_check_object(); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 240 | ▶ | $self->{$member} = $value if defined($value); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 240 | return $self->{$member}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 30 | } | |||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | =pod | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | =head1 CONSTRUCTOR | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | =item new ([ OPTIONS ]) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | Instantiates the CSS::Simple object. Sets up class variables that are used during file parsing/processing. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | B<warns_as_errors> (optional). Boolean value to indicate whether fatal errors should occur during parse failures. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | B<browser_specific_properties> (optional). Boolean value to indicate whether browser specific properties should be processed. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | =back | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | sub new { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 10 | ▶ | my ($proto, $params) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=6 SCAR=18.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 10 | ▶ | 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 10 | my $css = {}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | my $self = { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | stylesheet => undef, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 10 | ▶ | ordered => tie(%{$css}, 'Tie::IxHash'), | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition83%5/6
defined $params->{"warns_as_errors"} and $params->{"warns_as_errors"}
defined $params->{"browser_specific_properties"} and $params->{"browser_specific_properties"}
MC/DC50%1/2
defined $params->{"warns_as_errors"} and $params->{"warns_as_errors"}
defined $params->{"warns_as_errors"}
$params->{"warns_as_errors"}
MC/DC100%2/2
defined $params->{"browser_specific_properties"} and $params->{"browser_specific_properties"}
defined $params->{"browser_specific_properties"}
$params->{"browser_specific_properties"}
Truth table66%2/3
A and B
A= defined $params->{"warns_as_errors"}B= $params->{"warns_as_errors"}
Truth table100%3/3
A and B
A= defined $params->{"browser_specific_properties"}B= $params->{"browser_specific_properties"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | content_warnings => undef, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | warns_as_errors => (defined($$params{warns_as_errors}) && $$params{warns_as_errors}) ? 1 : 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 10 | browser_specific_properties => (defined($$params{browser_specific_properties}) && $$params{browser_specific_properties}) ? 1 : 0 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 10 | bless $self, $class; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 10 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | =head1 METHODS | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | =pod | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | =item read_file( params ) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | Opens and reads a CSS file, then subsequently performs the parsing of the CSS file | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | necessary for later manipulation. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | This method requires you to pass in a params hash that contains a | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | filename argument. For example: | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | $self->read_file({filename => 'myfile.css'}); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | sub read_file { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 0 | ▶ | my ($self,$params) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
read_file: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | 0 | $self->_check_object(); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | 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"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 0 | croak "You must pass in hash params that contain a filename argument"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | 0 | ▶ | open FILE, "<", $$params{filename} or croak $!; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | 0 | my $css = do { local( $/ ) ; <FILE> } ; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | 0 | close FILE; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | 0 | $self->read({css => $css}); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | 0 | return(); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | =pod | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | =item read( params ) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | Reads css data and parses it. The intermediate data is stored in class variables. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | Compound selectors (i.e. "a, span") are split apart during parsing and stored | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | separately, so the output of any given stylesheet may not match the output 100%, but the | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | rules themselves should apply as expected. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | Ordering of selectors may shift if the same selector is seen twice within the stylesheet. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | The precendence for any given selector is the last time it was seen by the parser. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | This method requires you to pass in a params hash that contains scalar | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | css data. For example: | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | $self->read({css => $css}); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | sub read { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | 8 | ▶ | my ($self,$params) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
read: called CC=13 SCAR=26.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | 8 | $self->_check_object(); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | 8 | $self->_content_warnings({}); # overwrite any existing warnings | |||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | 8 | ▶ | unless (exists $$params{css}) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | 0 | croak 'You must pass in hash params that contains the css data'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | 8 | ▶ | if ($params && $$params{css}) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$params and $params->{"css"}
MC/DC0%0/2
$params and $params->{"css"}
$params
$params->{"css"}
Truth table33%1/3
A and B
A= $paramsB= $params->{"css"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | # Flatten whitespace and remove /* comment */ style comments | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | 8 | my $string = $$params{css}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | 8 | $string =~ tr/\n\t/ /; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | 8 | $string =~ s!/\*.*?\*\/!!g; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | # Split into styles | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | 8 | foreach (grep { /\S/ } split /(?<=\})/, $string) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | 30 | ▶ | unless ( /^\s*([^{]+?)\s*\{(.*)\}\s*$/ ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | 0 | $self->_report_warning({ info => "Invalid or unexpected style data '$_'" }); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | # Split in such a way as to support grouped styles | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | 30 | my $rule = $1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | 30 | my $props = $2; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | 30 | $rule =~ s/\s{2,}/ /g; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | # Split into properties | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | 30 | my $properties = {}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | 30 | foreach ( grep { /\S/ } split /\;/, $props ) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | # skip over browser specific properties unless specified in constructor | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | 59 | ▶ | if (!$self->_browser_specific_properties() && (( /^\s*[*-_]/ ) || ( /\\/ ))) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
not $self->_browser_specific_properties and /^\s*[*-_]/ || /\\/
/^\s*[*-_]/ or /\\/
MC/DC66%2/3
not $self->_browser_specific_properties and /^\s*[*-_]/ || /\\/
not $self->_browser_specific_properties
/^\s*[*-_]/
/\\/
Truth table75%3/4
not(A) and B or C
A= not $self->_browser_specific_propertiesB= /^\s*[*-_]/C= /\\/
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | 12 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | # check if properties are valid, reporting error as configured | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | 47 | ▶ | unless ( /^\s*([\w._-]+)\s*:\s*(.*?)\s*$/ ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | 3 | $self->_report_warning({ info => "Invalid or unexpected property '$_' in style '$rule'" }); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | 2 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | #store the property for later | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | 44 | $$properties{lc $1} = $2; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | 29 | my @selectors = split /,/, $rule; # break the rule into the component selector(s) | |||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | #apply the found rules to each selector | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | 29 | foreach my $selector (@selectors) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | 30 | $selector =~ s/^\s+|\s+$//g; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | 30 | ▶ | if ($self->check_selector({selector => $selector})) { #check if we already exist | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | 3 | my $old_properties = $self->get_properties({selector => $selector}); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | 3 | $self->delete_selector({selector => $selector}); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | 3 | my %merged = (%$old_properties, %$properties); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | 3 | $self->add_selector({selector => $selector, properties => \%merged}); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | #store the properties within this selector | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | 27 | $self->add_selector({selector => $selector, properties => $properties}); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | 0 | $self->_report_warning({ info => 'No stylesheet data was found in the document'}); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | 7 | return(); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | =pod | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | =item write_file() | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | Write the parsed and manipulated CSS out to a file parameter | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | This method requires you to pass in a params hash that contains a | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | filename argument. For example: | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | $self->write_file({filename => 'myfile.css'}); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | sub write_file { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | 0 | ▶ | my ($self,$params) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
write_file: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | 0 | $self->_check_object(); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | 0 | ▶ | unless (exists $$params{filename}) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | 0 | croak "No filename specified for write operation"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | # Write the file | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | 0 | ▶ | open( CSS, '>'. $$params{filename} ) or croak "Failed to open file '$$params{filename}' for writing: $!"; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | 0 | print CSS $self->write(); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | 0 | close( CSS ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | 0 | return(); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | =pod | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | =item write() | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | Write the parsed and manipulated CSS out to a scalar and return it | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | sub write { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | 4 | ▶ | my ($self,$params) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
write: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | 4 | $self->_check_object(); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | 4 | my $contents = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | 4 | foreach my $selector ( $self->_ordered()->Keys ) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | #grab the properties that make up this particular selector | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | 28 | my $properties = $self->get_properties({selector => $selector}); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | 28 | ▶ | if (keys(%{$properties})) { # only output if the selector has properties | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | 23 | $contents .= "$selector {\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | 23 | foreach my $property ( sort keys %{ $properties } ) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | 42 | $contents .= "\t" . lc($property) . ": ".$properties->{$property}. ";\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | 23 | $contents .= "}\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | 4 | return $contents; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | =pod | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | =item content_warnings() | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | Return back any warnings thrown while parsing a given block of css | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | Note: content warnings are initialized at read time. In order to | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | receive back content feedback you must perform read() first. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | sub content_warnings { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | 1 | ▶ | my ($self,$params) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
content_warnings: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | 1 | $self->_check_object(); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | 1 | my @content_warnings = keys %{$self->_content_warnings()}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | 1 | return \@content_warnings; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | #################################################################### | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | # # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | # The following are all get/set methods for manipulating the # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | # stored stylesheet # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | # # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | # Provides a nicer interface than dealing with TIE # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | # # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | #################################################################### | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 325 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 326 | =pod | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 327 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 328 | =item get_selectors( params ) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 329 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 330 | Get an array of selectors that represents an inclusive list of all selectors | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 331 | stored. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 332 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 333 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 334 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | sub get_selectors { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | 0 | ▶ | my ($self,$params) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_selectors: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | 0 | $self->_check_object(); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 339 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 340 | 0 | return($self->_ordered()->Keys()); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 341 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 342 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 343 | =pod | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 344 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 345 | =item get_properties( params ) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 346 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 347 | Get a hash that represents the various properties for this particular selector | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 348 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 349 | This method requires you to pass in a params hash that contains scalar | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 350 | css data. For example: | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 351 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 352 | $self->get_properties({selector => '.foo'}); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 353 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 354 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 355 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 356 | sub get_properties { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 357 | 39 | ▶ | my ($self,$params) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_properties: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 358 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 359 | 39 | $self->_check_object(); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 360 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 361 | 39 | return($self->_ordered()->FETCH($$params{selector})); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 362 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 363 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 364 | =pod | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 365 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 366 | =item check_selector( params ) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 367 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 368 | Determine if a selector exists within the stored rulesets | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 369 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 370 | This method requires you to pass in a params hash that contains scalar | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 371 | css data. For example: | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 372 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 373 | $self->check_selector({selector => '.foo'}); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 374 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 375 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 376 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 377 | sub check_selector { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 378 | 77 | ▶ | my ($self,$params) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
check_selector: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 379 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 380 | 77 | $self->_check_object(); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 381 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 382 | 77 | return($self->_ordered()->EXISTS($$params{selector})); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 383 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 384 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 385 | =pod | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 386 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 387 | =item modify_selector( params ) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 388 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 389 | Modify an existing selector | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 390 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 391 | Modifying a selector maintains the existing selectivity of the rule with relation to the | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 392 | original stylesheet. If you want to ignore that selectivity, delete the element and re-add | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 393 | it to CSS::Simple | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 394 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 395 | This method requires you to pass in a params hash that contains scalar | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 396 | css data. For example: | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 397 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 398 | $self->modify_selector({selector => '.foo', new_selector => '.bar' }); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 399 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 400 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 401 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 402 | sub modify_selector { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 403 | 2 | ▶ | my ($self,$params) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
modify_selector: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 404 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 405 | 2 | $self->_check_object(); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 406 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 407 | #if the selector is found, replace the selector | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 408 | 2 | ▶ | if ($self->check_selector({selector => $$params{selector}})) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 409 | #we probably want to be doing this explicitely | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 410 | 2 | my ($index) = $self->_ordered()->Indices( $$params{selector} ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 411 | 2 | my $properties = $self->get_properties({selector => $$params{selector}}); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 412 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 413 | 2 | $self->_ordered()->Replace($index,$properties,$$params{new_selector}); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 414 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 415 | #otherwise new element, stick it onto the end of the rulesets | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 416 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 417 | #add a selector, there was nothing to replace | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 418 | 0 | $self->add_selector({selector => $$params{new_selector}, properties => {}}); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 419 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 420 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 421 | 2 | return(); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 422 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 423 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 424 | =pod | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 425 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 426 | =item add_selector( params ) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 427 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 428 | Add a selector and associated properties to the stored rulesets | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 429 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 430 | In the event that this particular ruleset already exists, invoking this method will | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 431 | simply replace the item. This is important - if you are modifying an existing rule | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 432 | using this method than the previously existing selectivity will continue to persist. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 433 | Delete the selector first if you want to ignore the previous selectivity. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 434 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 435 | This method requires you to pass in a params hash that contains scalar | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 436 | css data. For example: | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 437 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 438 | $self->add_selector({selector => '.foo', properties => {color => 'red' }}); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 439 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 440 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 441 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 442 | sub add_selector { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 443 | 41 | ▶ | my ($self,$params) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
add_selector: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 444 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 445 | 41 | $self->_check_object(); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 446 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 447 | #if we existed already, invoke REPLACE to preserve selectivity | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 448 | 41 | ▶ | if ($self->check_selector({selector => $$params{selector}})) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 449 | #we probably want to be doing this explicitely | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 450 | 2 | my ($index) = $self->_ordered()->Indices( $$params{selector} ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 451 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 452 | 2 | $self->_ordered()->Replace($index,dclone($$params{properties})); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 453 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 454 | #new element, stick it onto the end of the rulesets | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 455 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 456 | #store the properties | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 457 | 39 | $self->_ordered()->STORE($$params{selector},dclone($$params{properties})); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 458 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 459 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 460 | 41 | return(); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 461 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 462 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 463 | =pod | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 464 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 465 | =item add_properties( params ) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 466 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 467 | Add properties to an existing selector, preserving the selectivity of the original declaration. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 468 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 469 | In the event that this method is invoked with a selector that doesn't exist then the call | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 470 | is just translated to an add_selector call, thus creating the rule at the end of the ruleset. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 471 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 472 | This method requires you to pass in a params hash that contains scalar | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 473 | css data. For example: | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 474 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 475 | $self->add_properties({selector => '.foo', properties => {color => 'red' }}); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 476 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 477 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 478 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 479 | sub add_properties { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 480 | 4 | ▶ | my ($self,$params) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
add_properties: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 481 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 482 | 4 | $self->_check_object(); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 483 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 484 | #If selector exists already, merge properties into this selector | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 485 | 4 | ▶ | if ($self->check_selector({selector => $$params{selector}})) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 486 | #merge property sets together | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 487 | 1 | my %properties = (%{$self->get_properties({selector => $$params{selector}})}, %{$$params{properties}}); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 488 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 489 | #overwrite the existing properties for this selector with the new hybrid style | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 490 | 1 | $self->add_selector({selector => $$params{selector}, properties => \%properties}); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 491 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 492 | #otherwise add it wholesale | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 493 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 494 | 3 | $self->add_selector({selector => $$params{selector}, properties => $$params{properties}}); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 495 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 496 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 497 | 4 | return(); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 498 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 499 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 500 | =pod | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 501 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 502 | =item delete_selector( params ) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 503 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 504 | Delete a selector from the ruleset | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 505 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 506 | This method requires you to pass in a params hash that contains scalar | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 507 | css data. For example: | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 508 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 509 | $self->delete_selector({selector => '.foo' }); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 510 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 511 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 512 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 513 | sub delete_selector { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 514 | 3 | ▶ | my ($self,$params) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
delete_selector: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 515 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 516 | 3 | $self->_check_object(); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 517 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 518 | #store the properties, potentially overwriting properties that were there | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 519 | 3 | $self->_ordered()->DELETE($$params{selector}); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 520 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 521 | 3 | return(); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 522 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 523 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 524 | =pod | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 525 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 526 | =item delete_property( params ) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 527 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 528 | Delete a property from a specific selectors rules | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 529 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 530 | This method requires you to pass in a params hash that contains scalar | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 531 | css data. For example: | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 532 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 533 | $self->delete_property({selector => '.foo', property => 'color' }); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 534 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 535 | =back | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 536 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 537 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 538 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 539 | sub delete_property { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 540 | 1 | ▶ | my ($self,$params) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
delete_property: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 541 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 542 | 1 | $self->_check_object(); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 543 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 544 | #get the properties so we can remove the requested property from the hash | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 545 | 1 | my $properties = $self->get_properties({selector => $$params{selector}}); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 546 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 547 | 1 | delete $$properties{$$params{property}}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 548 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 549 | 1 | $self->add_selector({selector => $$params{selector}, properties => $properties}); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 550 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 551 | 1 | return(); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 552 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 553 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 554 | #################################################################### | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 555 | # # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 556 | # The following are all private methods and are not for normal use # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 557 | # I am working to finalize the get/set methods to make them public # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 558 | # # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 559 | #################################################################### | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 560 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 561 | sub _check_object { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 562 | 423 | ▶ | my ($self,$params) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_check_object: called CC=3 SCAR=13.3
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 563 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 564 | 423 | ▶ | 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 565 | 0 | croak "You must instantiate this class in order to properly use it"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 566 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 567 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 568 | 423 | return(); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 569 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 570 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 571 | sub _report_warning { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 572 | 3 | ▶ | my ($self,$params) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_report_warning: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 573 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 574 | 3 | $self->_check_object(); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 575 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 576 | 3 | ▶ | if ($self->{warns_as_errors}) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 577 | 1 | croak $$params{info}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 578 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 579 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 580 | 2 | my $warnings = $self->_content_warnings(); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 581 | 2 | $$warnings{$$params{info}} = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 582 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 583 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 584 | 2 | return(); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 585 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 586 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 587 | 6 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 588 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 589 | =pod | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 590 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 591 | =head1 Sponsor | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 592 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 593 | This code has been developed under sponsorship of MailerMailer LLC, http://www.mailermailer.com/ | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 594 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 595 | =head1 AUTHOR | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 596 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 597 | Kevin Kamel <C<kamelkev@mailermailer.com>> | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 598 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 599 | =head1 ATTRIBUTION | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 600 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 601 | This module is directly based off of Adam Kennedy's <adamk@cpan.org> CSS::Tiny module. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 602 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 603 | This particular version differs in terms of interface and the ultimate ordering of the CSS. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 604 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 605 | =head1 LICENSE | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 606 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 607 | This module is a derived version of Adam Kennedy's CSS::Tiny Module. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 608 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 609 | This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 610 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 611 | The full text of the license can be found in the LICENSE file included with this module. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 612 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 613 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||