blib/lib/CPAN/02Packages/Search.pm

filter: Statementstmt 37.7% 17 / 45 Branchbran 0.0% 0 / 20 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 55.5% 5 / 9 Podpod 0.0% 0 / 2 totaltotal 27.1% 22 / 81 SCAR 42.9
CC
12
Cov
25%
search
56.0
_open
20.0
new
12.0
CRAP 72.8
↑ Summary Build »
1 package CPAN::02Packages::Search;
2 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 1 ▶use Search::Dict ();
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use Symbol ();
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use Tie::Handle::SkipHeader;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 1 our $VERSION = '0.100';
10  
11 sub new {
12 0 ▶ my ($class, %argv) = @_;
Subroutine new: not called CC=3 SCAR=24.8
Pod undocumented
13 0 my $fh = $argv{fh};
14 0 ▶ if (!$fh) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($fh) 0 0 0
15 0 my $file = $argv{file};
16 0 ▶ my $skip_header = exists $argv{skip_header} ? $argv{skip_header} : 1;
Branch: 1 branch
BranchTrueFalseTotal
exists $argv{'skip_header'} ? : 0 0 0
17 0 $fh = $class->_open($file, $skip_header);
18 }
19 0 bless { fh => $fh }, $class;
20 }
21  
22 sub _open {
23 0 ▶ my ($class, $file, $skip_header) = @_;
Subroutine _open: not called CC=4 SCAR=30.0
24 0 ▶ if ($skip_header) {
Branch: 1 branch
BranchTrueFalseTotal
if ($skip_header) 0 0 0
25 0 my $fh = Symbol::gensym;
26 0 ▶ tie *$fh, 'Tie::Handle::SkipHeader', '<', $file or die "$!: $file\n";
Branch: 1 branch
BranchTrueFalseTotal
tie *$fh, "Tie::Handle::SkipHeader", "<", $file or die "$!: $file\n" 0 0 0
27 0 return $fh;
28 }
29 0 ▶ open my $fh, "<", $file or die "$!: $file\n";
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, "<", $file or die "$!: $file\n" 0 0 0
30 0 $fh;
31 }
32  
33 sub search {
34 0 ▶ my ($self, $package) = @_;
Subroutine search: not called CC=7 SCAR=40.3
Pod undocumented
35 0 my $fh = $self->{fh};
36 0 seek $fh, 0, 0;
37 0 my $pos = Search::Dict::look $fh, $package, { xfrm => \&_xform_package, fold => 1 };
38 0 ▶ return if $pos == -1 || eof $fh;
Branch: 1 branch
BranchTrueFalseTotal
if $pos == -1 or eof $fh 0 0 0
Condition0%0/3
$pos == -1 or eof $fh
l!l&&r!l&&!r
000
MC/DC0%0/2
$pos == -1 or eof $fh
$pos == -1 eof $fh
Truth table0%0/3
A or B
A= $pos == -1B= eof $fh
ABresult
1X1
011
000
39 0 ▶ while (my $line = <$fh>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $line = readline $fh)) 0 0 0
40 0 ▶ last if $line !~ /\A\Q$package\E\s+/i;
Branch: 1 branch
BranchTrueFalseTotal
unless $line =~ /\A\Q$package\E\s+/i 0 0 0
41 0 chomp $line;
42 0 my ($_package, $version, $path) = split /\s+/, $line, 4;
43 0 ▶ if ($package eq $_package) {
Branch: 1 branch
BranchTrueFalseTotal
if ($package eq $_package) 0 0 0
44 0 ▶ $version = undef if $version eq 'undef';
Branch: 1 branch
BranchTrueFalseTotal
if $version eq "undef" 0 0 0
45 0 return { version => $version, path => $path };
46 }
47 }
48 0 return;
49 }
50  
51 0 ▶sub _xform_package { (split " ", $_[0], 2)[0] }
Subroutine _xform_package: not called CC=1 SCAR=6.9
52  
53 1 1;
54 __END__
↑ Summary Build »