Add built local::lib
[catagits/Gitalist.git] / local-lib5 / lib / perl5 / Module / Install / Can.pm
1 package Module::Install::Can;
2
3 use strict;
4 use Config                ();
5 use File::Spec            ();
6 use ExtUtils::MakeMaker   ();
7 use Module::Install::Base ();
8
9 use vars qw{$VERSION @ISA $ISCORE};
10 BEGIN {
11         $VERSION = '0.91';
12         @ISA     = 'Module::Install::Base';
13         $ISCORE  = 1;
14 }
15
16 # check if we can load some module
17 ### Upgrade this to not have to load the module if possible
18 sub can_use {
19         my ($self, $mod, $ver) = @_;
20         $mod =~ s{::|\\}{/}g;
21         $mod .= '.pm' unless $mod =~ /\.pm$/i;
22
23         my $pkg = $mod;
24         $pkg =~ s{/}{::}g;
25         $pkg =~ s{\.pm$}{}i;
26
27         local $@;
28         eval { require $mod; $pkg->VERSION($ver || 0); 1 };
29 }
30
31 # check if we can run some command
32 sub can_run {
33         my ($self, $cmd) = @_;
34
35         my $_cmd = $cmd;
36         return $_cmd if (-x $_cmd or $_cmd = MM->maybe_command($_cmd));
37
38         for my $dir ((split /$Config::Config{path_sep}/, $ENV{PATH}), '.') {
39                 next if $dir eq '';
40                 my $abs = File::Spec->catfile($dir, $_[1]);
41                 return $abs if (-x $abs or $abs = MM->maybe_command($abs));
42         }
43
44         return;
45 }
46
47 # can we locate a (the) C compiler
48 sub can_cc {
49         my $self   = shift;
50         my @chunks = split(/ /, $Config::Config{cc}) or return;
51
52         # $Config{cc} may contain args; try to find out the program part
53         while (@chunks) {
54                 return $self->can_run("@chunks") || (pop(@chunks), next);
55         }
56
57         return;
58 }
59
60 # Fix Cygwin bug on maybe_command();
61 if ( $^O eq 'cygwin' ) {
62         require ExtUtils::MM_Cygwin;
63         require ExtUtils::MM_Win32;
64         if ( ! defined(&ExtUtils::MM_Cygwin::maybe_command) ) {
65                 *ExtUtils::MM_Cygwin::maybe_command = sub {
66                         my ($self, $file) = @_;
67                         if ($file =~ m{^/cygdrive/}i and ExtUtils::MM_Win32->can('maybe_command')) {
68                                 ExtUtils::MM_Win32->maybe_command($file);
69                         } else {
70                                 ExtUtils::MM_Unix->maybe_command($file);
71                         }
72                 }
73         }
74 }
75
76 1;
77
78 __END__
79
80 =pod
81
82 =head1 NAME
83
84 Module::Install::Can - Utility functions for capability detection
85
86 =head1 DESCRIPTION
87
88 C<Module::Install::Can> contains a number of functions for authors to use
89 when creating customised smarter installers. The functions simplify
90 standard tests so that you can express your dependencies and conditions
91 much more simply, and make your installer much easier to maintain.
92
93 =head1 COMMANDS
94
95 =head2 can_use
96
97   can_use('Module::Name');
98   can_use('Module::Name', 1.23);
99
100 The C<can_use> function tests the ability to load a specific named
101 module. Currently it will also actually load the module in the
102 process, although this may change in the future.
103
104 Takes an optional second param of a version number. The currently
105 installed version of the module will be tested to make sure it is
106 equal to or greater than the specified version.
107
108 Returns true if the module can be loaded, or false (in both scalar or
109 list context) if not.
110
111 =head2 can_run
112
113   can_run('cvs');
114
115 The C<can_run> function tests the ability to run a named command or
116 program on the local system.
117
118 Returns true if so, or false (both in scalar and list context) if not.
119
120 =head2 can_cc
121
122   can_cc();
123
124 The C<can_cc> function test the ability to locate a C compiler on the
125 local system. Returns true if the C compiler can be found, or false
126 (both in scalar and list context) if not.
127
128 =head1 TO DO
129
130 Currently, the use of a C<can_foo> command in a single problem domain
131 (for example C<can_use>) results in the inclusion of additional
132 functionality from different problem domains (for example C<can_run>).
133
134 This module should ultimately be broken up, and the individual
135 functions redestributed to different domain-specific extensions.
136
137 =head1 AUTHORS
138
139 Audrey Tang E<lt>autrijus@autrijus.orgE<gt>
140
141 Adam Kennedy E<lt>adamk@cpan.orgE<gt>
142
143 =head1 SEE ALSO
144
145 L<Module::Install>, L<Class::Inspector>
146
147 =head1 COPYRIGHT
148
149 Copyright 2006 Audrey Tang, Adam Kennedy.
150
151 This program is free software; you can redistribute it and/or modify it
152 under the same terms as Perl itself.
153
154 See L<http://www.perl.com/perl/misc/Artistic.html>
155
156 =cut