| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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)
}
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)
}
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||||||||||
| 90 | 88 | ▶ | if ($track_elements{$element_name}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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
Condition100%3/3
$in and @$in
MC/DC100%2/2
$in and @$in
$in
@$in
Truth table100%3/3
A and B
A= $inB= @$in
| |||||||||||||||||||||||||||||||||||||||||||
| 100 | 24 | my ($element_name, $attr) = @{$in->[-1]}; | |||||||||||||||||||||||||||||||||||||||||
| 101 | 24 | ▶ | if ($element_name eq 'for' && $attr->{target_matching} eq 'stopwords') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
Condition66%2/3
$element_name eq "for" and $attr->{"target_matching"} eq "stopwords"
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"
| |||||||||||||||||||||||||||||||||||||||||||
| 102 | # this will match both for/begin and stopwords/:stopwords | ||||||||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||||||||
| 104 | 16 | ▶ | print "Stopword para: <$text>\n" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 116 | } | ||||||||||||||||||||||||||||||||||||||||||
| 117 | ▶ | elsif ($element_name eq 'C' || $element_name eq 'F') { | |||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$element_name eq "C" or $element_name eq "F"
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"
| |||||||||||||||||||||||||||||||||||||||||||
| 118 | # maintain word boundaries | ||||||||||||||||||||||||||||||||||||||||||
| 119 | 6 | ▶ | my $pre = $text =~ s{\A\s+}{} ? ' ' : ''; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 120 | 6 | ▶ | my $post = $text =~ s{\s+\z}{} ? ' ' : ''; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
Condition100%6/6
$in and @$in and $in->[-1][0] eq $element_name
$in and @$in
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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||||||||||||||||
| 141 | 48 | my $buffer = delete $self->{buffer}; | |||||||||||||||||||||||||||||||||||||||||
| 142 | 48 | ▶ | if (!defined $buffer || !length $buffer) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $buffer and length $buffer
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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 152 | if $element_name ne 'Para'; | ||||||||||||||||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||||||||||||||||
| 154 | return | ||||||||||||||||||||||||||||||||||||||||||
| 155 | 35 | ▶ | if !length $out; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||||||||||||||||