Coverage.pm

filter: Statementstmt 95.5% 64 / 67 Branchbran 66.6% 8 / 12 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 11 / 11 Podpod 100% 1 / 1 totaltotal 88.5% 85 / 96 CC 10 SCAR 10.2
CC
10
Cov
89%
_check_selector
5.0
_got_coverage_directive
3.5
_build_html_trees
3.0
CRAP 2.8
« Coverage/Deparse.pm ↑ Summary Coverage/Document.pm »
1 package CSS::Coverage;
2 {
3 4 $CSS::Coverage::VERSION = '0.04';
4 }
5 4 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 4 ▶use CSS::SAC;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 4 ▶use CSS::Coverage::Document;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 4 ▶use CSS::Coverage::XPath;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 4 ▶use CSS::Coverage::Report;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 4 ▶use HTML::TreeBuilder::XPath;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 4 with 'CSS::Coverage::DocumentDelegate';
13  
14 4 has css => (
15 is => 'ro',
16 isa => 'Str|ScalarRef',
17 required => 1,
18 );
19  
20 4 has documents => (
21 is => 'ro',
22 isa => 'ArrayRef[Str|ScalarRef]',
23 required => 1,
24 );
25  
26 4 has html_trees => (
27 is => 'ro',
28 isa => 'ArrayRef',
29 builder => '_build_html_trees',
30 lazy => 1,
31 );
32  
33 has _sac_document => (
34 is => 'ro',
35 isa => 'CSS::Coverage::Document',
36 7 ▶ default => sub { CSS::Coverage::Document->new(delegate => shift) },
Subroutine __ANON__: called CC=1 SCAR=0.0
37 4 lazy => 1,
38 );
39  
40 4 has _report => (
41 is => 'rw',
42 isa => 'CSS::Coverage::Report',
43 clearer => '_clear_report',
44 );
45  
46 4 has _ignore_next_rule => (
47 is => 'rw',
48 isa => 'Bool',
49 default => 0,
50 );
51  
52 7 ▶sub _build_html_trees {
Subroutine _build_html_trees: called CC=3 SCAR=11.1
53 7 my $self = shift;
54 7 my @trees;
55  
56 7 for my $document (@{ $self->documents }) {
57 7 my $tree = HTML::TreeBuilder::XPath->new;
58 7 $tree->ignore_unknown(0);
59  
60 7 ▶ if (ref($document)) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $document) { } 7 0 7
61 7 $tree->parse($$document);
62 7 $tree->eof;
63 }
64 else {
65 0 $tree->parse_file($document);
66 }
67  
68 7 push @trees, $tree;
69 }
70  
71 7 return \@trees;
72 }
73  
74 7 ▶sub check {
Subroutine check: called CC=2 SCAR=7.0
Pod documented
75 7 my $self = shift;
76  
77 7 my $sac = CSS::SAC->new({
78 DocumentHandler => $self->_sac_document,
79 });
80  
81 7 my $report = CSS::Coverage::Report->new;
82 7 $self->_report($report);
83  
84 7 my $css = $self->css;
85 7 ▶ if (ref($css)) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $css) { } 7 0 7
86 7 $sac->parse({ string => $$css });
87 }
88 else {
89 0 $sac->parse({ filename => $css });
90 }
91  
92 7 $self->_clear_report;
93  
94 7 return $report;
95 }
96  
97 # -- CSS::Coverage::DocumentDelegate
98  
99 99 ▶sub _check_selector {
Subroutine _check_selector: called CC=5 SCAR=16.2
100 99 my ($self, $selector) = @_;
101  
102 99 ▶ if ($self->_ignore_next_rule) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_ignore_next_rule) 2 97 99
103 2 $self->_ignore_next_rule(0);
104 2 return;
105 }
106  
107 97 my $xpath = CSS::Coverage::XPath->new($selector)->to_xpath;
108  
109 97 for my $tree (@{ $self->html_trees }) {
110 97 ▶ if ($tree->exists($xpath)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tree->exists($xpath)) 33 64 97
111 33 return;
112 }
113 }
114  
115 64 ▶ if ($self->_report) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_report) { } 64 0 64
116 64 $self->_report->add_unmatched_selector($selector);
117 }
118 else {
119 0 warn "This selector matches no documents: $selector\n";
120 }
121 }
122  
123 2 ▶sub _got_coverage_directive {
Subroutine _got_coverage_directive: called CC=3 SCAR=12.5
124 2 my ($self, $directive) = @_;
125  
126 2 ▶ if ($directive eq 'dynamic' || $directive eq 'ignore') {
Branch: 1 branch
BranchTrueFalseTotal
if ($directive eq "dynamic" or $directive eq "ignore") 2 0 2
Condition33%1/3
$directive eq "dynamic" or $directive eq "ignore"
l!l&&r!l&&!r
020
MC/DC0%0/2
$directive eq "dynamic" or $directive eq "ignore"
$directive eq "dynamic" $directive eq "ignore"
Truth table33%1/3
A or B
A= $directive eq "dynamic"B= $directive eq "ignore"
ABresult
1X1
011
000
127 2 $self->_ignore_next_rule(1);
128 }
129 }
130  
131 4 __PACKAGE__->meta->make_immutable;
132  
133 4 1;
134  
135 __END__
« Coverage/Deparse.pm ↑ Summary Coverage/Document.pm »