Debian lenny version packages
[pkg-perl] / deb-src / libmodule-depends-perl / libmodule-depends-perl-0.14 / lib / Module / Depends / Intrusive.pm
1 use strict;
2 package Module::Depends::Intrusive;
3 use base qw( Module::Depends );
4 use Cwd qw( getcwd );
5 use ExtUtils::MakeMaker ();
6
7 sub _find_modules {
8     my $self = shift;
9
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;
13     unless ($pl) {
14         $self->error( 'No {Build,Makefile}.PL found in '.$self->dist_dir );
15         return $self;
16     }
17
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) = @_;
23         $lib =~ s/\-l//;
24         push @{ $self->libs }, $lib;
25         return 1;
26     };
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 {
31         my $class = shift;
32         my %args =  @_;
33         $self->requires( $args{requires} || {} );
34         $self->build_requires( $args{build_requires} || {} );
35         bless {}, "Module::Depends::Intrusive::Fake::Module::Build";
36     };
37     local *Module::Build::subclass = sub { 'Module::Build' };
38     local $Module::Build::VERSION = 666;
39
40     my $WriteMakefile = sub {
41         my %args = @_;
42         $self->requires( $args{PREREQ_PM} || {} );
43         1;
44     };
45     local *main::WriteMakefile;
46     local *ExtUtils::MakeMaker::WriteMakefile = $WriteMakefile;
47
48     # Inline::MakeMaker
49     local $INC{"Inline/MakeMaker.pm"} = 1;
50
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;
55
56     # Module::Install
57     local $INC{"inc/Module/Install.pm"} = 1;
58     local @inc::Module::Install::ISA = qw( Exporter );
59     local @inc::Module::Install::EXPORT = qw(
60
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
65
66     );
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;
71     };
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;
76     };
77
78     my $file = File::Spec->catfile( getcwd(), $pl );
79     eval {
80         package main;
81         no strict;
82         no warnings;
83         local $0 = $file;
84         require "$file";
85     };
86     $self->error( $@ ) if $@;
87     delete $INC{$file};
88     return $self;
89 }
90
91 package Module::Depends::Intrusive::Fake::Module::Build;
92 sub DESTROY {}
93 sub AUTOLOAD { shift }
94 sub y_n {
95     my ($self, $question, $default) = @_;
96     $default ||= 'n';
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
99 }
100
101 1;
102
103 __END__
104
105 =head1 NAME
106
107 Module::Depends::Intrusive - intrusive discovery of distribution dependencies.
108
109 =head1 SYNOPSIS
110
111  # Just like Module::Depends, only use the Intrusive class instead
112
113 =head1 DESCRIPTION
114
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.
118
119 You may now freak out about security.
120
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.
123
124 =head1 AUTHOR
125
126 Richard Clamp, based on code extracted from the Fotango build system
127 originally by James Duncan and Arthur Bergman.
128
129 =head1 COPYRIGHT
130
131 Copyright 2004 Fotango.  All Rights Reserved.
132
133 This module is free software; you can redistribute it and/or modify it
134 under the same terms as Perl itself.
135
136 =head1 SEE ALSO
137
138 L<Module::Depends>
139
140 =cut