Spellunker/Pod/Parser.pm

filter: Statementstmt 98.0% 51 / 52 Branchbran 85.0% 17 / 20 Conditioncond 81.8% 9 / 11 MC/DCmcdc 60.0% 3 / 5 Subroutinesub 100% 13 / 13 Podpod 25.0% 1 / 4 totaltotal 89.5% 94 / 105 CC 16 SCAR 14.8
CC
16
Cov
93%
_handle_element_start
9.2
_handle_text
4.0
start_line
2.1
CRAP 4.4
« Test/Spellunker.pm ↑ Summary Spellunker/CLI.pm »
1 package Spellunker::Pod::Parser;
2 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 3 ▶use parent qw(Pod::Simple::Methody);
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 3 ▶use Carp ();
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 3 ▶use constant {
Subroutine BEGIN: called CC=1 SCAR=0.0
10 3 MODE_STOPWORDS => 1,
11 MODE_IGNORE => 2,
12 MODE_NORMAL => 3,
13 3 };
14  
15 105 ▶sub _handle_element_start {
Subroutine _handle_element_start: called CC=9 SCAR=22.2
16 105 my ($self, $element_name, $attr_hash_r) = @_;
17 105 $element_name =~ tr/-:./__/;
18  
19 105 ▶ if (my $start_line = $attr_hash_r->{start_line}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $start_line = $attr_hash_r->{"start_line"}) 94 11 105
20 94 $self->{start_line} = $start_line;
21 }
22  
23 105 ▶ if ($element_name eq 'encoding') {
Branch: 3 branches
BranchTrueFalseTotal
if ($element_name eq 'encoding') { } 0 105 105
elsif ($element_name eq 'for') { } 2 103 105
elsif ($element_name eq 'code' or $element_name eq 'Verbatim' or $element_name eq 'C' or $element_name eq 'L') { } 16 87 103
24 0 $self->{mode} = MODE_IGNORE;
25 } elsif ($element_name eq 'for') {
26 2 ▶ if ($attr_hash_r->{target} eq 'stopwords') {
Branch: 1 branch
BranchTrueFalseTotal
if ($attr_hash_r->{"target"} eq "stopwords") 2 0 2
27 2 $self->{mode} = MODE_STOPWORDS;
28 }
29 ▶ } elsif (
Condition88%8/9
$element_name eq "code" or $element_name eq "Verbatim" or $element_name eq "C" or $element_name eq "L"
l!l&&r!l&&!r
10687
$element_name eq "code" or $element_name eq "Verbatim" or $element_name eq "C"
l!l&&r!l&&!r
5593
$element_name eq "code" or $element_name eq "Verbatim"
l!l&&r!l&&!r
0598
MC/DC75%3/4
$element_name eq "code" or $element_name eq "Verbatim" or $element_name eq "C" or $element_name eq "L"
$element_name eq "code" $element_name eq "Verbatim" $element_name eq "C" $element_name eq "L"
Truth table80%4/5
A or B or C or D
A= $element_name eq "code"B= $element_name eq "Verbatim"C= $element_name eq "C"D= $element_name eq "L"
ABCDresult
1XXX1
01XX1
001X1
00011
00000
30 $element_name eq 'code'
31 || $element_name eq 'Verbatim'
32 || $element_name eq 'C' # C<>
33 || $element_name eq 'L' # L<>
34 ) {
35 16 $_[0]->{mode} = MODE_IGNORE;
36 }
37 }
38  
39 105 ▶sub _handle_element_end {
Subroutine _handle_element_end: called CC=1 SCAR=0.0
40 105 my ($self, $element_name, $attr_hash_r) = @_;
41 105 $element_name =~ tr/-:./__/;
42 105 $self->{mode} = MODE_NORMAL;
43 }
44  
45 10 ▶sub new {
Subroutine new: called CC=2 SCAR=6.9
Pod documented
46 10 my $self = shift;
47 10 my $new = $self->SUPER::new(@_);
48 10 ▶ $new->{'output_fh'} ||= *STDOUT{IO};
Condition50%1/2
$new->{"output_fh"} ||= *STDOUT{"IO"}
l!l
010
MC/DC0%0/1
$new->{"output_fh"} ||= *STDOUT{"IO"}
$new->{"output_fh"}
Truth table50%1/2
A
A= $new->{"output_fh"}
Aresult
11
00
49 10 $new->{mode} = 'normal';
50 10 $new->accept_target_as_text(qw( text plaintext plain stopwords ));
51  
52 # whether to ignore X<...> codes
53 10 $new->nix_X_codes(1);
54  
55 # Whether to map S<...>'s to \xA0 characters
56 10 $new->nbsp_for_S(1);
57  
58 # whether to try to keep whitespace as-is
59 10 $new->preserve_whitespace(1);
60  
61 10 return $new;
62 }
63  
64 10 ▶sub stopwords { $_[0]->{stopwords} || [] }
Subroutine stopwords: called CC=2 SCAR=6.9
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
$_[0]{"stopwords"} or [] 2 8 10
65 10 ▶sub lines { $_[0]->{lines} || [] }
Subroutine lines: called CC=2 SCAR=6.9
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
$_[0]{"lines"} or [] 6 4 10
66 108 ▶sub start_line { $_[0]->{start_line} || 0 }
Subroutine start_line: called CC=2 SCAR=7.6
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
$_[0]{"start_line"} or 0 108 0 108
67  
68 101 ▶sub _handle_text {
Subroutine _handle_text: called CC=4 SCAR=13.9
69 101 my ($self, $text) = @_;
70 101 ▶ if ($self->{mode} eq MODE_IGNORE) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->{'mode'} eq 2) { } 16 85 101
elsif ($self->{'mode'} eq 1) { } 2 83 85
71 # nop.
72 } elsif ($self->{mode} eq MODE_STOPWORDS) {
73 2 push @{$self->{stopwords}}, $text;
74 } else {
75 83 my $offset = 0;
76 83 for my $line (split /\n/, $text) {
77 108 push @{$self->{lines}}, [
78 $self->start_line + $offset, $line
79 ];
80 108 $offset++;
81 }
82 }
83 }
84  
85 3 1;
86  
« Test/Spellunker.pm ↑ Summary Spellunker/CLI.pm »