2 package Module::Depends::Intrusive;
3 use base qw( Module::Depends );
5 use ExtUtils::MakeMaker ();
10 # this order is important, as when a Makefile.PL and Build.PL are
11 # present, the Makefile.PL could just be a passthrough
12 my $pl = -e 'Build.PL' ? 'Build.PL' : -e 'Makefile.PL' ? 'Makefile.PL' : 0;
14 $self->error( 'No {Build,Makefile}.PL found in '.$self->dist_dir );
18 # fake up Module::Build and ExtUtils::MakeMaker
19 no warnings 'redefine';
20 local *STDIN; # run non-interactive
21 local *ExtUtils::Liblist::ext = sub {
22 my ($class, $lib) = @_;
24 push @{ $self->libs }, $lib;
27 local *CORE::GLOBAL::exit = sub { };
28 local $INC{"Module/Build.pm"} = 1;
29 local @MyModuleBuilder::ISA = qw( Module::Build );
30 local *Module::Build::new = sub {
33 $self->requires( $args{requires} || {} );
34 $self->build_requires( $args{build_requires} || {} );
35 bless {}, "Module::Depends::Intrusive::Fake::Module::Build";
37 local *Module::Build::subclass = sub { 'Module::Build' };
38 local $Module::Build::VERSION = 666;
40 my $WriteMakefile = sub {
42 $self->requires( $args{PREREQ_PM} || {} );
45 local *main::WriteMakefile;
46 local *ExtUtils::MakeMaker::WriteMakefile = $WriteMakefile;
49 local $INC{"Inline/MakeMaker.pm"} = 1;
51 local @Inline::MakeMaker::EXPORT = qw( WriteMakefile WriteInlineMakefile );
52 local @Inline::MakeMaker::ISA = qw( Exporter );
53 local *Inline::MakeMaker::WriteMakefile = $WriteMakefile;
54 local *Inline::MakeMaker::WriteInlineMakefile = $WriteMakefile;
57 local $INC{"inc/Module/Install.pm"} = 1;
58 local @inc::Module::Install::ISA = qw( Exporter );
59 local @inc::Module::Install::EXPORT = qw(
61 all_from auto_install AUTOLOAD build_requires check_nmake include
62 include_deps installdirs Makefile makemaker_args Meta name no_index
63 requires WriteAll clean_files can_cc sign cc_inc_paths cc_files
64 cc_optimize_flags author license
67 local *inc::Module::Install::AUTOLOAD = sub { 1 };
68 local *inc::Module::Install::requires = sub {
69 my %deps = (@_ == 1 ? ( $_[0] => 0 ) : @_);
70 $self->requires->{ $_ } = $deps{ $_ } for keys %deps;
72 local *inc::Module::Install::include_deps = *inc::Module::Install::requires;
73 local *inc::Module::Install::build_requires = sub {
74 my %deps = (@_ == 1 ? ( $_[0] => 0 ) : @_);
75 $self->build_requires->{ $_ } = $deps{ $_ } for keys %deps;
78 my $file = File::Spec->catfile( getcwd(), $pl );
86 $self->error( $@ ) if $@;
91 package Module::Depends::Intrusive::Fake::Module::Build;
93 sub AUTOLOAD { shift }
95 my ($self, $question, $default) = @_;
97 return 1 if lc $default eq 'y';
98 return 0; # ok, we may say no when yes was intended, but we can't hang
107 Module::Depends::Intrusive - intrusive discovery of distribution dependencies.
111 # Just like Module::Depends, only use the Intrusive class instead
115 This module devines dependencies by running the distributions
116 Makefile.PL/Build.PL in a faked up environment and intercepting the
117 calls to Module::Build->new and ExtUtils::MakeMaker::WriteMakefile.
119 You may now freak out about security.
121 While you're doing that please remember that what we're doing is much
122 the same that CPAN.pm does in order to discover prerequisites.
126 Richard Clamp, based on code extracted from the Fotango build system
127 originally by James Duncan and Arthur Bergman.
131 Copyright 2004 Fotango. All Rights Reserved.
133 This module is free software; you can redistribute it and/or modify it
134 under the same terms as Perl itself.