Can.pm 1.7 KB

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