| 1 | package Pod::Simple::Words; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use 5.026; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use experimental qw( signatures ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 1 | ▶ | use JSON::MaybeXS qw( encode_json ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use Text::HumanComputerWords 0.02; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 1 | ▶ | use PPI; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 1 | ▶ | use URI; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 1 | ▶ | use base qw( Pod::Simple ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | # ABSTRACT: Parse words and locations from a POD document | ||||||||||||||||||||||||||||
| 14 | 1 | our $VERSION = '0.07'; # VERSION | |||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | 1 | __PACKAGE__->_accessorize( | |||||||||||||||||||||||||||
| 18 | qw( line_number in_verbatim in_head1 callback target head1 skip_section_hash link_address in_section_title splitter ), | ||||||||||||||||||||||||||||
| 19 | ); | ||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | 17 | ▶ | sub new ($class) | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||
| 23 | { | ||||||||||||||||||||||||||||
| 24 | 17 | my $self = $class->SUPER::new; | |||||||||||||||||||||||||||
| 25 | 17 | $self->preserve_whitespace(1); | |||||||||||||||||||||||||||
| 26 | 17 | $self->in_verbatim(0); | |||||||||||||||||||||||||||
| 27 | 17 | $self->in_head1(0); | |||||||||||||||||||||||||||
| 28 | 17 | $self->in_section_title(0); | |||||||||||||||||||||||||||
| 29 | 17 | $self->head1(''); | |||||||||||||||||||||||||||
| 30 | 17 | $self->no_errata_section(1); | |||||||||||||||||||||||||||
| 31 | 17 | $self->accept_targets( qw( stopwords )); | |||||||||||||||||||||||||||
| 32 | 17 | $self->target(undef); | |||||||||||||||||||||||||||
| 33 | 17 | $self->skip_section_hash({}); | |||||||||||||||||||||||||||
| 34 | 17 | ▶ | if(! defined $self->splitter) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 35 | { | ||||||||||||||||||||||||||||
| 36 | 17 | $self->splitter( | |||||||||||||||||||||||||||
| 37 | Text::HumanComputerWords->new( | ||||||||||||||||||||||||||||
| 38 | Text::HumanComputerWords->default_perl, | ||||||||||||||||||||||||||||
| 39 | ), | ||||||||||||||||||||||||||||
| 40 | ); | ||||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||
| 42 | 0 | ▶ | $self->callback(sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 43 | 0 | my $row = encode_json \@_; | |||||||||||||||||||||||||||
| 44 | 0 | print "--- $row\n"; | |||||||||||||||||||||||||||
| 45 | 17 | }); | |||||||||||||||||||||||||||
| 46 | 17 | $self; | |||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | 1 | ▶ | sub skip_sections ($self, @sections) | ||||||||||||||||||||||||||
|
Subroutine
skip_sections: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 51 | { | ||||||||||||||||||||||||||||
| 52 | 1 | $self->skip_section_hash->{lc $_} = 1 for @sections; | |||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | 103 | ▶ | sub _handle_element_start ($self, $tagname, $attrhash, @) | ||||||||||||||||||||||||||
|
Subroutine
_handle_element_start: called CC=11 SCAR=24.0
| |||||||||||||||||||||||||||||
| 56 | { | ||||||||||||||||||||||||||||
| 57 | 103 | ▶ | $self->line_number($attrhash->{start_line}) if defined $attrhash->{start_line}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | 103 | ▶ | if($tagname eq 'L') | ||||||||||||||||||||||||||
|
Branch: 5 branches
| |||||||||||||||||||||||||||||
| 60 | { | ||||||||||||||||||||||||||||
| 61 | 9 | my @row = ( $attrhash->{type} . "_link", $self->source_filename, $self->line_number, [undef, undef] ); | |||||||||||||||||||||||||||
| 62 | 9 | ▶ | if($attrhash->{type} eq 'url') | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 63 | { | ||||||||||||||||||||||||||||
| 64 | 3 | my $url = URI->new($attrhash->{to}); | |||||||||||||||||||||||||||
| 65 | 3 | ▶ | if(defined $url->fragment) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 66 | { | ||||||||||||||||||||||||||||
| 67 | 1 | $row[3]->[1] = $url->fragment; | |||||||||||||||||||||||||||
| 68 | 1 | $url->fragment(undef); | |||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||
| 70 | 3 | $row[3]->[0] = "$url"; | |||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||
| 72 | else | ||||||||||||||||||||||||||||
| 73 | { | ||||||||||||||||||||||||||||
| 74 | 6 | ▶ | $row[3]->[0] = $attrhash->{to} . '' if defined $attrhash->{to}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 75 | 6 | ▶ | $row[3]->[1] = $attrhash->{section} . '' if defined $attrhash->{section}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||
| 77 | 9 | $self->callback->(@row); | |||||||||||||||||||||||||||
| 78 | 9 | $self->link_address($attrhash->{to}); | |||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||
| 80 | elsif($tagname eq 'for') | ||||||||||||||||||||||||||||
| 81 | { | ||||||||||||||||||||||||||||
| 82 | 2 | $self->target($attrhash->{target}); | |||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||
| 84 | elsif($tagname eq 'Verbatim') | ||||||||||||||||||||||||||||
| 85 | { | ||||||||||||||||||||||||||||
| 86 | 3 | $self->in_verbatim($self->in_verbatim+1); | |||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||
| 88 | elsif($tagname eq 'head1') | ||||||||||||||||||||||||||||
| 89 | { | ||||||||||||||||||||||||||||
| 90 | 19 | $self->in_head1($self->in_head1+1); | |||||||||||||||||||||||||||
| 91 | 19 | $self->head1(''); | |||||||||||||||||||||||||||
| 92 | 19 | $self->in_section_title(1); | |||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||
| 94 | elsif($tagname =~ /^head[0-9]+$/) | ||||||||||||||||||||||||||||
| 95 | { | ||||||||||||||||||||||||||||
| 96 | 3 | $self->in_section_title(1); | |||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||
| 98 | 103 | (); | |||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | 103 | ▶ | sub _handle_element_end ($self, $tagname, @) | ||||||||||||||||||||||||||
|
Subroutine
_handle_element_end: called CC=6 SCAR=17.9
| |||||||||||||||||||||||||||||
| 102 | { | ||||||||||||||||||||||||||||
| 103 | 103 | ▶ | if($tagname eq 'Verbatim') | ||||||||||||||||||||||||||
|
Branch: 5 branches
| |||||||||||||||||||||||||||||
| 104 | { | ||||||||||||||||||||||||||||
| 105 | 3 | $self->in_verbatim($self->in_verbatim-1); | |||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||
| 107 | elsif($tagname eq 'head1') | ||||||||||||||||||||||||||||
| 108 | { | ||||||||||||||||||||||||||||
| 109 | 19 | $self->in_head1($self->in_head1-1); | |||||||||||||||||||||||||||
| 110 | 19 | $self->in_section_title(0); | |||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||
| 112 | elsif($tagname =~ /^head[0-9]+$/) | ||||||||||||||||||||||||||||
| 113 | { | ||||||||||||||||||||||||||||
| 114 | 3 | $self->in_section_title(0); | |||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||
| 116 | elsif($tagname eq 'for') | ||||||||||||||||||||||||||||
| 117 | { | ||||||||||||||||||||||||||||
| 118 | 2 | $self->target(undef); | |||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||
| 120 | elsif($tagname eq 'L') | ||||||||||||||||||||||||||||
| 121 | { | ||||||||||||||||||||||||||||
| 122 | 9 | $self->link_address(undef); | |||||||||||||||||||||||||||
| 123 | } | ||||||||||||||||||||||||||||
| 124 | } | ||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||
| 126 | 63 | ▶ | sub _add_words ($self, $line) | ||||||||||||||||||||||||||
|
Subroutine
_add_words: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 127 | { | ||||||||||||||||||||||||||||
| 128 | 63 | foreach my $event ($self->splitter->split($line)) | |||||||||||||||||||||||||||
| 129 | { | ||||||||||||||||||||||||||||
| 130 | 99 | my($type, $word) = @$event; | |||||||||||||||||||||||||||
| 131 | 99 | my @row = ( $type, $self->source_filename, $self->line_number, $word ); | |||||||||||||||||||||||||||
| 132 | 99 | $self->callback->(@row); | |||||||||||||||||||||||||||
| 133 | } | ||||||||||||||||||||||||||||
| 134 | } | ||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||
| 136 | 1 | ▶ | sub whine ($self, $line, $complaint) | ||||||||||||||||||||||||||
|
Subroutine
whine: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 137 | { | ||||||||||||||||||||||||||||
| 138 | 1 | my @row = ( 'error', $self->source_filename, $self->line_number, $complaint ); | |||||||||||||||||||||||||||
| 139 | 1 | $self->callback->(@row); | |||||||||||||||||||||||||||
| 140 | 1 | $self->SUPER::whine($line, $complaint); | |||||||||||||||||||||||||||
| 141 | } | ||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||
| 143 | 0 | ▶ | sub scream ($self, $line, $complaint) | ||||||||||||||||||||||||||
|
Subroutine
scream: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 144 | { | ||||||||||||||||||||||||||||
| 145 | 0 | my @row = ( 'error', $self->source_filename, $self->line_number, $complaint ); | |||||||||||||||||||||||||||
| 146 | 0 | $self->callback->(@row); | |||||||||||||||||||||||||||
| 147 | 0 | $self->SUPER::scream($line, $complaint); | |||||||||||||||||||||||||||
| 148 | } | ||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||
| 150 | 68 | ▶ | sub _handle_text ($self, $text) | ||||||||||||||||||||||||||
|
Subroutine
_handle_text: called CC=15 SCAR=27.2
| |||||||||||||||||||||||||||||
| 151 | { | ||||||||||||||||||||||||||||
| 152 | 68 | ▶ | return if defined $self->link_address && $self->link_address eq $text; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $self->link_address and $self->link_address eq $text
MC/DC100%2/2
defined $self->link_address and $self->link_address eq $text
defined $self->link_address
$self->link_address eq $text
Truth table100%3/3
A and B
A= defined $self->link_addressB= $self->link_address eq $text
| |||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||
| 154 | 66 | ▶ | if($self->in_section_title) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 155 | { | ||||||||||||||||||||||||||||
| 156 | 22 | my @row = ( 'section', $self->source_filename, $self->line_number, $text ); | |||||||||||||||||||||||||||
| 157 | 22 | $self->callback->(@row); | |||||||||||||||||||||||||||
| 158 | } | ||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||
| 160 | 66 | ▶ | if($self->in_head1) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 161 | { | ||||||||||||||||||||||||||||
| 162 | 19 | $self->head1(lc $text); | |||||||||||||||||||||||||||
| 163 | } | ||||||||||||||||||||||||||||
| 164 | else | ||||||||||||||||||||||||||||
| 165 | { | ||||||||||||||||||||||||||||
| 166 | 47 | ▶ | return if $self->skip_section_hash->{$self->head1}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 167 | } | ||||||||||||||||||||||||||||
| 168 | 65 | ▶ | if($self->target) | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 169 | { | ||||||||||||||||||||||||||||
| 170 | 2 | ▶ | if($self->target eq 'stopwords') | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 171 | { | ||||||||||||||||||||||||||||
| 172 | 2 | foreach my $word (split /\b{wb}/, $text) | |||||||||||||||||||||||||||
| 173 | { | ||||||||||||||||||||||||||||
| 174 | 10 | ▶ | next unless $word =~ /\w/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 175 | 6 | my @row = ( 'stopword', $self->source_filename, $self->line_number, $word ); | |||||||||||||||||||||||||||
| 176 | 6 | $self->callback->(@row); | |||||||||||||||||||||||||||
| 177 | } | ||||||||||||||||||||||||||||
| 178 | } | ||||||||||||||||||||||||||||
| 179 | } | ||||||||||||||||||||||||||||
| 180 | elsif($self->in_verbatim) | ||||||||||||||||||||||||||||
| 181 | { | ||||||||||||||||||||||||||||
| 182 | 3 | my $base_line = $self->line_number; | |||||||||||||||||||||||||||
| 183 | 3 | my $doc = PPI::Document->new(\$text); | |||||||||||||||||||||||||||
| 184 | 3 | ▶ | foreach my $comment (($doc->find('PPI::Token::Comment') || [])->@*) | ||||||||||||||||||||||||||
|
Condition100%2/2
$doc->find('PPI::Token::Comment') || []
MC/DC100%1/1
$doc->find('PPI::Token::Comment') || []
$doc->find('PPI::Token::Comment')
Truth table100%2/2
A
A= $doc->find('PPI::Token::Comment')
| |||||||||||||||||||||||||||||
| 185 | { | ||||||||||||||||||||||||||||
| 186 | 3 | $self->line_number($base_line + $comment->location->[0] - 1); | |||||||||||||||||||||||||||
| 187 | 3 | $self->_add_words("$comment"); | |||||||||||||||||||||||||||
| 188 | } | ||||||||||||||||||||||||||||
| 189 | } | ||||||||||||||||||||||||||||
| 190 | else | ||||||||||||||||||||||||||||
| 191 | { | ||||||||||||||||||||||||||||
| 192 | 60 | ▶ | $text = lc $text if $self->in_head1; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 193 | 60 | ▶ | while($text =~ /^(.*?)\r?\n(.*)$/) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 194 | { | ||||||||||||||||||||||||||||
| 195 | 0 | $text = $2; | |||||||||||||||||||||||||||
| 196 | 0 | $self->_add_words($1); | |||||||||||||||||||||||||||
| 197 | 0 | $self->line_number($self->line_number+1); | |||||||||||||||||||||||||||
| 198 | } | ||||||||||||||||||||||||||||
| 199 | 60 | $self->_add_words($text); | |||||||||||||||||||||||||||
| 200 | } | ||||||||||||||||||||||||||||
| 201 | 65 | (); | |||||||||||||||||||||||||||
| 202 | } | ||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||
| 204 | 1 | 1; | |||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||
| 206 | __END__ | ||||||||||||||||||||||||||||