| 1 | package App::Perldoc::Search; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | 3 | ▶ | BEGIN { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 3 | 3 | $App::Perldoc::Search::VERSION = '0.11'; | |||||||||||||||||||||||||||||||||||||||||
| 4 | } | ||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||
| 6 | 3 | ▶ | use 5.006; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | 3 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||
| 9 | 3 | require Config; | |||||||||||||||||||||||||||||||||||||||||
| 10 | 3 | require File::Find; | |||||||||||||||||||||||||||||||||||||||||
| 11 | 3 | require File::Spec; | |||||||||||||||||||||||||||||||||||||||||
| 12 | 3 | require Getopt::Long; | |||||||||||||||||||||||||||||||||||||||||
| 13 | 3 | require Pod::Usage; | |||||||||||||||||||||||||||||||||||||||||
| 14 | 3 | require IO::File; | |||||||||||||||||||||||||||||||||||||||||
| 15 | 3 | require App::Perldoc::Search::_Parser; | |||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||
| 17 | 3 | ▶ | sub run { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
run: called CC=13 SCAR=28.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 18 | 3 | my ( $class, @argv ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||
| 20 | # Read optional options. | ||||||||||||||||||||||||||||||||||||||||||
| 21 | 3 | local *ARGV = \ @argv; | |||||||||||||||||||||||||||||||||||||||||
| 22 | 3 | my $file_match_rx = qr/\.p(?:od|mc?)$/; | |||||||||||||||||||||||||||||||||||||||||
| 23 | Getopt::Long::GetOptions( | ||||||||||||||||||||||||||||||||||||||||||
| 24 | 'slow' => \ my $slow_match, | ||||||||||||||||||||||||||||||||||||||||||
| 25 | 0 | ▶ | 'G=s' => sub { $file_match_rx = qr/$_[1]/ }, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 26 | 3 | ▶ | 'help' => \ &_help, | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 27 | 'l' => \ my $list_files ) | ||||||||||||||||||||||||||||||||||||||||||
| 28 | or _error_help(); | ||||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||
| 30 | # Validate pattern. | ||||||||||||||||||||||||||||||||||||||||||
| 31 | 3 | ▶ | if ( ! @argv ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 32 | 0 | _error_help( -exitval => 1 ); | |||||||||||||||||||||||||||||||||||||||||
| 33 | } | ||||||||||||||||||||||||||||||||||||||||||
| 34 | 3 | my $pattern = _case_fold(shift @ARGV); | |||||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||||
| 36 | # Get search path | ||||||||||||||||||||||||||||||||||||||||||
| 37 | 3 | ▶ | my @search_path = @ARGV ? @ARGV : _default_search_path(); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||
| 39 | # Search all files. | ||||||||||||||||||||||||||||||||||||||||||
| 40 | 3 | my @files; | |||||||||||||||||||||||||||||||||||||||||
| 41 | File::Find::find( | ||||||||||||||||||||||||||||||||||||||||||
| 42 | { | ||||||||||||||||||||||||||||||||||||||||||
| 43 | follow_skip => 2, | ||||||||||||||||||||||||||||||||||||||||||
| 44 | no_chdir => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 45 | 102855 | ▶ | wanted => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=14.2
| |||||||||||||||||||||||||||||||||||||||||||
| 46 | return if | ||||||||||||||||||||||||||||||||||||||||||
| 47 | 102855 | ▶ | ! /$file_match_rx/ | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%4/6
/$file_match_rx/ and -f $_ and -r _
/$file_match_rx/ and -f $_
MC/DC33%1/3
/$file_match_rx/ and -f $_ and -r _
/$file_match_rx/
-f $_
-r _
Truth table50%2/4
A and B and C
A= /$file_match_rx/B= -f $_C= -r _
| |||||||||||||||||||||||||||||||||||||||||||
| 48 | || ! -f | ||||||||||||||||||||||||||||||||||||||||||
| 49 | || ! -r _; | ||||||||||||||||||||||||||||||||||||||||||
| 50 | 13755 | push @files, $_; | |||||||||||||||||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||||||||||||||||
| 52 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 53 | @search_path | ||||||||||||||||||||||||||||||||||||||||||
| 54 | 3 | ); | |||||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||||||
| 56 | { | ||||||||||||||||||||||||||||||||||||||||||
| 57 | 3 | my %seen; | |||||||||||||||||||||||||||||||||||||||||
| 58 | @files = | ||||||||||||||||||||||||||||||||||||||||||
| 59 | sort | ||||||||||||||||||||||||||||||||||||||||||
| 60 | 3 | grep { !$seen{$_}++ } | |||||||||||||||||||||||||||||||||||||||||
| 61 | @files; | ||||||||||||||||||||||||||||||||||||||||||
| 62 | 3 | undef %seen; | |||||||||||||||||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||||||
| 65 | 3 | for my $file ( @files ) { | |||||||||||||||||||||||||||||||||||||||||
| 66 | # Open the documentation. | ||||||||||||||||||||||||||||||||||||||||||
| 67 | 6297 | my $fh = IO::File->new; | |||||||||||||||||||||||||||||||||||||||||
| 68 | 6297 | ▶ | $fh->open( $file, '<' ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 69 | or next; # TODO | ||||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||||
| 71 | # Read the documentation. | ||||||||||||||||||||||||||||||||||||||||||
| 72 | 6297 | my $text; | |||||||||||||||||||||||||||||||||||||||||
| 73 | 6297 | IO::Handle->input_record_separator( undef ); | |||||||||||||||||||||||||||||||||||||||||
| 74 | 6297 | $text = $fh->getline; | |||||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||||||
| 76 | # Try a fast match to avoid parsing. | ||||||||||||||||||||||||||||||||||||||||||
| 77 | 6297 | ▶ | next if $text !~ $pattern; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||
| 79 | 1774 | my ($name); | |||||||||||||||||||||||||||||||||||||||||
| 80 | 1774 | ▶ | if ($slow_match) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 81 | # Prepare for searching. | ||||||||||||||||||||||||||||||||||||||||||
| 82 | 0 | my $searcher = App::Perldoc::Search::_Parser->new; | |||||||||||||||||||||||||||||||||||||||||
| 83 | 0 | $searcher->{pattern} = $pattern; | |||||||||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||||||||||
| 85 | # Search the document. | ||||||||||||||||||||||||||||||||||||||||||
| 86 | 0 | IO::Handle->input_record_separator( "\n" ); | |||||||||||||||||||||||||||||||||||||||||
| 87 | 0 | $fh->seek( 0, 0 ); | |||||||||||||||||||||||||||||||||||||||||
| 88 | 0 | $searcher->parse_from_filehandle( $fh ); | |||||||||||||||||||||||||||||||||||||||||
| 89 | 0 | ▶ | next if ! $searcher->{matched}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||||||||||||
| 91 | # Extract document name. | ||||||||||||||||||||||||||||||||||||||||||
| 92 | 0 | $name = $searcher->{name}; | |||||||||||||||||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||||||||||||||||
| 94 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 95 | 1774 | ($name) = $text =~ /^=head\d+\s+NAME[^\r\n]*[\r\n]+(\S+)/m; | |||||||||||||||||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||||||||||
| 98 | # Report. | ||||||||||||||||||||||||||||||||||||||||||
| 99 | 1774 | ▶ | if ($list_files) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 100 | 0 | print "$file\n"; | |||||||||||||||||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||||||||||||||||
| 102 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 103 | 1774 | ▶ | my $msg = ($name && $file) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$name and $file
MC/DC50%1/2
$name and $file
$name
$file
Truth table66%2/3
A and B
A= $nameB= $file
| |||||||||||||||||||||||||||||||||||||||||||
| 104 | ? "$name - $file\n" | ||||||||||||||||||||||||||||||||||||||||||
| 105 | : "$file\n"; | ||||||||||||||||||||||||||||||||||||||||||
| 106 | 1774 | ▶ | print $msg | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 107 | or warn "Can't write: $!"; | ||||||||||||||||||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||||||||||||
| 112 | 3 | return; | |||||||||||||||||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||||||||||||
| 115 | 3 | ▶ | sub _case_fold { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_case_fold: called CC=2 SCAR=7.2
| |||||||||||||||||||||||||||||||||||||||||||
| 116 | 3 | my $pattern = shift; | |||||||||||||||||||||||||||||||||||||||||
| 117 | 3 | ▶ | return $pattern =~ /[A-Z]/ | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 118 | ? $pattern | ||||||||||||||||||||||||||||||||||||||||||
| 119 | : $pattern; | ||||||||||||||||||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||||||||||||||||
| 122 | 0 | ▶ | sub _help { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_help: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 123 | 0 | Pod::Usage::pod2usage( | |||||||||||||||||||||||||||||||||||||||||
| 124 | -verbose => 2, | ||||||||||||||||||||||||||||||||||||||||||
| 125 | -exitval => 0, | ||||||||||||||||||||||||||||||||||||||||||
| 126 | -output => \*STDOUT ); | ||||||||||||||||||||||||||||||||||||||||||
| 127 | # NOT REACHED | ||||||||||||||||||||||||||||||||||||||||||
| 128 | } | ||||||||||||||||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||||||||||||||||
| 130 | 0 | ▶ | sub _error_help { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_error_help: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 131 | 0 | Pod::Usage::pod2usage( | |||||||||||||||||||||||||||||||||||||||||
| 132 | -verbose => 2, | ||||||||||||||||||||||||||||||||||||||||||
| 133 | -exitval => 2, | ||||||||||||||||||||||||||||||||||||||||||
| 134 | -output => \*STDERR, | ||||||||||||||||||||||||||||||||||||||||||
| 135 | @_ ); | ||||||||||||||||||||||||||||||||||||||||||
| 136 | # NOT REACHED | ||||||||||||||||||||||||||||||||||||||||||
| 137 | } | ||||||||||||||||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||||||||||||||||
| 139 | 3 | ▶ | sub _default_search_path { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_default_search_path: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 140 | 3 | my @search_path = @INC; | |||||||||||||||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||||||||||||||||
| 142 | # Add in the pod directories. | ||||||||||||||||||||||||||||||||||||||||||
| 143 | push @search_path, | ||||||||||||||||||||||||||||||||||||||||||
| 144 | # map { File::Spec->catdir($_, 'pod') } | ||||||||||||||||||||||||||||||||||||||||||
| 145 | @Config::Config{ | ||||||||||||||||||||||||||||||||||||||||||
| 146 | 3 | qw( | |||||||||||||||||||||||||||||||||||||||||
| 147 | archlibexp | ||||||||||||||||||||||||||||||||||||||||||
| 148 | privlibexp | ||||||||||||||||||||||||||||||||||||||||||
| 149 | sitelibexp | ||||||||||||||||||||||||||||||||||||||||||
| 150 | vendorlibexp)}; | ||||||||||||||||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||||||||||||||||
| 152 | 3 | return @search_path; | |||||||||||||||||||||||||||||||||||||||||
| 153 | } | ||||||||||||||||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||||||||||||||||
| 155 | 3 | q(Soviet Jesus's gift at Christmas of a blow-up doll to Debbie would always turn to be the most enigmatic); | |||||||||||||||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||||||||||||||||
| 157 | __END__ | ||||||||||||||||||||||||||||||||||||||||||