~ubuntu-branches/ubuntu/saucy/libyaml-libyaml-perl/saucy-security

« back to all changes in this revision

Viewing changes to inc/Module/Install/Can.pm

  • Committer: Bazaar Package Importer
  • Author(s): Ryan Niebur
  • Date: 2009-06-01 02:17:22 UTC
  • Revision ID: james.westby@ubuntu.com-20090601021722-8qlj45pmu8ffwzau
Tags: upstream-0.32
ImportĀ upstreamĀ versionĀ 0.32

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#line 1
 
2
package Module::Install::Can;
 
3
 
 
4
use strict;
 
5
use Module::Install::Base;
 
6
use Config ();
 
7
### This adds a 5.005 Perl version dependency.
 
8
### This is a bug and will be fixed.
 
9
use File::Spec ();
 
10
use ExtUtils::MakeMaker ();
 
11
 
 
12
use vars qw{$VERSION $ISCORE @ISA};
 
13
BEGIN {
 
14
        $VERSION = '0.77';
 
15
        $ISCORE  = 1;
 
16
        @ISA     = qw{Module::Install::Base};
 
17
}
 
18
 
 
19
# check if we can load some module
 
20
### Upgrade this to not have to load the module if possible
 
21
sub can_use {
 
22
        my ($self, $mod, $ver) = @_;
 
23
        $mod =~ s{::|\\}{/}g;
 
24
        $mod .= '.pm' unless $mod =~ /\.pm$/i;
 
25
 
 
26
        my $pkg = $mod;
 
27
        $pkg =~ s{/}{::}g;
 
28
        $pkg =~ s{\.pm$}{}i;
 
29
 
 
30
        local $@;
 
31
        eval { require $mod; $pkg->VERSION($ver || 0); 1 };
 
32
}
 
33
 
 
34
# check if we can run some command
 
35
sub can_run {
 
36
        my ($self, $cmd) = @_;
 
37
 
 
38
        my $_cmd = $cmd;
 
39
        return $_cmd if (-x $_cmd or $_cmd = MM->maybe_command($_cmd));
 
40
 
 
41
        for my $dir ((split /$Config::Config{path_sep}/, $ENV{PATH}), '.') {
 
42
                next if $dir eq '';
 
43
                my $abs = File::Spec->catfile($dir, $_[1]);
 
44
                return $abs if (-x $abs or $abs = MM->maybe_command($abs));
 
45
        }
 
46
 
 
47
        return;
 
48
}
 
49
 
 
50
# can we locate a (the) C compiler
 
51
sub can_cc {
 
52
        my $self   = shift;
 
53
        my @chunks = split(/ /, $Config::Config{cc}) or return;
 
54
 
 
55
        # $Config{cc} may contain args; try to find out the program part
 
56
        while (@chunks) {
 
57
                return $self->can_run("@chunks") || (pop(@chunks), next);
 
58
        }
 
59
 
 
60
        return;
 
61
}
 
62
 
 
63
# Fix Cygwin bug on maybe_command();
 
64
if ( $^O eq 'cygwin' ) {
 
65
        require ExtUtils::MM_Cygwin;
 
66
        require ExtUtils::MM_Win32;
 
67
        if ( ! defined(&ExtUtils::MM_Cygwin::maybe_command) ) {
 
68
                *ExtUtils::MM_Cygwin::maybe_command = sub {
 
69
                        my ($self, $file) = @_;
 
70
                        if ($file =~ m{^/cygdrive/}i and ExtUtils::MM_Win32->can('maybe_command')) {
 
71
                                ExtUtils::MM_Win32->maybe_command($file);
 
72
                        } else {
 
73
                                ExtUtils::MM_Unix->maybe_command($file);
 
74
                        }
 
75
                }
 
76
        }
 
77
}
 
78
 
 
79
1;
 
80
 
 
81
__END__
 
82
 
 
83
#line 158