| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package App::whichdll; | 
| 2 |  |  |  |  |  |  |  | 
| 3 | 2 |  |  | 2 |  | 192171 | use strict; | 
|  | 2 |  |  |  |  | 9 |  | 
|  | 2 |  |  |  |  | 49 |  | 
| 4 | 2 |  |  | 2 |  | 10 | use warnings; | 
|  | 2 |  |  |  |  | 3 |  | 
|  | 2 |  |  |  |  | 37 |  | 
| 5 | 2 |  |  | 2 |  | 33 | use 5.008001; | 
|  | 2 |  |  |  |  | 6 |  | 
| 6 | 2 |  |  | 2 |  | 847 | use FFI::CheckLib 0.28 qw( find_lib ); | 
|  | 2 |  |  |  |  | 4922 |  | 
|  | 2 |  |  |  |  | 111 |  | 
| 7 | 2 |  |  | 2 |  | 1240 | use Getopt::Long qw( GetOptions ); | 
|  | 2 |  |  |  |  | 17821 |  | 
|  | 2 |  |  |  |  | 7 |  | 
| 8 | 2 |  |  | 2 |  | 1699 | use Path::Tiny qw( path ); | 
|  | 2 |  |  |  |  | 20944 |  | 
|  | 2 |  |  |  |  | 959 |  | 
| 9 |  |  |  |  |  |  |  | 
| 10 |  |  |  |  |  |  | # ABSTRACT: Find dynamic libraries | 
| 11 |  |  |  |  |  |  | our $VERSION = '0.04'; # VERSION | 
| 12 |  |  |  |  |  |  |  | 
| 13 |  |  |  |  |  |  |  | 
| 14 |  |  |  |  |  |  | sub main | 
| 15 |  |  |  |  |  |  | { | 
| 16 | 0 |  |  | 0 | 0 |  | local @ARGV; | 
| 17 | 0 |  |  |  |  |  | (undef, @ARGV) = @_; | 
| 18 |  |  |  |  |  |  |  | 
| 19 | 0 |  |  |  |  |  | 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 | 0 | 0 |  |  |  |  | "alien=s" => \@alien, | 
| 29 |  |  |  |  |  |  | ) || return _usage(); | 
| 30 | 0 | 0 |  |  |  |  | return _version() if $opts{v}; | 
| 31 | 0 | 0 |  |  |  |  | return _usage()   unless @ARGV; | 
| 32 |  |  |  |  |  |  |  | 
| 33 | 0 |  |  |  |  |  | my %seen; | 
| 34 |  |  |  |  |  |  |  | 
| 35 |  |  |  |  |  |  | my @extra_args; | 
| 36 | 0 | 0 |  |  |  |  | if(@alien) | 
| 37 |  |  |  |  |  |  | { | 
| 38 | 0 |  |  |  |  |  | push @extra_args, alien => \@alien; | 
| 39 |  |  |  |  |  |  | } | 
| 40 |  |  |  |  |  |  |  | 
| 41 | 0 |  |  |  |  |  | foreach my $name (@ARGV) | 
| 42 |  |  |  |  |  |  | { | 
| 43 | 0 |  |  |  |  |  | my @result; | 
| 44 | 0 | 0 | 0 |  |  |  | if($opts{a} || $name eq '*') | 
| 45 |  |  |  |  |  |  | { | 
| 46 | 0 | 0 |  | 0 |  |  | @result = find_lib( lib => '*', verify => sub { ($name eq '*') || ($_[0] eq $name) }, @extra_args); | 
|  | 0 |  |  |  |  |  |  | 
| 47 |  |  |  |  |  |  | } | 
| 48 |  |  |  |  |  |  | else | 
| 49 |  |  |  |  |  |  | { | 
| 50 | 0 |  |  |  |  |  | my $result = find_lib( lib => $name, @extra_args ); | 
| 51 | 0 | 0 |  |  |  |  | push @result, $result if defined $result; | 
| 52 |  |  |  |  |  |  | } | 
| 53 |  |  |  |  |  |  |  | 
| 54 | 0 | 0 |  |  |  |  | unless($opts{s}) | 
| 55 |  |  |  |  |  |  | { | 
| 56 | 0 |  |  |  |  |  | foreach my $path (map { path($_) } @result) | 
|  | 0 |  |  |  |  |  |  | 
| 57 |  |  |  |  |  |  | { | 
| 58 | 0 |  |  |  |  |  | my $dir = path($path)->parent->realpath; | 
| 59 | 0 |  |  |  |  |  | $path = $dir->child($path->basename); | 
| 60 | 0 | 0 |  |  |  |  | if(-l $path) | 
| 61 |  |  |  |  |  |  | { | 
| 62 | 0 |  |  |  |  |  | my $target = path(readlink $path)->absolute($dir); | 
| 63 | 0 | 0 |  |  |  |  | if(-e $target) | 
| 64 |  |  |  |  |  |  | { | 
| 65 | 0 |  |  |  |  |  | $target = $target->realpath; | 
| 66 | 0 | 0 | 0 |  |  |  | next if (!$opts{x}) && $seen{$target}++; | 
| 67 | 0 |  |  |  |  |  | print "$path => $target\n"; | 
| 68 |  |  |  |  |  |  | } | 
| 69 |  |  |  |  |  |  | else | 
| 70 |  |  |  |  |  |  | { | 
| 71 | 0 | 0 | 0 |  |  |  | next if (!$opts{x}) && $seen{$target}++; | 
| 72 | 0 |  |  |  |  |  | print "$path => !! $target !!\n"; | 
| 73 |  |  |  |  |  |  | } | 
| 74 |  |  |  |  |  |  | } | 
| 75 |  |  |  |  |  |  | else | 
| 76 |  |  |  |  |  |  | { | 
| 77 | 0 | 0 | 0 |  |  |  | next if (!$opts{x}) && $seen{$path}++; | 
| 78 | 0 |  |  |  |  |  | print "$path\n"; | 
| 79 |  |  |  |  |  |  | } | 
| 80 |  |  |  |  |  |  | } | 
| 81 |  |  |  |  |  |  | } | 
| 82 |  |  |  |  |  |  |  | 
| 83 | 0 | 0 |  |  |  |  | unless(@result) | 
| 84 |  |  |  |  |  |  | { | 
| 85 | 0 | 0 |  |  |  |  | print STDERR "$0: no $name in dynamic library path\n" unless $opts{s}; | 
| 86 | 0 |  |  |  |  |  | return 1; | 
| 87 |  |  |  |  |  |  | } | 
| 88 |  |  |  |  |  |  | } | 
| 89 |  |  |  |  |  |  |  | 
| 90 | 0 |  |  |  |  |  | return 0; | 
| 91 |  |  |  |  |  |  | } | 
| 92 |  |  |  |  |  |  |  | 
| 93 |  |  |  |  |  |  | sub _version | 
| 94 |  |  |  |  |  |  | { | 
| 95 | 0 |  | 0 | 0 |  |  | my $my_version = $App::whichdll::VERSION || 'dev'; | 
| 96 | 0 |  |  |  |  |  | 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 | 0 |  |  |  |  |  | 2; | 
| 106 |  |  |  |  |  |  | } | 
| 107 |  |  |  |  |  |  |  | 
| 108 |  |  |  |  |  |  | sub _usage | 
| 109 |  |  |  |  |  |  | { | 
| 110 | 0 |  |  | 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 |  |  |  |  |  |  | 1; | 
| 121 |  |  |  |  |  |  |  | 
| 122 |  |  |  |  |  |  | __END__ |