Add the following packages libalgorithm-diff-perl libspiffy-perl libtext-diff-perl...
[pkg-perl] / deb-src / libspiffy-perl / libspiffy-perl-0.30 / inc / Module / Install / Can.pm
1 #line 1 "inc/Module/Install/Can.pm - /Users/ingy/local/lib/perl5/site_perl/5.8.6/Module/Install/Can.pm"
2 package Module::Install::Can;
3 use Module::Install::Base; @ISA = qw(Module::Install::Base);
4 $VERSION = '0.01';
5
6 use strict;
7 use Config ();
8 use File::Spec ();
9 use ExtUtils::MakeMaker ();
10
11 # check if we can load some module
12 sub can_use {
13     my ($self, $mod, $ver) = @_;
14     $mod =~ s{::|\\}{/}g;
15     $mod .= ".pm" unless $mod =~ /\.pm$/i;
16
17     my $pkg = $mod;
18     $pkg =~ s{/}{::}g;
19     $pkg =~ s{\.pm$}{}i;
20
21     local $@;
22     eval { require $mod; $pkg->VERSION($ver || 0); 1 };
23 }
24
25 # check if we can run some command
26 sub can_run {
27     my ($self, $cmd) = @_;
28
29     my $_cmd = $cmd;
30     return $_cmd if (-x $_cmd or $_cmd = MM->maybe_command($_cmd));
31
32     for my $dir ((split /$Config::Config{path_sep}/, $ENV{PATH}), '.') {
33         my $abs = File::Spec->catfile($dir, $_[1]);
34         return $abs if (-x $abs or $abs = MM->maybe_command($abs));
35     }
36
37     return;
38 }
39
40 sub can_cc {
41     my $self = shift;
42     my @chunks = split(/ /, $Config::Config{cc}) or return;
43
44     # $Config{cc} may contain args; try to find out the program part
45     while (@chunks) {
46         return $self->can_run("@chunks") || (pop(@chunks), next);
47     }
48
49     return;
50 }
51
52 # Fix Cygwin bug on maybe_command();
53 if ($^O eq 'cygwin') {
54     require ExtUtils::MM_Cygwin;
55     require ExtUtils::MM_Win32;
56     if (!defined(&ExtUtils::MM_Cygwin::maybe_command)) {
57         *ExtUtils::MM_Cygwin::maybe_command = sub {
58             my ($self, $file) = @_;
59             if ($file =~ m{^/cygdrive/}i and ExtUtils::MM_Win32->can('maybe_command')) {
60                 ExtUtils::MM_Win32->maybe_command($file);
61             }
62             else {
63                 ExtUtils::MM_Unix->maybe_command($file);
64             }
65         }
66     }
67 }
68
69 1;