App-whichdll

 view release on metacpan or  search on metacpan

lib/App/whichdll.pm  view on Meta::CPAN

package App::whichdll;

use strict;
use warnings;
use 5.008001;
use FFI::CheckLib 0.28 qw( find_lib );
use Getopt::Long qw( GetOptions );
use Path::Tiny qw( path );

# ABSTRACT: Find dynamic libraries
our $VERSION = '0.04'; # VERSION


sub main
{
  local @ARGV;
  (undef, @ARGV) = @_;

  my %opts;

  my @alien;

  GetOptions(
    "a"       => \$opts{a},
    "v"       => \$opts{v},
    "s"       => \$opts{s},
    "x"       => \$opts{x},
    "alien=s" => \@alien,
  ) || return _usage();
  return _version() if $opts{v};
  return _usage()   unless @ARGV;

  my %seen;

  my @extra_args;
  if(@alien)
  {
    push @extra_args, alien => \@alien;
  }

  foreach my $name (@ARGV)
  {
    my @result;
    if($opts{a} || $name eq '*')
    {
      @result = find_lib( lib => '*', verify => sub { ($name eq '*') || ($_[0] eq $name) }, @extra_args);
    }
    else
    {
      my $result = find_lib( lib => $name, @extra_args );
      push @result, $result if defined $result;
    }

    unless($opts{s})
    {
      foreach my $path (map { path($_) } @result)
      {
        my $dir = path($path)->parent->realpath;
        $path = $dir->child($path->basename);
        if(-l $path)
        {
          my $target = path(readlink $path)->absolute($dir);
          if(-e $target)
          {
            $target = $target->realpath;
            next if (!$opts{x}) && $seen{$target}++;
            print "$path => $target\n";
          }
          else
          {
            next if (!$opts{x}) && $seen{$target}++;
            print "$path => !! $target !!\n";
          }
        }
        else
        {



( run in 2.238 seconds using v1.01-cache-2.11-cpan-ceb78f64989 )