| 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
| |||||||||||||||||||||||||||||
| 15 | 0 | my $file = $argv{file}; | |||||||||||||||||||||||||||
| 16 | 0 | ▶ | my $skip_header = exists $argv{skip_header} ? $argv{skip_header} : 1; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 25 | 0 | my $fh = Symbol::gensym; | |||||||||||||||||||||||||||
| 26 | 0 | ▶ | tie *$fh, 'Tie::Handle::SkipHeader', '<', $file or die "$!: $file\n"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 27 | 0 | return $fh; | |||||||||||||||||||||||||||
| 28 | } | ||||||||||||||||||||||||||||
| 29 | 0 | ▶ | open my $fh, "<", $file or die "$!: $file\n"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
Condition0%0/3
$pos == -1 or eof $fh
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
| |||||||||||||||||||||||||||||
| 39 | 0 | ▶ | while (my $line = <$fh>) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 40 | 0 | ▶ | last if $line !~ /\A\Q$package\E\s+/i; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 41 | 0 | chomp $line; | |||||||||||||||||||||||||||
| 42 | 0 | my ($_package, $version, $path) = split /\s+/, $line, 4; | |||||||||||||||||||||||||||
| 43 | 0 | ▶ | if ($package eq $_package) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 44 | 0 | ▶ | $version = undef if $version eq 'undef'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||