Spell.pm

filter: Statementstmt 100% 85 / 85 Branchbran 92.8% 39 / 42 Conditioncond 71.4% 15 / 21 MC/DCmcdc 53.8% 7 / 13 Subroutinesub 100% 15 / 15 Podpod 100% 4 / 4 totaltotal 91.6% 165 / 180 CC 29 SCAR 20.6
CC
29
Cov
94%
_handle_text
14.5
_handle_element_end
10.0
new
3.0
CRAP 7.9
↑ Summary Wordlist.pm »
1 package Pod::Spell;
2 6 ▶use 5.008;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 6 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 6 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 6 our $VERSION = '1.27';
7  
8 16 ▶sub new {
Subroutine new: called CC=3 SCAR=11.0
Pod documented
9 16 my ( $class, %args ) = @_;
10  
11 16 my $no_wide_chars = delete $args{no_wide_chars};
12 16 ▶ my $debug = exists $args{debug} ? delete $args{debug} : $ENV{PERL_POD_SPELL_DEBUG};
Branch: 1 branch
BranchTrueFalseTotal
exists $args{'debug'} ? : 4 12 16
13  
14 16 ▶ my $stopwords = $args{stopwords} || do {
Condition33%1/3
$args{'stopwords'} || do { require Pod::Wordlist; 'Pod::Wordlist'->new('_is_debug', $debug, 'no_wide_chars', $no_wide_chars) }
l!l&&r!l&&!r
0160
MC/DC0%0/2
$args{'stopwords'} || do { require Pod::Wordlist; 'Pod::Wordlist'->new('_is_debug', $debug, 'no_wide_chars', $no_wide_chars) }
$args{'stopwords'} do { require Pod::Wordlist; 'Pod::Wordlist'->new('_is_debug', $debug, 'no_wide_chars', $no_wide_chars) }
Truth table33%1/3
A || B
A= $args{'stopwords'}B= do { require Pod::Wordlist; 'Pod::Wordlist'->new('_is_debug', $debug, 'no_wide_chars', $no_wide_chars) }
ABresult
1X1
011
000
15 16 require Pod::Wordlist;
16 16 Pod::Wordlist->new(
17 _is_debug => $debug,
18 no_wide_chars => $no_wide_chars
19 )
20 };
21  
22 16 my $parser = Pod::Spell::_Processor->new;
23 16 $parser->stopwords($stopwords);
24 16 $parser->_is_debug($debug);
25  
26 16 my %self = (
27 processor => $parser,
28 stopwords => $stopwords,
29 debug => $debug,
30 );
31  
32 16 bless \%self, $class
33 }
34  
35 2 ▶sub _is_debug { (shift)->{debug} ? 1 : 0; }
Subroutine _is_debug: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
+(shift())->{'debug'} ? : 1 1 2
36  
37 1 ▶sub stopwords { (shift)->{stopwords} }
Subroutine stopwords: called CC=1 SCAR=0.0
Pod documented
38  
39 14 ▶sub parse_from_file {
Subroutine parse_from_file: called CC=1 SCAR=0.0
Pod documented
40 14 my $self = shift;
41 14 $self->{processor}->parse_from_file(@_);
42 }
43  
44 14 ▶sub parse_from_filehandle {
Subroutine parse_from_filehandle: called CC=1 SCAR=0.0
Pod documented
45 14 my $self = shift;
46 14 $self->parse_from_file(@_);
47 }
48  
49 package # Hide from indexing
50 Pod::Spell::_Processor;
51 6 ▶use parent 'Pod::Simple';
Subroutine BEGIN: called CC=1 SCAR=0.0
52  
53 6 ▶use Text::Wrap ();
Subroutine BEGIN: called CC=1 SCAR=0.0
54  
55 6 __PACKAGE__->_accessorize(qw(
56 stopwords
57 _is_debug
58 ));
59  
60 16 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
61 16 my $class = shift;
62 16 my $self = $class->SUPER::new(@_);
63 16 $self->accept_targets('stopwords');
64 16 return $self;
65 }
66  
67 6 my %track_elements = (
68 for => 1,
69 Verbatim => 1,
70 L => 1,
71 C => 1,
72 F => 1,
73 );
74  
75 49 ▶sub output_fh {
Subroutine output_fh: called CC=2 SCAR=6.9
76 49 my $self = shift;
77 49 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 14 35 49
78 14 my ($fh) = @_;
79 14 my $encoded_fh = grep $_ eq 'utf8', PerlIO::get_layers(*$fh);
80 14 $self->{_encoded_fh} = $encoded_fh;
81 }
82 49 return $self->SUPER::output_fh(@_);
83 }
84  
85 88 ▶sub _handle_element_start {
Subroutine _handle_element_start: called CC=3 SCAR=11.0
86 88 my ($self, $element_name, $attr) = @_;
87 $self->{buffer} = ''
88 88 ▶ if !defined $self->{buffer};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"buffer"} 49 39 88
89  
90 88 ▶ if ($track_elements{$element_name}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($track_elements{$element_name}) 23 65 88
91 23 push @{ $self->{in_element} }, [ $element_name, $attr ];
92 }
93 }
94  
95 66 ▶sub _handle_text {
Subroutine _handle_text: called CC=14 SCAR=26.7
96 66 my ($self, $text) = @_;
97  
98 66 my $in = $self->{in_element};
99 66 ▶ if ($in && @$in) {
Branch: 1 branch
BranchTrueFalseTotal
if ($in and @$in) 24 42 66
Condition100%3/3
$in and @$in
!ll&&!rl&&r
24024
MC/DC100%2/2
$in and @$in
$in @$in
Truth table100%3/3
A and B
A= $inB= @$in
ABresult
0X0
100
111
100 24 my ($element_name, $attr) = @{$in->[-1]};
101 24 ▶ if ($element_name eq 'for' && $attr->{target_matching} eq 'stopwords') {
Branch: 4 branches
BranchTrueFalseTotal
if ($element_name eq 'for' and $attr->{'target_matching'} eq 'stopwords') { } 16 8 24
elsif ($element_name eq 'Verbatim') { } 1 7 8
elsif ($element_name eq 'L') { } 1 6 7
elsif ($element_name eq 'C' or $element_name eq 'F') { } 6 0 6
Condition66%2/3
$element_name eq "for" and $attr->{"target_matching"} eq "stopwords"
!ll&&!rl&&r
8016
MC/DC50%1/2
$element_name eq "for" and $attr->{"target_matching"} eq "stopwords"
$element_name eq "for" $attr->{"target_matching"} eq "stopwords"
Truth table66%2/3
A and B
A= $element_name eq "for"B= $attr->{"target_matching"} eq "stopwords"
ABresult
0X0
100
111
102 # this will match both for/begin and stopwords/:stopwords
103  
104 16 ▶ print "Stopword para: <$text>\n"
Branch: 1 branch
BranchTrueFalseTotal
if $self->_is_debug 4 12 16
105 if $self->_is_debug;
106 16 $self->stopwords->learn_stopwords($text);
107 16 return;
108 }
109 # totally ignore verbatim sections
110 elsif ($element_name eq 'Verbatim') {
111 1 return;
112 }
113 elsif ($element_name eq 'L') {
114 return
115 1 ▶ if $attr->{'content-implicit'};
Branch: 1 branch
BranchTrueFalseTotal
if $attr->{"content-implicit"} 1 0 1
116 }
117 ▶ elsif ($element_name eq 'C' || $element_name eq 'F') {
Condition33%1/3
$element_name eq "C" or $element_name eq "F"
l!l&&r!l&&!r
600
MC/DC0%0/2
$element_name eq "C" or $element_name eq "F"
$element_name eq "C" $element_name eq "F"
Truth table33%1/3
A or B
A= $element_name eq "C"B= $element_name eq "F"
ABresult
1X1
011
000
118 # maintain word boundaries
119 6 ▶ my $pre = $text =~ s{\A\s+}{} ? ' ' : '';
Branch: 1 branch
BranchTrueFalseTotal
$text =~ s/\A\s+// ? : 2 4 6
120 6 ▶ my $post = $text =~ s{\s+\z}{} ? ' ' : '';
Branch: 1 branch
BranchTrueFalseTotal
$text =~ s/\s+\z// ? : 2 4 6
121 # if _ is joined with text before or after, it will be treated as
122 # a Perl token and the entire word ignored
123 6 ▶ $text = $pre . (length $text ? '_' : '') . $post;
Branch: 1 branch
BranchTrueFalseTotal
length $text ? : 6 0 6
124 }
125 }
126  
127 48 $self->{buffer} .= $text;
128 }
129  
130 88 ▶sub _handle_element_end {
Subroutine _handle_element_end: called CC=10 SCAR=23.0
131 88 my ($self, $element_name) = @_;
132  
133 88 my $in = $self->{in_element};
134 88 ▶ if ($in && @$in && $in->[-1][0] eq $element_name) {
Branch: 1 branch
BranchTrueFalseTotal
if ($in and @$in and $in->[-1][0] eq $element_name) 23 65 88
Condition100%6/6
$in and @$in and $in->[-1][0] eq $element_name
!ll&&!rl&&r
491623
$in and @$in
!ll&&!rl&&r
24739
MC/DC100%3/3
$in and @$in and $in->[-1][0] eq $element_name
$in @$in $in->[-1][0] eq $element_name
Truth table100%4/4
A and B and C
A= $inB= @$inC= $in->[-1][0] eq $element_name
ABCresult
0XX0
10X0
1100
1111
135 23 pop @$in;
136 }
137  
138 return
139 88 ▶ if $element_name !~ m{\A(?:Para|head\d|item-.*|over-block)\z};
Branch: 1 branch
BranchTrueFalseTotal
unless $element_name =~ /\A(?:Para|head\d|item-.*|over-block)\z/ 40 48 88
140  
141 48 my $buffer = delete $self->{buffer};
142 48 ▶ if (!defined $buffer || !length $buffer) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $buffer and length $buffer) 13 35 48
Condition66%2/3
defined $buffer and length $buffer
!ll&&!rl&&r
01335
MC/DC50%1/2
defined $buffer and length $buffer
defined $buffer length $buffer
Truth table66%2/3
A and B
A= defined $bufferB= length $buffer
ABresult
0X0
100
111
143 13 return;
144 }
145  
146 35 my $fh = $self->output_fh;
147  
148 35 my $out = $self->stopwords->strip_stopwords($buffer);
149  
150 # maintain exact output of older Pod::Parser based implementation
151 35 ▶ print { $fh } "\n"
Branch: 1 branch
BranchTrueFalseTotal
if $element_name ne "Para" 14 21 35
152 if $element_name ne 'Para';
153  
154 return
155 35 ▶ if !length $out;
Branch: 1 branch
BranchTrueFalseTotal
unless length $out 3 32 35
156  
157 32 local $Text::Wrap::huge = 'overflow';
158 32 my $wrapped = Text::Wrap::wrap( '', '', $out ) . "\n\n";
159  
160 32 ▶ if ($self->{_encoded_fh}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'_encoded_fh'}) { } 16 16 32
161 16 print { $fh } $wrapped;
162 }
163 else {
164 16 print { $fh } Encode::encode('UTF-8', $wrapped);
165 }
166 }
167  
168 6 1;
169  
170 __END__
↑ Summary Wordlist.pm »