| 1 | package Pod::Index::Builder; | ||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use 5.008; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 4 | 1 | $VERSION = '0.14'; | |||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 7 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||
| 9 | 1 | ▶ | use base qw(Pod::Parser); | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 10 | 1 | ▶ | use Pod::Index::Entry; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 11 | 1 | ▶ | use File::Spec; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||
| 13 | ####### Pod::Parser overriden methods | ||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||
| 15 | 1 | ▶ | sub begin_input { | ||||||||||||||||||||||||||||||
|
Subroutine
begin_input: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 16 | 1 | my ($self) = @_; | |||||||||||||||||||||||||||||||
| 17 | 1 | $self->{pi_breadcrumbs} = []; | |||||||||||||||||||||||||||||||
| 18 | } | ||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||
| 20 | 4 | ▶ | sub verbatim { | ||||||||||||||||||||||||||||||
|
Subroutine
verbatim: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 21 | #my ($self, $text, $line_num, $pod_para) = @_; | ||||||||||||||||||||||||||||||||
| 22 | # do nothing | ||||||||||||||||||||||||||||||||
| 23 | } | ||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||
| 25 | 11 | ▶ | sub textblock { | ||||||||||||||||||||||||||||||
|
Subroutine
textblock: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 26 | 11 | my ($self, $text, $line_num, $pod_para) = @_; | |||||||||||||||||||||||||||||||
| 27 | 11 | $self->{pi_pos} = [$pod_para->file_line, [ @{$self->{pi_breadcrumbs}} ] ]; | |||||||||||||||||||||||||||||||
| 28 | 11 | $self->interpolate($text, $line_num); | |||||||||||||||||||||||||||||||
| 29 | 11 | return; | |||||||||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||
| 32 | 15 | ▶ | sub command { | ||||||||||||||||||||||||||||||
|
Subroutine
command: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 33 | 15 | my ($self, $cmd, $text, $line_num, $pod_para) = @_; | |||||||||||||||||||||||||||||||
| 34 | 15 | my $breadcrumbs = $self->{pi_breadcrumbs}; | |||||||||||||||||||||||||||||||
| 35 | 15 | ▶ | if ($cmd =~ /head(\d)/) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 36 | 5 | my $level = $1; | |||||||||||||||||||||||||||||||
| 37 | 5 | ▶ | splice @$breadcrumbs, $level-1 if @$breadcrumbs >= $level; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 38 | 5 | $self->{pi_pos} = [$pod_para->file_line, [ @$breadcrumbs ] ]; | |||||||||||||||||||||||||||||||
| 39 | 5 | my $s = $self->interpolate($text, $line_num); | |||||||||||||||||||||||||||||||
| 40 | 5 | $self->{pi_breadcrumbs}[$level - 1] = $s; | |||||||||||||||||||||||||||||||
| 41 | } else { | ||||||||||||||||||||||||||||||||
| 42 | 10 | $self->{pi_pos} = [$pod_para->file_line, [ @$breadcrumbs ] ]; | |||||||||||||||||||||||||||||||
| 43 | 10 | $self->interpolate($text, $line_num); | |||||||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||||||
| 45 | 15 | return; | |||||||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||
| 48 | 17 | ▶ | sub interior_sequence { | ||||||||||||||||||||||||||||||
|
Subroutine
interior_sequence: called CC=2 SCAR=7.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 49 | 17 | my ($self, $seq_command, $seq_argument, $seq_obj) = @_ ; | |||||||||||||||||||||||||||||||
| 50 | 17 | ▶ | if ($seq_command eq 'X') { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 51 | 17 | $self->add_entry($seq_argument); | |||||||||||||||||||||||||||||||
| 52 | 17 | return ''; | |||||||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||||||
| 54 | 0 | return $seq_argument; | |||||||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||
| 58 | ###### new methods | ||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||
| 60 | 1 | ▶ | sub pod_index { shift->{pi_pod_index} } | ||||||||||||||||||||||||||||||
|
Subroutine
pod_index: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||
| 62 | 17 | ▶ | sub add_entry { | ||||||||||||||||||||||||||||||
|
Subroutine
add_entry: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 63 | 17 | my ($self, $keyword) = @_; | |||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||
| 65 | 17 | my ($filename, $line, $breadcrumbs) = @{$self->{pi_pos}}; | |||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||
| 67 | 17 | my $podname = $self->path2package($filename); | |||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||
| 69 | 17 | my $context = $breadcrumbs->[-1]; | |||||||||||||||||||||||||||||||
| 70 | 17 | ▶ | $context = '' unless defined $context; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 71 | 17 | $context =~ s/\n.*//s; | |||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||
| 73 | 17 | my $entry = Pod::Index::Entry->new( | |||||||||||||||||||||||||||||||
| 74 | keyword => $keyword, | ||||||||||||||||||||||||||||||||
| 75 | filename => $filename, | ||||||||||||||||||||||||||||||||
| 76 | podname => $podname, | ||||||||||||||||||||||||||||||||
| 77 | line => $line, | ||||||||||||||||||||||||||||||||
| 78 | context => $context, | ||||||||||||||||||||||||||||||||
| 79 | ); | ||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||
| 81 | 17 | push @{$self->{pi_pod_index}{lc $keyword}}, $entry; | |||||||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||
| 84 | 17 | ▶ | sub path2package { | ||||||||||||||||||||||||||||||
|
Subroutine
path2package: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 85 | 17 | my ($self, $pathname) = @_; | |||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||
| 87 | 17 | my $relname = File::Spec->abs2rel($pathname, $self->{pi_base}); | |||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||
| 89 | 17 | my ($volume, $dirstring, $file) = File::Spec->splitpath($relname); | |||||||||||||||||||||||||||||||
| 90 | 17 | my @dirs = File::Spec->splitdir($dirstring); | |||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||
| 92 | 17 | ▶ | pop @dirs if ($dirs[-1] eq ''); # in case there was a trailing slash | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 93 | 17 | $file =~ s/\.\w+$//; | |||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||
| 95 | 17 | my $package = join('::',@dirs,$file); | |||||||||||||||||||||||||||||||
| 96 | 17 | return $package; | |||||||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||
| 99 | 1 | ▶ | sub print_index { | ||||||||||||||||||||||||||||||
|
Subroutine
print_index: called CC=10 SCAR=30.6
Pod
documented
| |||||||||||||||||||||||||||||||||
| 100 | 1 | my ($self, $f) = @_; | |||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||
| 102 | # figure out filehandle | ||||||||||||||||||||||||||||||||
| 103 | 1 | my $fh; | |||||||||||||||||||||||||||||||
| 104 | 1 | ▶ | if ($f and !ref $f) { | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition33%1/3
$f and not ref $f
MC/DC0%0/2
$f and not ref $f
$f
not ref $f
Truth table33%1/3
A and not(B)
A= $fB= not ref $f
| |||||||||||||||||||||||||||||||||
| 105 | 0 | ▶ | open $fh, ">", $f or die "couldn't open $f: $!\n"; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 106 | } elsif ($f) { | ||||||||||||||||||||||||||||||||
| 107 | 1 | $fh = $f; | |||||||||||||||||||||||||||||||
| 108 | } else { | ||||||||||||||||||||||||||||||||
| 109 | 0 | ▶ | $fh ||= *STDOUT; | ||||||||||||||||||||||||||||||
|
Condition0%0/3
$fh ||= *STDOUT
MC/DC0%0/2
$fh ||= *STDOUT
$fh
*STDOUT
Truth table0%0/3
A ||= B
A= $fhB= *STDOUT
| |||||||||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||
| 112 | # print out the index | ||||||||||||||||||||||||||||||||
| 113 | 1 | my $idx = $self->pod_index; | |||||||||||||||||||||||||||||||
| 114 | 1 | for my $key ( | |||||||||||||||||||||||||||||||
| 115 | sort { | ||||||||||||||||||||||||||||||||
| 116 | $a cmp $b | ||||||||||||||||||||||||||||||||
| 117 | or $idx->{$a}{keyword} cmp $idx->{$b}{keyword} | ||||||||||||||||||||||||||||||||
| 118 | 41 | ▶ | } keys %$idx | ||||||||||||||||||||||||||||||
|
Condition33%1/3
$a cmp $b || $idx->{$a}{'keyword'} cmp $idx->{$b}{'keyword'}
MC/DC0%0/2
$a cmp $b || $idx->{$a}{'keyword'} cmp $idx->{$b}{'keyword'}
$a cmp $b
$idx->{$a}{'keyword'} cmp $idx->{$b}{'keyword'}
Truth table33%1/3
A || B
A= $a cmp $bB= $idx->{$a}{'keyword'} cmp $idx->{$b}{'keyword'}
| |||||||||||||||||||||||||||||||||
| 119 | ) { | ||||||||||||||||||||||||||||||||
| 120 | 15 | for my $entry ( | |||||||||||||||||||||||||||||||
| 121 | sort { | ||||||||||||||||||||||||||||||||
| 122 | $a->{podname} cmp $b->{podname} | ||||||||||||||||||||||||||||||||
| 123 | or $a->{line} <=> $b->{line} | ||||||||||||||||||||||||||||||||
| 124 | 2 | ▶ | } @{$idx->{$key}} | ||||||||||||||||||||||||||||||
|
Condition33%1/3
$Pod::Index::Builder::a->{'podname'} cmp $Pod::Index::Builder::b->{'podname'} || $Pod::Index::Builder::a->{'line'} <=> $Pod::Index::Builder::b->{'line'}
MC/DC0%0/2
$Pod::Index::Builder::a->{'podname'} cmp $Pod::Index::Builder::b->{'podname'} || $Pod::Index::Builder::a->{'line'} <=> $Pod::Index::Builder::b->{'line'}
$Pod::Index::Builder::a->{'podname'} cmp $Pod::Index::Builder::b->{'podname'}
$Pod::Index::Builder::a->{'line'} <=> $Pod::Index::Builder::b->{'line'}
Truth table33%1/3
A || B
A= $Pod::Index::Builder::a->{'podname'} cmp $Pod::Index::Builder::b->{'podname'}B= $Pod::Index::Builder::a->{'line'} <=> $Pod::Index::Builder::b->{'line'}
| |||||||||||||||||||||||||||||||||
| 125 | ) { | ||||||||||||||||||||||||||||||||
| 126 | 17 | print $fh join("\t", @$entry{qw(keyword podname line context)}), "\n"; | |||||||||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||||||||
| 128 | } | ||||||||||||||||||||||||||||||||
| 129 | } | ||||||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||||||
| 131 | 1 | 1; | |||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||||
| 133 | __END__ | ||||||||||||||||||||||||||||||||