blib/lib/App/whichdll.pm

filter: Statementstmt 46.5% 27 / 58 Branchbran 6.6% 2 / 30 Conditioncond 7.1% 1 / 14 MC/DCmcdc 0.0% 0 / 9 Subroutinesub 80.0% 8 / 10 Podpod 0.0% 0 / 1 totaltotal 31.1% 38 / 122 CC 23 SCAR 54.5
CC
23
Cov
29%
main
352.3
__ANON__
6.0
_version
2.0
CRAP 232.0
↑ Summary bin/whichdll »
1 package App::whichdll;
2  
3 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 3 ▶use 5.008001;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 3 ▶use FFI::CheckLib 0.28 qw( find_lib );
Subroutine BEGIN: called CC=1 SCAR=0.0
7 3 ▶use Getopt::Long qw( GetOptions );
Subroutine BEGIN: called CC=1 SCAR=0.0
8 3 ▶use Path::Tiny qw( path );
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 # ABSTRACT: Find dynamic libraries
11 3 our $VERSION = '0.04'; # VERSION
12  
13  
14 sub main
15 1 ▶{
Subroutine main: called CC=21 SCAR=58.6
Pod undocumented
16 1 local @ARGV;
17 1 (undef, @ARGV) = @_;
18  
19 1 my %opts;
20  
21 my @alien;
22  
23 GetOptions(
24 "a" => \$opts{a},
25 "v" => \$opts{v},
26 "s" => \$opts{s},
27 "x" => \$opts{x},
28 1 ▶ "alien=s" => \@alien,
Branch: 1 branch
BranchTrueFalseTotal
&GetOptions("a", \$opts{"a"}, "v", \$opts{"v"}, "s", \$opts{"s"}, "x", \$opts{"x"}, "alien=s", \@alien) or return _usage() 1 0 1
29 ) || return _usage();
30 1 ▶ return _version() if $opts{v};
Branch: 1 branch
BranchTrueFalseTotal
if $opts{"v"} 1 0 1
31 0 ▶ return _usage() unless @ARGV;
Branch: 1 branch
BranchTrueFalseTotal
unless @ARGV 0 0 0
32  
33 0 my %seen;
34  
35 my @extra_args;
36 0 ▶ if(@alien)
Branch: 1 branch
BranchTrueFalseTotal
if (@alien) 0 0 0
37 {
38 0 push @extra_args, alien => \@alien;
39 }
40  
41 0 foreach my $name (@ARGV)
42 {
43 0 my @result;
44 0 ▶ if($opts{a} || $name eq '*')
Branch: 1 branch
BranchTrueFalseTotal
if ($opts{'a'} or $name eq '*') { } 0 0 0
Condition0%0/3
$opts{"a"} or $name eq "*"
l!l&&r!l&&!r
000
MC/DC0%0/2
$opts{"a"} or $name eq "*"
$opts{"a"} $name eq "*"
Truth table0%0/3
A or B
A= $opts{"a"}B= $name eq "*"
ABresult
1X1
011
000
45 {
46 0 ▶ @result = find_lib( lib => '*', verify => sub { ($name eq '*') || ($_[0] eq $name) }, @extra_args);
Subroutine __ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
$name eq "*" or $_[0] eq $name 0 0 0
47 }
48 else
49 {
50 0 my $result = find_lib( lib => $name, @extra_args );
51 0 ▶ push @result, $result if defined $result;
Branch: 1 branch
BranchTrueFalseTotal
if defined $result 0 0 0
52 }
53  
54 0 ▶ unless($opts{s})
Branch: 1 branch
BranchTrueFalseTotal
unless ($opts{"s"}) 0 0 0
55 {
56 0 foreach my $path (map { path($_) } @result)
57 {
58 0 my $dir = path($path)->parent->realpath;
59 0 $path = $dir->child($path->basename);
60 0 ▶ if(-l $path)
Branch: 1 branch
BranchTrueFalseTotal
if (-l $path) { } 0 0 0
61 {
62 0 my $target = path(readlink $path)->absolute($dir);
63 0 ▶ if(-e $target)
Branch: 1 branch
BranchTrueFalseTotal
if (-e $target) { } 0 0 0
64 {
65 0 $target = $target->realpath;
66 0 ▶ next if (!$opts{x}) && $seen{$target}++;
Branch: 1 branch
BranchTrueFalseTotal
if not $opts{"x"} and $seen{$target}++ 0 0 0
Condition0%0/3
not $opts{"x"} and $seen{$target}++
!ll&&!rl&&r
000
MC/DC0%0/2
not $opts{"x"} and $seen{$target}++
not $opts{"x"} $seen{$target}++
Truth table0%0/3
not(A) and B
A= not $opts{"x"}B= $seen{$target}++
ABresult
0X0
100
111
67 0 print "$path => $target\n";
68 }
69 else
70 {
71 0 ▶ next if (!$opts{x}) && $seen{$target}++;
Branch: 1 branch
BranchTrueFalseTotal
if not $opts{"x"} and $seen{$target}++ 0 0 0
Condition0%0/3
not $opts{"x"} and $seen{$target}++
!ll&&!rl&&r
000
MC/DC0%0/2
not $opts{"x"} and $seen{$target}++
not $opts{"x"} $seen{$target}++
Truth table0%0/3
not(A) and B
A= not $opts{"x"}B= $seen{$target}++
ABresult
0X0
100
111
72 0 print "$path => !! $target !!\n";
73 }
74 }
75 else
76 {
77 0 ▶ next if (!$opts{x}) && $seen{$path}++;
Branch: 1 branch
BranchTrueFalseTotal
if not $opts{"x"} and $seen{$path}++ 0 0 0
Condition0%0/3
not $opts{"x"} and $seen{$path}++
!ll&&!rl&&r
000
MC/DC0%0/2
not $opts{"x"} and $seen{$path}++
not $opts{"x"} $seen{$path}++
Truth table0%0/3
not(A) and B
A= not $opts{"x"}B= $seen{$path}++
ABresult
0X0
100
111
78 0 print "$path\n";
79 }
80 }
81 }
82  
83 0 ▶ unless(@result)
Branch: 1 branch
BranchTrueFalseTotal
unless (@result) 0 0 0
84 {
85 0 ▶ print STDERR "$0: no $name in dynamic library path\n" unless $opts{s};
Branch: 1 branch
BranchTrueFalseTotal
unless $opts{"s"} 0 0 0
86 0 return 1;
87 }
88 }
89  
90 0 return 0;
91 }
92  
93 sub _version
94 1 ▶{
Subroutine _version: called CC=2 SCAR=7.1
95 1 ▶ my $my_version = $App::whichdll::VERSION || 'dev';
Condition50%1/2
$App::whichdll::VERSION || 'dev'
l!l
10
MC/DC0%0/1
$App::whichdll::VERSION || 'dev'
$App::whichdll::VERSION
Truth table50%1/2
A
A= $App::whichdll::VERSION
Aresult
11
00
96 1 print <<"EOF";
97 whichdll running FFI::CheckLib $FFI::CheckLib::VERSION
98 App::whichdll $my_version
99  
100 Copyright 2017 Graham Ollis
101  
102 This program is free software; you may redistribute it and/or modify
103 it under the same terms as Perl itself.
104 EOF
105 1 2;
106 }
107  
108 sub _usage
109 0 ▶{
Subroutine _usage: not called CC=1 SCAR=6.9
110 0 print <<"EOF";
111 Usage: $0 [-a] [-s] [-v] [--alien Alien::Name] dllname [dllname ...]
112 -a Print all matches in dynamic library path.
113 --alien Include Perl Aliens in search
114 -v Prints version and exits
115 -s Silent mode
116 -x Do not prune duplicates (due to symlinks, etc.)
117 EOF
118 }
119  
120 3 1;
121  
122 __END__
↑ Summary bin/whichdll »