1 package Module::Install::Can;
6 use ExtUtils::MakeMaker ();
7 use Module::Install::Base ();
9 use vars qw{$VERSION @ISA $ISCORE};
12 @ISA = 'Module::Install::Base';
16 # check if we can load some module
17 ### Upgrade this to not have to load the module if possible
19 my ($self, $mod, $ver) = @_;
21 $mod .= '.pm' unless $mod =~ /\.pm$/i;
28 eval { require $mod; $pkg->VERSION($ver || 0); 1 };
31 # check if we can run some command
33 my ($self, $cmd) = @_;
36 return $_cmd if (-x $_cmd or $_cmd = MM->maybe_command($_cmd));
38 for my $dir ((split /$Config::Config{path_sep}/, $ENV{PATH}), '.') {
40 my $abs = File::Spec->catfile($dir, $_[1]);
41 return $abs if (-x $abs or $abs = MM->maybe_command($abs));
47 # can we locate a (the) C compiler
50 my @chunks = split(/ /, $Config::Config{cc}) or return;
52 # $Config{cc} may contain args; try to find out the program part
54 return $self->can_run("@chunks") || (pop(@chunks), next);
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);
70 ExtUtils::MM_Unix->maybe_command($file);
84 Module::Install::Can - Utility functions for capability detection
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.
97 can_use('Module::Name');
98 can_use('Module::Name', 1.23);
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.
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.
108 Returns true if the module can be loaded, or false (in both scalar or
109 list context) if not.
115 The C<can_run> function tests the ability to run a named command or
116 program on the local system.
118 Returns true if so, or false (both in scalar and list context) if not.
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.
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>).
134 This module should ultimately be broken up, and the individual
135 functions redestributed to different domain-specific extensions.
139 Audrey Tang E<lt>autrijus@autrijus.orgE<gt>
141 Adam Kennedy E<lt>adamk@cpan.orgE<gt>
145 L<Module::Install>, L<Class::Inspector>
149 Copyright 2006 Audrey Tang, Adam Kennedy.
151 This program is free software; you can redistribute it and/or modify it
152 under the same terms as Perl itself.
154 See L<http://www.perl.com/perl/misc/Artistic.html>