blib/lib/App/Perldoc/Search/_Parser.pm

filter: Statementstmt 48.5% 17 / 35 Branchbran 0.0% 0 / 14 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 66.6% 6 / 9 Podpod 0.0% 0 / 3 totaltotal 32.3% 23 / 71 CC 10 SCAR 27.2
CC
10
Cov
31%
textblock
30.0
command
20.0
verbatim
12.0
CRAP 15.1
↑ Summary blib/lib/App/Perldoc/Search.pm »
1 package App::Perldoc::Search::_Parser;
2 3 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
3 3 $App::Perldoc::Search::_Parser::VERSION = '0.11';
4 }
5  
6 =head1 NAME
7  
8 App::Perldoc::Search::_Parser - Pod parser for extracting NAME and searching for matchs
9  
10 =head1 VERSION
11  
12 version 0.11
13  
14 =head1 SYNOPSIS
15  
16 my $parser = App::Perldoc::Search::_Parser->new;
17 $parser->{pattern} = qr/thing_to_search_for/;
18 $parser->parse_from_filehandle( $fh );
19  
20 if ( $parser->{matched} ) {
21 print "$parser->{name}\n";
22 }
23  
24 =head1 DESCRIPTION
25  
26 Parses pod to extract the NAME and also search for a pattern match.
27  
28 =head1 ATTRIBUTES
29  
30 =over
31  
32 =item pattern
33  
34 Set this to a regular expression prior to parsing. This is the pattern being searched for.
35  
36 =item matched
37  
38 A boolean returned which tells whether the pattern matched.
39  
40 =item name
41  
42 The extracted name and description
43  
44 =back
45  
46 =cut
47  
48  
49  
50 3 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
51 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
52 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
53 3 ▶no warnings 'uninitialized';
Subroutine BEGIN: called CC=1 SCAR=0.0
54 3 ▶use Pod::Parser ();
Subroutine BEGIN: called CC=1 SCAR=0.0
55 3 our @ISA = 'Pod::Parser';
56  
57  
58 =head1 METHODS
59  
60 =head2 command
61  
62 Checks for =head NAME commands and searches for the pattern.
63  
64 =cut
65  
66 0 ▶sub command {
Subroutine command: not called CC=4 SCAR=30.0
Pod undocumented
67 0 my ( $self, $cmd, $text, $line_num, $pod_para ) = @_;
68  
69 # Check for "=head1 NAME"
70 $self->{expect_name} =
71 0 ▶ $cmd =~ /^head\d+$/
Condition0%0/3
$cmd =~ /^head\d+$/ && $text =~ /^\s*NAME\b/
!ll&&!rl&&r
000
MC/DC0%0/2
$cmd =~ /^head\d+$/ && $text =~ /^\s*NAME\b/
$cmd =~ /^head\d+$/ $text =~ /^\s*NAME\b/
Truth table0%0/3
A && B
A= $cmd =~ /^head\d+$/B= $text =~ /^\s*NAME\b/
ABresult
0X0
100
111
72 && $text =~ /^\s*NAME\b/;
73  
74 # Check our pattern.
75 0 ▶ if ( length $self->{pattern} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $self->{"pattern"}) 0 0 0
76 0 ▶ ++$self->{matched} while $text =~ /$self->{pattern}/g;
Branch: 1 branch
BranchTrueFalseTotal
$text =~ /$self->{"pattern"}/g and do { ++$self->{"matched"} } 0 0 0
77 }
78  
79 0 return;
80 }
81  
82  
83  
84 =head2 verbatim
85  
86 Searches for the pattern.
87  
88 =cut
89  
90 0 ▶sub verbatim {
Subroutine verbatim: not called CC=3 SCAR=24.8
Pod undocumented
91 0 my ( $self, $text ) = @_;
92  
93 # Check our pattern.
94 0 ▶ if ( length $self->{pattern} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $self->{"pattern"}) 0 0 0
95 0 ▶ ++ $self->{matched} while $text =~ /$self->{pattern}/g;
Branch: 1 branch
BranchTrueFalseTotal
$text =~ /$self->{"pattern"}/g and do { ++$self->{"matched"} } 0 0 0
96 }
97  
98 0 return;
99 }
100  
101  
102  
103  
104 =head2 textblock
105  
106 Searches for the pattern. Extracts the name if a =head command was just encountered
107  
108 =cut
109  
110 0 ▶sub textblock {
Subroutine textblock: not called CC=5 SCAR=34.0
Pod undocumented
111 0 my ( $self, $text, $line_num ) = @_;
112  
113 # Check our pattern.
114 0 ▶ if ( length $self->{pattern} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $self->{"pattern"}) 0 0 0
115 0 ▶ ++$self->{matched} while $text =~ /$self->{pattern}/g;
Branch: 1 branch
BranchTrueFalseTotal
$text =~ /$self->{"pattern"}/g and do { ++$self->{"matched"} } 0 0 0
116 }
117  
118 # If we recently found "=head1 NAME" then look for a name.
119 0 ▶ if ( $self->{expect_name} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"expect_name"}) 0 0 0
120 0 $self->{expect_name} = 0;
121  
122 0 $text =~ s/^\s+//;
123 0 $text =~ s/\s+$//;
124 0 ▶ $self->{name} ||= $text;
Condition0%0/3
$self->{"name"} ||= $text
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"name"} ||= $text
$self->{"name"} $text
Truth table0%0/3
A ||= B
A= $self->{"name"}B= $text
ABresult
1X1
011
000
125 }
126  
127 0 return;
128 }
129  
130  
131  
132 3 q(Soviet Jesus's gift at Christmas of a blow-up doll to Debbie would always turn to be the most enigmatic);
↑ Summary blib/lib/App/Perldoc/Search.pm »