blib/lib/Template/Flute/Style/CSS.pm

filter: Statementstmt 8.4% 21 / 250 Branchbran 0.0% 0 / 140 Conditioncond 0.0% 0 / 53 MC/DCmcdc 0.0% 0 / 34 Subroutinesub 40.0% 6 / 15 Podpod 100% 4 / 4 totaltotal 6.2% 31 / 496 CC 116 SCAR 74.0
CC
116
Cov
5%
_build_properties
3306.0
properties
756.0
descendant_properties
210.0
CRAP 1638.1
↑ Summary
1 package Template::Flute::Style::CSS;
2  
3 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 2 ▶use CSS::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 2 ▶use Template::Flute::Utils;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 # names for the sides of a box, as in border-top, border-right, ...
11 2 ▶use constant SIDE_NAMES => qw/top right bottom left/;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 # default font size - used for the calucation of 1em
14 2 ▶use constant FONT_SIZE => '12';
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 2 our $VERSION = '0.0081';
17  
18 # block elements
19 2 my %block_elements = (address => 1,
20 blockquote => 1,
21 div => 1,
22 dl => 1,
23 fieldset => 1,
24 form => 1,
25 h1 => 1,
26 h2 => 1,
27 h3 => 1,
28 h4 => 1,
29 h5 => 1,
30 h6 => 1,
31 noscript => 1,
32 ol => 1,
33 p => 1,
34 pre => 1,
35 table => 1,
36 ul => 1);
37  
38 =head1 NAME
39  
40 Template::Flute::Style::CSS - CSS parser class for Template::Flute
41  
42 =head1 VERSION
43  
44 Version 0.0081
45  
46 =head1 CONSTRUCTOR
47  
48 =head2 new
49  
50 Create Template::Flute::Style::CSS object with the following parameters:
51  
52 =over 4
53  
54 =item template
55  
56 L<Template::Flute::HTML> object.
57  
58 =item prepend_directory
59  
60 Directory which is prepended to the CSS path when the
61 template doesn't reside in a file.
62  
63 =back
64  
65 =cut
66  
67 0 ▶sub new {
Subroutine new: not called CC=3 SCAR=24.8
Pod documented
68 0 my ($proto, @args) = @_;
69 0 my ($class, $self);
70  
71 0 ▶ $class = ref($proto) || $proto;
Condition0%0/3
ref $proto || $proto
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $proto || $proto
ref $proto $proto
Truth table0%0/3
A || B
A= ref $protoB= $proto
ABresult
1X1
011
000
72 0 $self = {@args};
73  
74 0 bless ($self, $class);
75  
76 0 ▶ if ($self->{template}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"template"}) 0 0 0
77 0 $self->{css} = $self->_initialize();
78 }
79  
80 0 return $self;
81 }
82  
83 0 ▶sub _initialize {
Subroutine _initialize: not called CC=9 SCAR=45.0
84 0 my ($self) = @_;
85 0 my (@ret, $css_file, $css);
86  
87 # create CSS::Tiny object
88 0 $css = new CSS::Tiny;
89  
90 # search for external stylesheets
91 0 for my $ext ($self->{template}->root()->get_xpath(qq{//link})) {
92 0 ▶ if ($ext->att('rel') eq 'stylesheet'
Branch: 1 branch
BranchTrueFalseTotal
if ($ext->att("rel") eq "stylesheet" and $ext->att("type") eq "text/css") 0 0 0
Condition0%0/3
$ext->att("rel") eq "stylesheet" and $ext->att("type") eq "text/css"
!ll&&!rl&&r
000
MC/DC0%0/2
$ext->att("rel") eq "stylesheet" and $ext->att("type") eq "text/css"
$ext->att("rel") eq "stylesheet" $ext->att("type") eq "text/css"
Truth table0%0/3
A and B
A= $ext->att("rel") eq "stylesheet"B= $ext->att("type") eq "text/css"
ABresult
0X0
100
111
93 && $ext->att('type') eq 'text/css') {
94 0 ▶ if ($self->{template}->file) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->{'template'}->file) { } 0 0 0
elsif ($self->{'prepend_directory'}) { } 0 0 0
95 $css_file = Template::Flute::Utils::derive_filename
96 0 ($self->{template}->file, $ext->att('href'), 1);
97 }
98 elsif ($self->{prepend_directory}) {
99 $css_file = join('/', $self->{prepend_directory},
100 0 $ext->att('href'));
101 }
102 else {
103 0 $css_file = $ext->att('href');
104 }
105
106 0 ▶ unless ($css->read($css_file)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($css->read($css_file)) 0 0 0
107 0 die "Failed to parse CSS file $css_file: " . $css->errstr() . "\n";
108 }
109 }
110 }
111
112 # search for inline stylesheets
113 0 push (@ret, $self->{template}->root()->get_xpath(qq{//style}));
114
115 0 for (@ret) {
116 0 ▶ unless ($css->read_string($_->text())) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($css->read_string($_->text)) 0 0 0
117 0 die "Failed to parse inline CSS: " . $css->errstr() . "\n";
118 }
119 }
120
121 0 return $css;
122 }
123  
124 =head1 METHODS
125  
126 =head2 properties
127  
128 Builds CSS properties based on the following parameters:
129  
130 =over 4
131  
132 =item selector
133  
134 CSS selector.
135  
136 =item class
137  
138 CSS class.
139  
140 =item id
141  
142 CSS id.
143  
144 =item tag
145  
146 HTML tag.
147  
148 =item inherit
149  
150 CSS properties to inherit from.
151  
152 =back
153  
154 =cut
155  
156 0 ▶sub properties {
Subroutine properties: not called CC=27 SCAR=66.3
Pod documented
157 0 my ($self, %parms) = @_;
158 0 my (@ids, @classes, @tags, $props);
159  
160 # inherit from parent element
161 0 ▶ if (exists $parms{inherit}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $parms{"inherit"}) 0 0 0
162 0 $props = $self->inherit($parms{inherit});
163 }
164
165 # defaults
166 0 ▶ unless (exists $props->{color}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $props->{"color"}) 0 0 0
167 0 $props->{color} = 'black';
168 }
169
170 0 ▶ unless (exists $props->{font}->{size}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $props->{"font"}{"size"}) 0 0 0
171 0 $props->{font}->{size} = FONT_SIZE;
172 }
173  
174 0 ▶ if (defined $parms{tag} && $parms{tag} =~ /\S/) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $parms{"tag"} and $parms{"tag"} =~ /\S/) 0 0 0
Condition0%0/3
defined $parms{"tag"} and $parms{"tag"} =~ /\S/
!ll&&!rl&&r
000
MC/DC0%0/2
defined $parms{"tag"} and $parms{"tag"} =~ /\S/
defined $parms{"tag"} $parms{"tag"} =~ /\S/
Truth table0%0/3
A and B
A= defined $parms{"tag"}B= $parms{"tag"} =~ /\S/
ABresult
0X0
100
111
175 0 @tags = split(/\s+/, $parms{tag});
176  
177 0 ▶ if (@tags) {
Branch: 1 branch
BranchTrueFalseTotal
if (@tags) 0 0 0
178 0 for my $tag (@tags) {
179 0 $self->_build_properties($props, $tag);
180  
181 0 ▶ if (($parms{tag} eq 'strong' || $parms{tag} eq 'b')
Branch: 1 branch
BranchTrueFalseTotal
if ($parms{"tag"} eq "strong" || $parms{"tag"} eq "b" and not exists $props->{"font"}{"weight"}) 0 0 0
Condition0%0/6
$parms{"tag"} eq "strong" || $parms{"tag"} eq "b" and not exists $props->{"font"}{"weight"}
!ll&&!rl&&r
000
$parms{"tag"} eq "strong" or $parms{"tag"} eq "b"
l!l&&r!l&&!r
000
MC/DC0%0/3
$parms{"tag"} eq "strong" || $parms{"tag"} eq "b" and not exists $props->{"font"}{"weight"}
$parms{"tag"} eq "strong" $parms{"tag"} eq "b" not exists $props->{"font"}{"weight"}
Truth table0%0/5
A or B and not(C)
A= $parms{"tag"} eq "strong"B= $parms{"tag"} eq "b"C= not exists $props->{"font"}{"weight"}
ABCresult
00X0
1X00
0100
1X11
0111
182 && ! exists $props->{font}->{weight}) {
183 0 $props->{font}->{weight} = 'bold';
184 }
185 }
186  
187 0 ▶ if ($parms{tag} eq 'p') {
Branch: 1 branch
BranchTrueFalseTotal
if ($parms{"tag"} eq "p") 0 0 0
188 # add automagic margin of 1em
189 0 for (qw/top bottom/) {
190 0 ▶ unless ($props->{margin}->{$_}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($props->{"margin"}{$_}) 0 0 0
191 0 $props->{margin}->{$_} = $props->{font}->{size};
192  
193 0 ▶ if ($props->{font}->{size} =~ /^[0-9.]+$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($props->{"font"}{"size"} =~ /^[0-9.]+$/) 0 0 0
194 0 $props->{margin}->{$_} .= 'pt';
195 }
196 }
197 }
198 }
199
200 0 ▶ if (! $props->{display} && exists $block_elements{$tags[0]} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $props->{"display"} and exists $block_elements{$tags[0]}) 0 0 0
Condition0%0/3
not $props->{"display"} and exists $block_elements{$tags[0]}
!ll&&!rl&&r
000
MC/DC0%0/2
not $props->{"display"} and exists $block_elements{$tags[0]}
not $props->{"display"} exists $block_elements{$tags[0]}
Truth table0%0/3
not(A) and B
A= not $props->{"display"}B= exists $block_elements{$tags[0]}
ABresult
0X0
100
111
201 0 $props->{display} = 'block';
202 }
203 }
204 }
205
206 0 ▶ if (defined $parms{id} && $parms{id} =~ /\S/) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $parms{"id"} and $parms{"id"} =~ /\S/) 0 0 0
Condition0%0/3
defined $parms{"id"} and $parms{"id"} =~ /\S/
!ll&&!rl&&r
000
MC/DC0%0/2
defined $parms{"id"} and $parms{"id"} =~ /\S/
defined $parms{"id"} $parms{"id"} =~ /\S/
Truth table0%0/3
A and B
A= defined $parms{"id"}B= $parms{"id"} =~ /\S/
ABresult
0X0
100
111
207 0 @ids = split(/\s+/, $parms{id});
208  
209 0 for my $id (@ids) {
210 0 $self->_build_properties($props, "#$id");
211 }
212 }
213  
214 0 ▶ if (defined $parms{class} && $parms{class} =~ /\S/) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $parms{"class"} and $parms{"class"} =~ /\S/) 0 0 0
Condition0%0/3
defined $parms{"class"} and $parms{"class"} =~ /\S/
!ll&&!rl&&r
000
MC/DC0%0/2
defined $parms{"class"} and $parms{"class"} =~ /\S/
defined $parms{"class"} $parms{"class"} =~ /\S/
Truth table0%0/3
A and B
A= defined $parms{"class"}B= $parms{"class"} =~ /\S/
ABresult
0X0
100
111
215 0 @classes = split(/\s+/, $parms{class});
216  
217 0 for my $class (@classes) {
218 0 $self->_build_properties($props, ".$class");
219 0 for (@tags) {
220 0 $self->_build_properties($props, "$_.$class");
221 }
222 }
223 }
224  
225 0 ▶ if (defined $parms{selector} && $parms{selector} =~ /\S/) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $parms{"selector"} and $parms{"selector"} =~ /\S/) 0 0 0
Condition0%0/3
defined $parms{"selector"} and $parms{"selector"} =~ /\S/
!ll&&!rl&&r
000
MC/DC0%0/2
defined $parms{"selector"} and $parms{"selector"} =~ /\S/
defined $parms{"selector"} $parms{"selector"} =~ /\S/
Truth table0%0/3
A and B
A= defined $parms{"selector"}B= $parms{"selector"} =~ /\S/
ABresult
0X0
100
111
226 0 $self->_build_properties($props, $parms{selector});
227 }
228  
229 0 ▶ $props->{display} ||= 'inline';
Condition0%0/2
$props->{"display"} ||= "inline"
l!l
00
MC/DC0%0/1
$props->{"display"} ||= "inline"
$props->{"display"}
Truth table0%0/2
A
A= $props->{"display"}
Aresult
11
00
230  
231 0 $self->_expand_properties($props);
232  
233 0 return $props;
234 }
235  
236 =head2 descendant_properties
237  
238 Builds descendant CSS properties based on the following parameters:
239  
240 =over 4
241  
242 =item parent
243  
244 Parent properties.
245  
246 =item class
247  
248 CSS class.
249  
250 =item id
251  
252 CSS id.
253  
254 =item tag
255  
256 HTML tag.
257  
258 =back
259  
260 =cut
261  
262 0 ▶sub descendant_properties {
Subroutine descendant_properties: not called CC=14 SCAR=53.5
Pod documented
263 0 my ($self, %parms) = @_;
264 0 my (@ids, @classes, @selectors, $regex, $sel, @tags, %selmap);
265  
266 0 ▶ if (ref($parms{parent}) eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $parms{"parent"} eq "HASH") 0 0 0
267 0 %selmap = %{$parms{parent}};
268 }
269  
270 0 ▶ if (defined $parms{id} && $parms{id} =~ /\S/) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $parms{"id"} and $parms{"id"} =~ /\S/) 0 0 0
Condition0%0/3
defined $parms{"id"} and $parms{"id"} =~ /\S/
!ll&&!rl&&r
000
MC/DC0%0/2
defined $parms{"id"} and $parms{"id"} =~ /\S/
defined $parms{"id"} $parms{"id"} =~ /\S/
Truth table0%0/3
A and B
A= defined $parms{"id"}B= $parms{"id"} =~ /\S/
ABresult
0X0
100
111
271 0 @ids = split(/\s+/, $parms{id});
272  
273 0 for my $id (@ids) {
274 0 $regex = qr{^#$id\s+};
275 0 @selectors = $self->_grep_properties($regex);
276  
277 0 for (@selectors) {
278 0 $sel = substr($_, length($id) + 2);
279 0 $selmap{$sel} = $_;
280 }
281 }
282 }
283
284 0 ▶ if (defined $parms{class} && $parms{class} =~ /\S/) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $parms{'class'} and $parms{'class'} =~ /\S/) { } 0 0 0
elsif (defined $parms{'tag'} and $parms{'tag'} =~ /\S/) { } 0 0 0
Condition0%0/3
defined $parms{"class"} and $parms{"class"} =~ /\S/
!ll&&!rl&&r
000
MC/DC0%0/2
defined $parms{"class"} and $parms{"class"} =~ /\S/
defined $parms{"class"} $parms{"class"} =~ /\S/
Truth table0%0/3
A and B
A= defined $parms{"class"}B= $parms{"class"} =~ /\S/
ABresult
0X0
100
111
285 0 @classes = split(/\s+/, $parms{class});
286  
287 0 for my $class (@classes) {
288 0 $regex = qr{^.$class\s+};
289 0 @selectors = $self->_grep_properties($regex);
290  
291 0 for (@selectors) {
292 0 $sel = substr($_, length($class) + 2);
293 0 $selmap{$sel} = $_;
294 }
295 }
296 }
297 ▶ elsif (defined $parms{tag} && $parms{tag} =~ /\S/) {
Condition0%0/3
defined $parms{"tag"} and $parms{"tag"} =~ /\S/
!ll&&!rl&&r
000
MC/DC0%0/2
defined $parms{"tag"} and $parms{"tag"} =~ /\S/
defined $parms{"tag"} $parms{"tag"} =~ /\S/
Truth table0%0/3
A and B
A= defined $parms{"tag"}B= $parms{"tag"} =~ /\S/
ABresult
0X0
100
111
298 0 @tags = split(/\s+/, $parms{tag});
299
300 0 for my $tag (@tags) {
301 0 $regex = qr{^$tag\s+};
302 0 @selectors = $self->_grep_properties($regex);
303
304 0 for (@selectors) {
305 0 $sel = substr($_, length($tag) + 1);
306 0 $selmap{$sel} = $_;
307 }
308 }
309 }
310
311 0 return \%selmap;
312 }
313  
314 0 ▶sub _grep_properties {
Subroutine _grep_properties: not called CC=1 SCAR=6.9
315 0 my ($self, $sel_regex) = @_;
316 0 my (@selectors);
317  
318 0 @selectors = grep {/$sel_regex/} keys %{$self->{css}};
319  
320 0 return @selectors;
321 }
322  
323 0 ▶sub _build_properties {
Subroutine _build_properties: not called CC=57 SCAR=81.0
324 0 my ($self, $propref, $sel) = @_;
325 0 my ($props_css, $sides);
326 0 my (@specs, $value);
327
328 0 $props_css = $self->{css}->{$sel};
329  
330 # background: all possible values in arbitrary order
331 # attachment,color,image,position,repeat
332  
333 0 ▶ if ($value = $props_css->{background}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($value = $props_css->{"background"}) 0 0 0
334 0 @specs = split(/\s+/, $value);
335  
336 0 for (@specs) {
337 # attachment
338 0 ▶ if (/^(fixed|scroll)$/) {
Branch: 1 branch
BranchTrueFalseTotal
if (/^(fixed|scroll)$/) 0 0 0
339 0 $propref->{background}->{attachment} = $1;
340 0 next;
341 }
342 # color (switch later to one of Graphics::ColorNames modules)
343 0 ▶ if (/^(\#[0-9a-f]{3,6})$/) {
Branch: 1 branch
BranchTrueFalseTotal
if (/^(\#[0-9a-f]{3,6})$/) 0 0 0
344 0 $propref->{background}->{color} = $1;
345 0 next;
346 }
347  
348 }
349 }
350  
351 0 for (qw/attachment color image position repeat/) {
352 0 ▶ if ($value = $props_css->{"background-$_"}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($value = $$props_css{"background-$_"}) 0 0 0
353 0 $propref->{background}->{$_} = $value;
354 }
355 }
356
357 # border
358 0 ▶ if ($value = $props_css->{border}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($value = $props_css->{"border"}) 0 0 0
359 0 my ($width, $style, $color) = split(/\s+/, $value);
360
361 0 $propref->{border}->{all} = {width => $width,
362 style => $style,
363 color => $color};
364 }
365
366 # border-width, border-style, border-color
367 0 for my $p (qw/width style color/) {
368 0 ▶ if ($value = $props_css->{"border-$p"}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($value = $$props_css{"border-$p"}) 0 0 0
369 0 $sides = $self->_by_sides($value);
370  
371 0 $propref->{border}->{all}->{$p} = $sides->{all};
372
373 0 for (SIDE_NAMES) {
374 0 ▶ $propref->{border}->{$_}->{$p} = $sides->{$_} || $sides->{all};
Condition0%0/3
$sides->{$_} || $sides->{'all'}
l!l&&r!l&&!r
000
MC/DC0%0/2
$sides->{$_} || $sides->{'all'}
$sides->{$_} $sides->{'all'}
Truth table0%0/3
A || B
A= $sides->{$_}B= $sides->{'all'}
ABresult
1X1
011
000
375 }
376 }
377 }
378
379 # border sides
380 0 for my $s (qw/top bottom left right/) {
381 0 ▶ if ($value = $props_css->{"border-$s"}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($value = $$props_css{"border-$s"}) 0 0 0
382 0 my ($width, $style, $color) = split(/\s+/, $value);
383  
384 0 $propref->{border}->{$s} = {width => $width,
385 style => $style,
386 color => $color};
387 }
388  
389 0 for my $p (qw/width style color/) {
390 0 ▶ if ($value = $props_css->{"border-$s-$p"}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($value = $$props_css{"border-$s-$p"}) 0 0 0
391 0 $propref->{border}->{$s}->{$p} = $value;
392 }
393 }
394 }
395  
396 # clear
397 0 ▶ if ($props_css->{clear}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($props_css->{'clear'}) { } 0 0 0
elsif (not $propref->{'clear'}) { } 0 0 0
398 0 $propref->{clear} = $props_css->{clear};
399 }
400 elsif (! $propref->{clear}) {
401 0 $propref->{clear} = 'none';
402 }
403
404 # color
405 0 ▶ if ($props_css->{color}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($props_css->{"color"}) 0 0 0
406 0 $propref->{color} = $props_css->{color};
407 }
408  
409 # display
410 0 ▶ if ($props_css->{display}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($props_css->{"display"}) 0 0 0
411 0 $propref->{display} = $props_css->{display};
412 }
413  
414 # float
415 0 ▶ if ($props_css->{float}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($props_css->{'float'}) { } 0 0 0
elsif (not $propref->{'float'}) { } 0 0 0
416 0 $propref->{float} = $props_css->{float};
417 }
418 elsif (! $propref->{float}) {
419 0 $propref->{float} = 'none';
420 }
421
422 # font
423 0 ▶ if ($props_css->{'font-size'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($props_css->{"font-size"}) 0 0 0
424 0 $propref->{font}->{size} = $props_css->{'font-size'};
425 }
426 0 ▶ if ($props_css->{'font-family'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($props_css->{"font-family"}) 0 0 0
427 0 $propref->{font}->{family} = ucfirst(lc($props_css->{'font-family'}));
428 }
429 0 ▶ if ($props_css->{'font-style'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($props_css->{"font-style"}) 0 0 0
430 0 $propref->{font}->{style} = ucfirst(lc($props_css->{'font-style'}));
431 }
432 0 ▶ if ($props_css->{'font-weight'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($props_css->{"font-weight"}) 0 0 0
433 0 $propref->{font}->{weight} = $props_css->{'font-weight'};
434 }
435  
436 # height
437 0 ▶ if ($props_css->{'height'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($props_css->{"height"}) 0 0 0
438 0 $propref->{height} = $props_css->{height};
439 }
440  
441 # min-height
442 0 ▶ if ($props_css->{'min-height'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($props_css->{"min-height"}) 0 0 0
443 0 $propref->{min_height} = $props_css->{'min-height'};
444 }
445
446 # line-height
447 0 ▶ if ($props_css->{'line-height'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($props_css->{"line-height"}) 0 0 0
448 0 $propref->{'line_height'} = $props_css->{'line-height'};
449 }
450  
451 # list-style
452 0 ▶ if ($props_css->{'list-style'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($props_css->{"list-style"}) 0 0 0
453 0 $propref->{'list_style'} = $props_css->{'list-style'};
454 }
455
456 # margin
457 0 ▶ if (exists $props_css->{'margin'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $props_css->{"margin"}) 0 0 0
458 0 $sides = $self->_by_sides($props_css->{'margin'});
459  
460 0 for (SIDE_NAMES) {
461 0 ▶ $propref->{margin}->{$_} = $sides->{$_} || $sides->{all};
Condition0%0/3
$sides->{$_} || $sides->{'all'}
l!l&&r!l&&!r
000
MC/DC0%0/2
$sides->{$_} || $sides->{'all'}
$sides->{$_} $sides->{'all'}
Truth table0%0/3
A || B
A= $sides->{$_}B= $sides->{'all'}
ABresult
1X1
011
000
462 }
463 }
464  
465 # margin sides
466 0 for (SIDE_NAMES) {
467 0 ▶ if (exists $props_css->{"margin-$_"}
Branch: 1 branch
BranchTrueFalseTotal
if (exists $$props_css{"margin-$_"} and $$props_css{"margin-$_"} =~ /\S/) 0 0 0
Condition0%0/3
exists $$props_css{"margin-$_"} and $$props_css{"margin-$_"} =~ /\S/
!ll&&!rl&&r
000
MC/DC0%0/2
exists $$props_css{"margin-$_"} and $$props_css{"margin-$_"} =~ /\S/
exists $$props_css{"margin-$_"} $$props_css{"margin-$_"} =~ /\S/
Truth table0%0/3
A and B
A= exists $$props_css{"margin-$_"}B= $$props_css{"margin-$_"} =~ /\S/
ABresult
0X0
100
111
468 && $props_css->{"margin-$_"} =~ /\S/) {
469 0 $propref->{margin}->{$_} = $props_css->{"margin-$_"};
470 }
471 }
472
473 # padding
474 0 ▶ if ($props_css->{'padding'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($props_css->{"padding"}) 0 0 0
475 0 $sides = $self->_by_sides($props_css->{'padding'});
476  
477 0 for (SIDE_NAMES) {
478 0 ▶ $propref->{padding}->{$_} = $sides->{$_} || $sides->{all};
Condition0%0/3
$sides->{$_} || $sides->{'all'}
l!l&&r!l&&!r
000
MC/DC0%0/2
$sides->{$_} || $sides->{'all'}
$sides->{$_} $sides->{'all'}
Truth table0%0/3
A || B
A= $sides->{$_}B= $sides->{'all'}
ABresult
1X1
011
000
479 }
480 }
481  
482 # padding sides
483 0 for (SIDE_NAMES) {
484 0 ▶ if (exists $props_css->{"padding-$_"}
Branch: 1 branch
BranchTrueFalseTotal
if (exists $$props_css{"padding-$_"} and $$props_css{"padding-$_"} =~ /\S/) 0 0 0
Condition0%0/3
exists $$props_css{"padding-$_"} and $$props_css{"padding-$_"} =~ /\S/
!ll&&!rl&&r
000
MC/DC0%0/2
exists $$props_css{"padding-$_"} and $$props_css{"padding-$_"} =~ /\S/
exists $$props_css{"padding-$_"} $$props_css{"padding-$_"} =~ /\S/
Truth table0%0/3
A and B
A= exists $$props_css{"padding-$_"}B= $$props_css{"padding-$_"} =~ /\S/
ABresult
0X0
100
111
485 && $props_css->{"padding-$_"} =~ /\S/) {
486 0 $propref->{padding}->{$_} = $props_css->{"padding-$_"};
487 }
488 }
489  
490 # text
491 0 ▶ if ($props_css->{'text-align'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($props_css->{"text-align"}) 0 0 0
492 0 $propref->{text}->{align} = $props_css->{'text-align'};
493 }
494 0 ▶ if ($props_css->{'text-decoration'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($props_css->{"text-decoration"}) 0 0 0
495 0 $propref->{text}->{decoration} = $props_css->{'text-decoration'};
496 }
497 0 ▶ if ($props_css->{'text-transform'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($props_css->{"text-transform"}) 0 0 0
498 0 $propref->{text}->{transform} = $props_css->{'text-transform'};
499 }
500
501 # transform
502 0 for (qw/transform -webkit-transform -moz-transform -o-transform -ms-transform/) {
503 0 my ($prop_value, @frags);
504  
505 0 ▶ if ($prop_value = $props_css->{$_}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($prop_value = $props_css->{$_}) 0 0 0
506 0 @frags = split(/\s+/, $prop_value);
507  
508 0 for my $value (@frags) {
509 0 ▶ if ($value =~ s/^\s*rotate\(((-?)\d+(\.\d+)?)\s*deg\)\s*$/$1/) {
Branch: 2 branches
BranchTrueFalseTotal
if ($value =~ s/^\s*rotate\(((-?)\d+(\.\d+)?)\s*deg\)\s*$/$1/) { } 0 0 0
elsif ($value =~ /translate([xy])?\((.*?)(,(.*?))?\)/i) { } 0 0 0
510 0 ▶ if ($2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($2) { } 0 0 0
511 # negative angle
512 0 $propref->{rotate} = 360 + $value;
513 }
514 else {
515 0 $propref->{rotate} = $value;
516 }
517 }
518 elsif ($value =~ /translate([xy])?\((.*?)(,(.*?))?\)/i) {
519 0 ▶ if (lc($1) eq 'x') {
Branch: 2 branches
BranchTrueFalseTotal
if (lc $1 eq 'x') { } 0 0 0
elsif (lc $1 eq 'y') { } 0 0 0
520 # translateX value
521 0 $propref->{translate}->{x} = $2;
522 }
523 elsif (lc($1) eq 'y') {
524 # translateY value
525 0 $propref->{translate}->{y} = $2;
526 }
527 else {
528 # translate value (x and optionally y)
529 0 $propref->{translate}->{x} = $2;
530
531 0 ▶ if ($4) {
Branch: 1 branch
BranchTrueFalseTotal
if ($4) 0 0 0
532 0 $propref->{translate}->{y} = $4;
533 }
534 }
535 }
536 }
537  
538 0 last;
539 }
540 }
541  
542 # vertical-align
543 0 ▶ if ($props_css->{'vertical-align'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($props_css->{"vertical-align"}) 0 0 0
544 0 $propref->{vertical_align} = $props_css->{'vertical-align'};
545 }
546  
547 # width
548 0 ▶ if ($props_css->{'width'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($props_css->{"width"}) 0 0 0
549 0 $propref->{width} = $props_css->{width};
550 }
551  
552 # min-width
553 0 ▶ if ($props_css->{'min-width'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($props_css->{"min-width"}) 0 0 0
554 0 $propref->{min_width} = $props_css->{'min-width'};
555 }
556
557 0 return $propref;
558 }
559  
560 0 ▶sub _expand_properties {
Subroutine _expand_properties: not called CC=4 SCAR=30.0
561 0 my ($self, $props) = @_;
562  
563 # border sides
564 0 for my $s (SIDE_NAMES) {
565 0 for my $p (qw/width style color/) {
566 0 ▶ next if exists $props->{border}->{$s}->{$p};
Branch: 1 branch
BranchTrueFalseTotal
if exists $props->{"border"}{$s}{$p} 0 0 0
567 0 $props->{border}->{$s}->{$p} = $props->{border}->{all}->{$p};
568 }
569 }
570 }
571  
572 0 ▶sub inherit {
Subroutine inherit: not called CC=4 SCAR=30.0
Pod documented
573 0 my ($self, $inherit) = @_;
574 0 my (%props);
575  
576 # font
577 0 ▶ if ($inherit->{font}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($inherit->{"font"}) 0 0 0
578 0 %{$props{font}} = %{$inherit->{font}};
579 }
580  
581 # line height
582 0 ▶ if ($inherit->{line_height}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($inherit->{"line_height"}) 0 0 0
583 0 $props{line_height} = $inherit->{line_height};
584 }
585  
586 # text
587 0 ▶ if ($inherit->{text}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($inherit->{"text"}) 0 0 0
588 0 $props{text} = $inherit->{text};
589 }
590
591 0 return \%props;
592 }
593  
594 # helper functions
595  
596 0 ▶sub _by_sides {
Subroutine _by_sides: not called CC=5 SCAR=34.0
597 0 my ($self, $value) = @_;
598 0 my (@specs, %sides);
599  
600 0 @specs = split(/\s+/, $value);
601  
602 0 ▶ if (@specs == 1) {
Branch: 4 branches
BranchTrueFalseTotal
if (@specs == 1) { } 0 0 0
elsif (@specs == 2) { } 0 0 0
elsif (@specs == 3) { } 0 0 0
elsif (@specs == 4) { } 0 0 0
603 # all sides
604 0 $sides{all} = $specs[0];
605 } elsif (@specs == 2) {
606 # top/bottom, left/right
607 0 $sides{top} = $sides{bottom} = $specs[0];
608 0 $sides{left} = $sides{right} = $specs[1];
609 } elsif (@specs == 3) {
610 # top, left/right, bottom
611 0 $sides{top} = $specs[0];
612 0 $sides{left} = $sides{right} = $specs[1];
613 0 $sides{bottom} = $specs[2];
614 } elsif (@specs == 4) {
615 # top, right, bottom, left
616 0 $sides{top} = $specs[0];
617 0 $sides{right} = $specs[1];
618 0 $sides{bottom} = $specs[2];
619 0 $sides{left} = $specs[3];
620 }
621  
622 0 return \%sides;
623  
624 }
625  
626 =head1 AUTHOR
627  
628 Stefan Hornburg (Racke), <racke@linuxia.de>
629  
630 =head1 BUGS
631  
632 Please report any bugs or feature requests to C<bug-template-flute-style-css at rt.cpan.org>, or through
633 the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Template-Flute-Style-CSS>.
634  
635 =head1 SUPPORT
636  
637 You can find documentation for this module with the perldoc command.
638  
639 perldoc Template::Flute::Style::CSS
640  
641 You can also look for information at:
642  
643 =over 4
644  
645 =item * RT: CPAN's request tracker
646  
647 L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Template-Flute-Style-CSS>
648  
649 =item * AnnoCPAN: Annotated CPAN documentation
650  
651 L<http://annocpan.org/dist/Template-Flute-Style-CSS>
652  
653 =item * CPAN Ratings
654  
655 L<http://cpanratings.perl.org/d/Template-Flute-Style-CSS>
656  
657 =item * Search CPAN
658  
659 L<http://search.cpan.org/dist/Template-Flute-Style-CSS/>
660  
661 =back
662  
663 =head1 LICENSE AND COPYRIGHT
664  
665 Copyright 2010-2012 Stefan Hornburg (Racke) <racke@linuxia.de>.
666  
667 This program is free software; you can redistribute it and/or modify it
668 under the terms of either: the GNU General Public License as published
669 by the Free Software Foundation; or the Artistic License.
670  
671 See http://dev.perl.org/licenses/ for more information.
672  
673 =cut
674  
675 2 1;
676  
↑ Summary