| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 111 | 33 | return; | |||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||
| 115 | 64 | ▶ | if ($self->_report) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
Condition33%1/3
$directive eq "dynamic" or $directive eq "ignore"
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"
| |||||||||||||||||||||||||||||
| 127 | 2 | $self->_ignore_next_rule(1); | |||||||||||||||||||||||||||
| 128 | } | ||||||||||||||||||||||||||||
| 129 | } | ||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||
| 131 | 4 | __PACKAGE__->meta->make_immutable; | |||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||
| 133 | 4 | 1; | |||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||
| 135 | __END__ | ||||||||||||||||||||||||||||