| 1 | package CSS::Parse::Packed; | ||||||||||||
| 2 | |||||||||||||
| 3 | 3 | ▶ | use warnings; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 4 | 3 | ▶ | use strict; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 5 | |||||||||||||
| 6 | 3 | our $VERSION = '0.06'; | |||||||||||
| 7 | |||||||||||||
| 8 | 3 | ▶ | use base qw/CSS::Parse/; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 9 | 3 | ▶ | use Carp; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 10 | 3 | ▶ | use CSS::Style; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 11 | 3 | ▶ | use CSS::Selector; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 12 | 3 | ▶ | use CSS::Property; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 13 | |||||||||||||
| 14 | sub parse_string { | ||||||||||||
| 15 | 6 | ▶ | my $self = shift; | ||||||||||
|
Subroutine
parse_string: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||
| 16 | 6 | my $string = shift; | |||||||||||
| 17 | |||||||||||||
| 18 | 6 | $string =~ s{\r\n|\r|\n}{ }g; | |||||||||||
| 19 | 6 | $string =~ s{(?:\@[\S\s]*?;)}{}g; | |||||||||||
| 20 | 6 | $self->_parse_string($string); | |||||||||||
| 21 | 6 | $self->_create_styles; | |||||||||||
| 22 | } | ||||||||||||
| 23 | |||||||||||||
| 24 | sub _parse_string { | ||||||||||||
| 25 | 6 | ▶ | my $self = shift; | ||||||||||
|
Subroutine
_parse_string: called CC=6 SCAR=17.9
| |||||||||||||
| 26 | 6 | my $string = shift; | |||||||||||
| 27 | |||||||||||||
| 28 | 6 | for my $str (grep { /\S/ } split /(?<=\})/, $string) { | |||||||||||
| 29 | 11 | ▶ | my ($selectors, $properties) = $str =~ m/^\s*([^{]+?)\s*\{(.*)\}\s*$/ | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 30 | or carp "Invalid style data '$str'", next; | ||||||||||||
| 31 | |||||||||||||
| 32 | 11 | my @selectors = split /\s*,\s*/, $selectors; | |||||||||||
| 33 | 11 | for my $property (grep { /\S/ } split /\;/, $properties) { | |||||||||||
| 34 | 13 | ▶ | my ($name, $val) = $property =~ m/^\s*([\w._-]+)\s*:\s*(.*?)\s*$/ | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 35 | or carp "Invalid property '$property'", next; | ||||||||||||
| 36 | 12 | for my $selector (@selectors) { | |||||||||||
| 37 | 12 | $self->stash->{$selector}->{$name} = $val; | |||||||||||
| 38 | } | ||||||||||||
| 39 | } | ||||||||||||
| 40 | } | ||||||||||||
| 41 | } | ||||||||||||
| 42 | |||||||||||||
| 43 | sub _create_styles { | ||||||||||||
| 44 | 6 | ▶ | my $self = shift; | ||||||||||
|
Subroutine
_create_styles: called CC=3 SCAR=11.0
| |||||||||||||
| 45 | |||||||||||||
| 46 | 6 | my @styles; | |||||||||||
| 47 | 6 | for my $selector (keys %{$self->stash}) { | |||||||||||
| 48 | 6 | my $s = CSS::Style->new({ adaptor => $self->{parent}->{adaptor} }); | |||||||||||
| 49 | 6 | $s->add_selector(CSS::Selector->new({ name => $selector })); | |||||||||||
| 50 | 6 | ▶ | while (my ($name, $val) = each %{ $self->stash->{$selector} }) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 51 | my $property = CSS::Property->new({ | ||||||||||||
| 52 | property => $name, | ||||||||||||
| 53 | value => $val, | ||||||||||||
| 54 | adaptor => $s->{adaptor}, | ||||||||||||
| 55 | 11 | }); | |||||||||||
| 56 | 11 | $s->add_property($property); | |||||||||||
| 57 | } | ||||||||||||
| 58 | 6 | push @styles, $s; | |||||||||||
| 59 | } | ||||||||||||
| 60 | |||||||||||||
| 61 | 6 | $self->{parent}->{styles} = \@styles; | |||||||||||
| 62 | } | ||||||||||||
| 63 | |||||||||||||
| 64 | sub stash { | ||||||||||||
| 65 | 35 | ▶ | $_[0]->{parent}->{__PACKAGE__."::stash"} ||= {}; | ||||||||||
|
Subroutine
stash: called CC=2 SCAR=6.9
Pod
undocumented
Condition100%2/2
$_[0]{"parent"}{"CSS::Parse::Packed::stash"} ||= {}
MC/DC100%1/1
$_[0]{"parent"}{"CSS::Parse::Packed::stash"} ||= {}
$_[0]{"parent"}{"CSS::Parse::Packed::stash"}
Truth table100%2/2
A
A= $_[0]{"parent"}{"CSS::Parse::Packed::stash"}
| |||||||||||||
| 66 | } | ||||||||||||
| 67 | |||||||||||||
| 68 | 3 | 1; | |||||||||||
| 69 | __END__ | ||||||||||||