| 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
| |||||||||||||||||||||||||||||
| 29 | ) || return _usage(); | ||||||||||||||||||||||||||||
| 30 | 1 | ▶ | return _version() if $opts{v}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 31 | 0 | ▶ | return _usage() unless @ARGV; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | 0 | my %seen; | |||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | my @extra_args; | ||||||||||||||||||||||||||||
| 36 | 0 | ▶ | if(@alien) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
Condition0%0/3
$opts{"a"} or $name eq "*"
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 "*"
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | 0 | ▶ | unless($opts{s}) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 61 | { | ||||||||||||||||||||||||||||
| 62 | 0 | my $target = path(readlink $path)->absolute($dir); | |||||||||||||||||||||||||||
| 63 | 0 | ▶ | if(-e $target) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 64 | { | ||||||||||||||||||||||||||||
| 65 | 0 | $target = $target->realpath; | |||||||||||||||||||||||||||
| 66 | 0 | ▶ | next if (!$opts{x}) && $seen{$target}++; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not $opts{"x"} and $seen{$target}++
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}++
| |||||||||||||||||||||||||||||
| 67 | 0 | print "$path => $target\n"; | |||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||
| 69 | else | ||||||||||||||||||||||||||||
| 70 | { | ||||||||||||||||||||||||||||
| 71 | 0 | ▶ | next if (!$opts{x}) && $seen{$target}++; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not $opts{"x"} and $seen{$target}++
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}++
| |||||||||||||||||||||||||||||
| 72 | 0 | print "$path => !! $target !!\n"; | |||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||
| 75 | else | ||||||||||||||||||||||||||||
| 76 | { | ||||||||||||||||||||||||||||
| 77 | 0 | ▶ | next if (!$opts{x}) && $seen{$path}++; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not $opts{"x"} and $seen{$path}++
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}++
| |||||||||||||||||||||||||||||
| 78 | 0 | print "$path\n"; | |||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | 0 | ▶ | unless(@result) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 84 | { | ||||||||||||||||||||||||||||
| 85 | 0 | ▶ | print STDERR "$0: no $name in dynamic library path\n" unless $opts{s}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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'
MC/DC0%0/1
$App::whichdll::VERSION || 'dev'
$App::whichdll::VERSION
Truth table50%1/2
A
A= $App::whichdll::VERSION
| |||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||