| 1 | package CSS::Scopifier::Group; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | # ABSTRACT: Like CSS::Scopifier, but can handle rule groups | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 1 | ▶ | use Moo; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use Types::Standard qw(:all); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 1 | ▶ | use CSS::Scopifier; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 1 | ▶ | use Path::Class qw(file); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 1 | ▶ | use Text::Balanced qw(extract_bracketed); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 1 | ▶ | has 'group_name', is => 'ro', isa => Maybe[Str], default => sub {undef}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 5 | ▶ | has 'local', is => 'ro', isa => InstanceOf['CSS::Scopifier'], default => sub { CSS::Scopifier->new }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 5 | ▶ | has '_members', is => 'ro', isa => ArrayRef, default => sub {[]}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 5 | ▶ | sub scopify { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
scopify: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 5 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 5 | $_->scopify(@_) for ($self->local,@{$self->_members}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 5 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 10 | ▶ | sub write_string { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
write_string: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 10 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | join("\n", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | $self->local->write_string, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 10 | map { join('',$_->group_name," \{\n",$_->write_string,"\n\}\n") } @{$self->_members} | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 1 | ▶ | sub read { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
read: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 1 | my ($class, $file) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 1 | $class->read_string( scalar file($file)->resolve->slurp ) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 5 | ▶ | sub read_string { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
read_string: called CC=13 SCAR=25.7
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 5 | ▶ | my $self = ref $_[0] ? shift : (shift)->new; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 5 | my $string = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | # Flatten whitespace and remove /* comment */ style comments (copied from CSS::Tiny) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 5 | $string =~ tr/\n\t/ /; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 5 | $string =~ s!/\*.*?\*\/!!g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 5 | my $local = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 5 | ▶ | while($string) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 18 | my ($extracted,$remainder,$skipped) = extract_bracketed( $string, '{}', '[^\{]*' ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 18 | my ($pre,$inner) = ($skipped,$extracted); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 18 | ▶ | if($pre) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 14 | $pre =~ s/^\s+//; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 14 | $pre =~ s/\s+$//; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 18 | ▶ | if($inner) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 14 | $inner =~ s/^\{//; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 14 | $inner =~ s/\}$//; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | # we consider this to be a 'group' if it starts with '@' and contains | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | # additional curly brace(s) within (i.e. @media print { h1 { ... } }) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 18 | ▶ | if($pre && $inner && $pre =~ /^\@/ && $inner =~ /\{/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition77%7/9
$pre and $inner and $pre =~ /^\@/ and $inner =~ /\{/
$pre and $inner and $pre =~ /^\@/
$pre and $inner
MC/DC50%2/4
$pre and $inner and $pre =~ /^\@/ and $inner =~ /\{/
$pre
$inner
$pre =~ /^\@/
$inner =~ /\{/
Truth table60%3/5
A and B and C and D
A= $preB= $innerC= $pre =~ /^\@/D= $inner =~ /\{/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 4 | push @{$self->_members}, (ref $self) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | ->new({ group_name => $pre }) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | ->read_string($inner) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 14 | ▶ | $self->local->read_string( join('', $skipped||'', $extracted||'') ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%4/4
$skipped || ''
$extracted || ''
MC/DC100%1/1
$skipped || ''
$skipped
MC/DC100%1/1
$extracted || ''
$extracted
Truth table100%2/2
A
A= $skipped
Truth table100%2/2
A
A= $extracted
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 18 | $string = $remainder; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 18 | ▶ | last unless ($extracted); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | # Read in any leftover bits into the local/top-level object for god measure | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 5 | ▶ | $self->local->read_string($string) if ($string); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 5 | $self | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | ### honor the origical CSS::Tiny API: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | # Generate a HTML fragment for the CSS | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 0 | ▶ | sub html { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
html: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 0 | ▶ | my $css = $_[0]->write_string or return ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 0 | return "<style type=\"text/css\">\n<!--\n${css}-->\n</style>"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | # Generate an xhtml fragment for the CSS | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 0 | ▶ | sub xhtml { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
xhtml: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 0 | ▶ | my $css = $_[0]->write_string or return ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 0 | return "<style type=\"text/css\">\n/* <![CDATA[ */\n${css}/* ]]> */\n</style>"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | # Error handling | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 0 | ▶ | sub errstr { $CSS::Tiny::errstr } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
errstr: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 0 | ▶ | sub _error { $CSS::Tiny::errstr = $_[1]; undef } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_error: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 1 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||