line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package CSS::Scopifier::Group;
|
2
|
1
|
|
|
1
|
|
685
|
use strict;
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
25
|
|
3
|
1
|
|
|
1
|
|
4
|
use warnings;
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
51
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
# ABSTRACT: Like CSS::Scopifier, but can handle rule groups
|
6
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
731
|
use Moo;
|
|
1
|
|
|
|
|
13284
|
|
|
1
|
|
|
|
|
6
|
|
8
|
1
|
|
|
1
|
|
2312
|
use Types::Standard qw(:all);
|
|
1
|
|
|
|
|
62918
|
|
|
1
|
|
|
|
|
9
|
|
9
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
51109
|
use CSS::Scopifier;
|
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
34
|
|
11
|
1
|
|
|
1
|
|
804
|
use Path::Class qw(file);
|
|
1
|
|
|
|
|
1685940
|
|
|
1
|
|
|
|
|
75
|
|
12
|
1
|
|
|
1
|
|
5187902
|
use Text::Balanced qw(extract_bracketed);
|
|
1
|
|
|
|
|
888768
|
|
|
1
|
|
|
|
|
770
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
has 'group_name', is => 'ro', isa => Maybe[Str], default => sub {undef};
|
15
|
|
|
|
|
|
|
has 'local', is => 'ro', isa => InstanceOf['CSS::Scopifier'], default => sub { CSS::Scopifier->new };
|
16
|
|
|
|
|
|
|
has '_members', is => 'ro', isa => ArrayRef, default => sub {[]};
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub scopify {
|
19
|
5
|
|
|
5
|
0
|
14
|
my $self = shift;
|
20
|
5
|
|
|
|
|
15
|
$_->scopify(@_) for ($self->local,@{$self->_members});
|
|
5
|
|
|
|
|
40
|
|
21
|
5
|
|
|
|
|
22
|
return 1;
|
22
|
|
|
|
|
|
|
}
|
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub write_string {
|
25
|
10
|
|
|
10
|
0
|
25
|
my $self = shift;
|
26
|
|
|
|
|
|
|
join("\n",
|
27
|
|
|
|
|
|
|
$self->local->write_string,
|
28
|
10
|
|
|
|
|
69
|
map { join('',$_->group_name," \{\n",$_->write_string,"\n\}\n") } @{$self->_members}
|
|
8
|
|
|
|
|
36
|
|
|
10
|
|
|
|
|
552
|
|
29
|
|
|
|
|
|
|
)
|
30
|
|
|
|
|
|
|
}
|
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub read {
|
33
|
1
|
|
|
1
|
0
|
408
|
my ($class, $file) = @_;
|
34
|
1
|
|
|
|
|
7
|
$class->read_string( scalar file($file)->resolve->slurp )
|
35
|
|
|
|
|
|
|
}
|
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub read_string {
|
39
|
5
|
100
|
|
5
|
0
|
1457
|
my $self = ref $_[0] ? shift : (shift)->new;
|
40
|
|
|
|
|
|
|
|
41
|
5
|
|
|
|
|
1510
|
my $string = shift;
|
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
# Flatten whitespace and remove /* comment */ style comments (copied from CSS::Tiny)
|
44
|
5
|
|
|
|
|
21
|
$string =~ tr/\n\t/ /;
|
45
|
5
|
|
|
|
|
26
|
$string =~ s!/\*.*?\*\/!!g;
|
46
|
|
|
|
|
|
|
|
47
|
5
|
|
|
|
|
11
|
my $local = '';
|
48
|
|
|
|
|
|
|
|
49
|
5
|
|
|
|
|
78
|
while($string) {
|
50
|
18
|
|
|
|
|
68
|
my ($extracted,$remainder,$skipped) = extract_bracketed( $string, '{}', '[^\{]*' );
|
51
|
|
|
|
|
|
|
|
52
|
18
|
|
|
|
|
6971
|
my ($pre,$inner) = ($skipped,$extracted);
|
53
|
18
|
100
|
|
|
|
58
|
if($pre) {
|
54
|
14
|
|
|
|
|
69
|
$pre =~ s/^\s+//;
|
55
|
14
|
|
|
|
|
78
|
$pre =~ s/\s+$//;
|
56
|
|
|
|
|
|
|
}
|
57
|
18
|
100
|
|
|
|
62
|
if($inner) {
|
58
|
14
|
|
|
|
|
63
|
$inner =~ s/^\{//;
|
59
|
14
|
|
|
|
|
105
|
$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
|
100
|
66
|
|
|
206
|
if($pre && $inner && $pre =~ /^\@/ && $inner =~ /\{/) {
|
|
|
|
100
|
|
|
|
|
|
|
|
66
|
|
|
|
|
65
|
4
|
|
|
|
|
6
|
push @{$self->_members}, (ref $self)
|
|
4
|
|
|
|
|
159
|
|
66
|
|
|
|
|
|
|
->new({ group_name => $pre })
|
67
|
|
|
|
|
|
|
->read_string($inner)
|
68
|
|
|
|
|
|
|
}
|
69
|
|
|
|
|
|
|
else {
|
70
|
14
|
|
100
|
|
|
171
|
$self->local->read_string( join('', $skipped||'', $extracted||'') )
|
|
|
|
100
|
|
|
|
|
71
|
|
|
|
|
|
|
}
|
72
|
|
|
|
|
|
|
|
73
|
18
|
|
|
|
|
56
|
$string = $remainder;
|
74
|
|
|
|
|
|
|
|
75
|
18
|
100
|
|
|
|
85
|
last unless ($extracted);
|
76
|
|
|
|
|
|
|
}
|
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
# Read in any leftover bits into the local/top-level object for god measure
|
79
|
5
|
100
|
|
|
|
31
|
$self->local->read_string($string) if ($string);
|
80
|
|
|
|
|
|
|
|
81
|
5
|
|
|
|
|
29
|
$self
|
82
|
|
|
|
|
|
|
}
|
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
### honor the origical CSS::Tiny API:
|
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
# Generate a HTML fragment for the CSS
|
88
|
|
|
|
|
|
|
sub html {
|
89
|
0
|
0
|
|
0
|
0
|
|
my $css = $_[0]->write_string or return '';
|
90
|
0
|
|
|
|
|
|
return "";
|
91
|
|
|
|
|
|
|
}
|
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
# Generate an xhtml fragment for the CSS
|
94
|
|
|
|
|
|
|
sub xhtml {
|
95
|
0
|
0
|
|
0
|
0
|
|
my $css = $_[0]->write_string or return '';
|
96
|
0
|
|
|
|
|
|
return "";
|
97
|
|
|
|
|
|
|
}
|
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
# Error handling
|
100
|
0
|
|
|
0
|
0
|
|
sub errstr { $CSS::Tiny::errstr }
|
101
|
0
|
|
|
0
|
|
|
sub _error { $CSS::Tiny::errstr = $_[1]; undef }
|
|
0
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
1;
|
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
__END__
|