1 package Module::Install::Can;
4 use Module::Install::Base;
6 ### This adds a 5.005 Perl version dependency.
7 ### This is a bug and will be fixed.
9 use ExtUtils::MakeMaker ();
11 use vars qw{$VERSION $ISCORE @ISA};
15 @ISA = qw{Module::Install::Base};
18 # check if we can load some module
19 ### Upgrade this to not have to load the module if possible
21 my ($self, $mod, $ver) = @_;
23 $mod .= '.pm' unless $mod =~ /\.pm$/i;
30 eval { require $mod; $pkg->VERSION($ver || 0); 1 };
33 # check if we can run some command
35 my ($self, $cmd) = @_;
38 return $_cmd if (-x $_cmd or $_cmd = MM->maybe_command($_cmd));
40 for my $dir ((split /$Config::Config{path_sep}/, $ENV{PATH}), '.') {
41 my $abs = File::Spec->catfile($dir, $_[1]);
42 return $abs if (-x $abs or $abs = MM->maybe_command($abs));
48 # can we locate a (the) C compiler
51 my @chunks = split(/ /, $Config::Config{cc}) or return;
53 # $Config{cc} may contain args; try to find out the program part
55 return $self->can_run("@chunks") || (pop(@chunks), next);
61 # Fix Cygwin bug on maybe_command();
62 if ( $^O eq 'cygwin' ) {
63 require ExtUtils::MM_Cygwin;
64 require ExtUtils::MM_Win32;
65 if ( ! defined(&ExtUtils::MM_Cygwin::maybe_command) ) {
66 *ExtUtils::MM_Cygwin::maybe_command = sub {
67 my ($self, $file) = @_;
68 if ($file =~ m{^/cygdrive/}i and ExtUtils::MM_Win32->can('maybe_command')) {
69 ExtUtils::MM_Win32->maybe_command($file);
71 ExtUtils::MM_Unix->maybe_command($file);
85 Module::Install::Can - Utility functions for capability detection
89 C<Module::Install::Can> contains a number of functions for authors to use
90 when creating customised smarter installers. The functions simplify
91 standard tests so that you can express your dependencies and conditions
92 much more simply, and make your installer much easier to maintain.
98 can_use('Module::Name');
99 can_use('Module::Name', 1.23);
101 The C<can_use> function tests the ability to load a specific named
102 module. Currently it will also actually load the module in the
103 process, although this may change in the future.
105 Takes an optional second param of a version number. The currently
106 installed version of the module will be tested to make sure it is
107 equal to or greater than the specified version.
109 Returns true if the module can be loaded, or false (in both scalar or
110 list context) if not.
116 The C<can_run> function tests the ability to run a named command or
117 program on the local system.
119 Returns true if so, or false (both in scalar and list context) if not.
125 The C<can_cc> function test the ability to locate a C compiler on the
126 local system. Returns true if the C compiler can be found, or false
127 (both in scalar and list context) if not.
131 Currently, the use of a C<can_foo> command in a single problem domain
132 (for example C<can_use>) results in the inclusion of additional
133 functionality from different problem domains (for example C<can_run>).
135 This module should ultimately be broken up, and the individual
136 functions redestributed to different domain-specific extensions.
140 Audrey Tang E<lt>autrijus@autrijus.orgE<gt>
142 Adam Kennedy E<lt>adamk@cpan.orgE<gt>
146 L<Module::Install>, L<Class::Inspector>
150 Copyright 2006 Audrey Tang, Adam Kennedy.
152 This program is free software; you can redistribute it and/or modify it
153 under the same terms as Perl itself.
155 See L<http://www.perl.com/perl/misc/Artistic.html>