blib/lib/Pandoc/Selector.pm

filter: Statementstmt 97.5% 39 / 40 Branchbran 95.8% 23 / 24 Conditioncond 100% 3 / 3 MC/DCmcdc 100% 2 / 2 Subroutinesub 100% 8 / 8 Podpod 0.0% 0 / 2 totaltotal 94.9% 75 / 79 SCAR 27.1
CC
15
Cov
97%
_match_expression
8.0
_match_attributes
6.0
match
3.0
CRAP 15.0
« blib/lib/Pandoc/Walker.pm ↑ Summary blib/lib/Pandoc/Filter/HeaderIdentifiers.pm »
1 package Pandoc::Selector;
2 31 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 31 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 31 ▶use 5.010001;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 31 ▶use Pandoc::Elements;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 31 my $IDENTIFIER = qr{[\p{L}\p{N}_-]+};
9 31 my $NAME = qr{[A-Za-z]+};
10  
11 sub new {
12 173 ▶ my ($class, $selector) = @_;
Subroutine new: called CC=1 SCAR=0.0
Pod undocumented
13 # TODO: compile selector
14 173 bless { selector => $selector }, $class;
15 }
16  
17 sub match {
18 173 ▶ my ($self, $element) = @_;
Subroutine match: called CC=3 SCAR=11.0
Pod undocumented
19  
20 173 foreach my $selector ( split /\|/, $self->{selector} ) {
21 340 ▶ return 1 if _match_expression($selector, $element);
Branch: 1 branch
BranchTrueFalseTotal
if _match_expression($selector, $element) 83 257 340
22 }
23  
24 90 return 0;
25 }
26  
27 sub _match_expression {
28 340 ▶ my ( $selector, $elem ) = @_;
Subroutine _match_expression: called CC=8 SCAR=20.8
29 340 $selector =~ s/^\s+|\s+$//g;
30  
31 # name
32 340 ▶ return 0
Branch: 1 branch
BranchTrueFalseTotal
if $selector =~ s/^($NAME)\s*//i and lc $1 ne lc $elem->name 250 90 340
Condition100%3/3
$selector =~ s/^($NAME)\s*//i and lc $1 ne lc $elem->name
!ll&&!rl&&r
1575250
MC/DC100%2/2
$selector =~ s/^($NAME)\s*//i and lc $1 ne lc $elem->name
$selector =~ s/^($NAME)\s*//i lc $1 ne lc $elem->name
Truth table100%3/3
A and B
A= $selector =~ s/^($NAME)\s*//iB= lc $1 ne lc $elem->name
ABresult
0X0
100
111
33 if $selector =~ s/^($NAME)\s*//i and lc($1) ne lc( $elem->name );
34 90 ▶ return 1 if $selector eq '';
Branch: 1 branch
BranchTrueFalseTotal
if $selector eq "" 73 17 90
35  
36 # type
37 17 ▶ if ( $selector =~ s/^:(document|block|inline|meta)\s*// ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($selector =~ s/^:(document|block|inline|meta)\s*//) 6 11 17
38 6 my $method = "is_$1";
39 6 ▶ return 0 unless $elem->$method;
Branch: 1 branch
BranchTrueFalseTotal
unless $elem->$method 2 4 6
40 4 ▶ return 1 if $selector eq '';
Branch: 1 branch
BranchTrueFalseTotal
if $selector eq "" 3 1 4
41 }
42  
43 # TODO: :method (e.g. :url)
44  
45 # TODO: [:level=1]
46  
47 # TODO [<number>]
48  
49 # TODO [@<attr>]
50  
51 # id and/or classes
52 12 ▶ return 0 unless $elem->isa('Pandoc::Document::AttributesRole');
Branch: 1 branch
BranchTrueFalseTotal
unless $elem->isa("Pandoc::Document::AttributesRole") 1 11 12
53 11 return _match_attributes($selector, $elem);
54 }
55  
56 # check #id and .class
57 sub _match_attributes {
58 11 ▶ my ( $selector, $elem ) = @_;
Subroutine _match_attributes: called CC=6 SCAR=18.0
59  
60 11 $selector =~ s/^\s+|\s+$//g; # trim
61  
62 11 ▶ while ( $selector ne '' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($selector ne "") 14 7 21
63 14 ▶ if ( $selector =~ s/^#($IDENTIFIER)\s*// ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($selector =~ s/^#($IDENTIFIER)\s*//) { } 4 10 14
elsif ($selector =~ s/^\.($IDENTIFIER)\s*//) { } 10 0 10
64 4 ▶ return 0 unless $elem->id eq $1;
Branch: 1 branch
BranchTrueFalseTotal
unless $elem->id eq $1 2 2 4
65 }
66 elsif ( $selector =~ s/^\.($IDENTIFIER)\s*// ) {
67 10 ▶ return 0 unless grep { $1 eq $_ } @{ $elem->attr->[1] };
Branch: 1 branch
BranchTrueFalseTotal
unless grep {$1 eq $_;} @{$elem->attr->[1];} 2 8 10
68 }
69 else {
70 0 return 0;
71 }
72 }
73  
74 7 return 1;
75 }
76  
77 31 1;
78 __END__
« blib/lib/Pandoc/Walker.pm ↑ Summary blib/lib/Pandoc/Filter/HeaderIdentifiers.pm »