1# See lib/ExtUtils/MakeMaker.pm for details of how to influence
2# the contents of the Makefile that is written.
3
4use 5.006; #weak references require perl 5.6
5use strict;
6use ExtUtils::MakeMaker;
7use diagnostics;
8
9my @PREREQS = (
10#   ["<feature>","<installed module>",<dependency hash>,<install by default, 2=always>];
11    [
12        "Core Package",
13        "SOAP::Lite",
14        {
15          "Test::More"      => 0,
16          "XML::Parser"     => "2.23",
17          "MIME::Base64"    => 0,
18          "URI"             => 0,
19          "Scalar::Util"    => 0,
20          "Task::Weaken"    => 0, #to be sure than weaken works (Scalar::Util has XS part)
21          "constant"        => 0, #don't force people to upgrade
22          "Class::Inspector" => 0,
23        },
24        2
25    ],
26    [
27        "Client HTTP support",
28        "SOAP::Transport::HTTP",
29        {
30            "LWP::UserAgent" => 0
31        },
32        2
33    ],
34    ["Client HTTPS support","SOAP::Transport::HTTPS::Client",{"Crypt::SSLeay" => 0},0],
35    ["Client SMTP/sendmail support","SOAP::Transport::MAILTO::Client",{"MIME::Lite" => 0},1],
36    ["Client FTP support","SOAP::Transport::FTP::Client",{"SOAP::Transport::FTP" => 0.711},0],
37    ["Client TCP support","SOAP::Transport::TCP::Client",{"SOAP::Transport::TCP" => 0.714},0],
38    ["Standalone HTTP server","SOAP::Transport::HTTP::Daemon",{"HTTP::Daemon" => 0},1],
39    ["Apache/mod_perl server","SOAP::Transport::HTTP::Apache",{"Apache" => 0},0],
40    ["FastCGI server","SOAP::Transport::HTTP::FCGI",{"FCGI" => 0},0],
41    ["POP3 server","SOAP::Transport::POP3::Server",{"Net::POP3" => 0,"MIME::Parser" => 0},1],
42    ["IO server","SOAP::Transport::IO::Server",{"IO::File" => 0},0],
43    ["MQ transport support","SOAP::Transport::MQ",{"SOAP::Transport::MQ" => 0.712},0],
44    ["JABBER transport support","SOAP::Transport::JABBER",{"SOAP::Transport::JABBER" => 0.712},0],
45    ["MIME messages","SOAP::Packager::MIME",{"MIME::Parser" => 0},1],
46    ["DIME messages","SOAP::Packager::DIME",{"IO::Scalar" => "2.105", "DIME::Tools" => 0.03, "Data::UUID" => "0.11"},0],
47    ["SSL Support for TCP Transport","SOAP::Transport::TCP",{"IO::Socket::SSL" => 0},0],
48    ["Compression support for HTTP","SOAP::Transport::HTTP",{"Compress::Zlib" => 0},0],
49    ["MIME interoperability w/ Axis","SOAP::Lite",{"MIME::Parser" => "6.106"},0],
50);
51
52use Getopt::Long;
53
54my $helptext = <<EOI;
55Usage: perl Makefile.PL <options>
56
57Possible options are:
58
59  --noprompt            Disable interactive dialog
60  --help, -?            Display this help text
61
62  [Do not] install prerequisites for appropriate module:
63
64EOI
65
66# Create config parameters using module names and expand help text
67# We will create a hash (%config) that has each module => (1|0) for install
68my(%options, %config, %has_module_cache);
69
70# Initialize the prereq table and all help text
71foreach my $prereq (@PREREQS) {
72    my ($feature,$dep,$modules,$default) = @$prereq;
73    next unless $dep ne "";
74    $prereq->[3] = has_all_modules($modules) unless $prereq->[3] == 2;
75
76    my $module = do { $dep =~ s/::/-/g; $dep };
77    my $shortcut = do { (my $t = $module) =~ s/SOAP-(?:Transport-)?//; $t };
78    $config{$dep} = has_all_modules($modules);
79    $options{"install-$dep|$shortcut!"} = \$config{$dep};
80    $helptext .= sprintf "  --[no]install-%-28s --[no]%s\n", $dep, $shortcut;
81}
82
83use vars qw($noprompt $alltests $help $intro);
84#my ($noprompt,$alltests,$help);
85
86GetOptions (
87    "noprompt" => \$noprompt,
88    "help|?" => \$help,
89);
90
91# don't prompt when run on a smoke test system.
92# See http://cpantest.grango.org/wiki/CPANAuthorNotes
93# Thanks to Andreas J Koenig && all CPAN testers !
94$noprompt++ if $ENV{AUTOMATED_TESTING};
95
96$help and print($helptext), exit;
97
98$intro = <<EOI;
99We are about to install SOAP::Lite and for your convenience will provide
100you with list of modules and prerequisites, so you'll be able to choose
101only modules you need for your configuration.
102
103XMLRPC::Lite, UDDI::Lite, and XML::Parser::Lite are included by default.
104Installed transports can be used for both SOAP::Lite and XMLRPC::Lite.
105
106EOI
107
108if ($noprompt) {
109    print "These are the modules that will get installed:\n\n";
110} else {
111    ExtUtils::MakeMaker::prompt($intro . "Press <enter> to see the detailed list.");
112}
113
114# This hash will contain a list of all perl modules we would like to
115# explicitly depend upon in our Makefile
116my %prereqs;
117my $proceed = 0;
118do {
119    print "\n".generate_prereq_table()."\n";
120    # Ask the user if this is the configuration they desire
121    if ($noprompt) {
122        $proceed = 1;
123    } else {
124        $proceed = ExtUtils::MakeMaker::prompt("Do you want to proceed with this configuration?" => 'yes') =~ /^\s*y/i;
125    }
126    # Loop through each prerequisite and ask the user if they wish to
127    # install it or not - reset prereqs, cause they change each time
128    %prereqs = ();
129    for my $prereq (@PREREQS) {
130        my ($feature,$dep,$modules,$default) = @$prereq;
131        next unless $dep ne "";
132        unless ($proceed || $prereq->[3] == 2) { # need to use $prereq, because we modify actual value
133            $prereq->[3] = (ExtUtils::MakeMaker::prompt("Do you plan to use ${feature}?" => ($prereq->[3] ? 'yes' : 'no')) =~ /^\s*(y)/i);
134        }
135        (%prereqs = (%prereqs, map { $_,$modules->{$_} } keys %$modules)) if $prereq->[3];
136    }
137} while (!$proceed);
138
139
140# Old way of selecting tests - replaced by extended test suite in
141# subdirectories...
142# my $tests = join ' ', glob ($noncoretests ? 't/*.t' : 't/0*.t');
143
144# Additional tests require Test::More
145# only run noncoretests if we have Test::More
146my $noncoretests;
147if (eval { require Test::More; }) {
148    $noncoretests++;
149}
150
151my $tests;
152if ($noncoretests) {
153    my @test_from = ();
154    require File::Find;
155    File::Find::find(sub {
156            return if -d $_;
157            return if $_ !~m{\.t$}x;
158            return if $File::Find::dir=~m{\bCVS\b};
159            return if $File::Find::dir=~m{\b\.svn\b};
160            return if $_=~m{^[1-9]}x;
161            push @test_from, $File::Find::name;
162        }, 't/'
163    );
164    $tests = join ' ' , @test_from;
165}
166else {
167    $tests = join ' ', glob ('t/0*.t t/*xmlparserlite.t t/*loopback.t');
168}
169
170ExtUtils::MakeMaker::WriteMakefile(
171    'NAME'          => 'SOAP::Lite',
172    'AUTHOR'        =>  'Pavel Kulchenko, Randy J Ray, Byrne Reese, Martin Kutter (MKUTTER@cpan.org)',
173    'LICENSE'       => 'perl',
174    'VERSION_FROM'  => 'lib/SOAP/Lite.pm',
175    'ABSTRACT_FROM' => 'lib/SOAP/Lite.pm',
176    'PREREQ_PM'     => {
177        %prereqs
178     },
179    'EXE_FILES'     => ['bin/SOAPsh.pl', 'bin/XMLRPCsh.pl', 'bin/stubmaker.pl'],
180    test            => {TESTS => $tests},
181    ($ExtUtils::MakeMaker::VERSION ge '6.48'?
182     (MIN_PERL_VERSION => 5.006,
183      META_MERGE => {
184          resources=> {
185              repository => 'https://soaplite.svn.sourceforge.net/svnroot/soaplite/branches/0.71',
186          },
187          keywords => ['SOAP','SOAP client','SOAP server'],
188          bugtracker => 'https://sourceforge.net/tracker/?group_id=66000&atid=513017',
189
190      },
191     ) : ()),
192);
193
194
195######################################################
196# Supporting subroutines
197######################################################
198# Maintains a cache of what 3rd party modules you have
199# installed
200sub has_module {
201    my ($mod, $version) = @_;
202    $version ||= '';
203    # use "require Foo; Exporter::require_version('Foo' => 1)" instead of
204    # obvious "use Foo 1". The later doesn't work with MIME::Parser
205    # wonder why? --PK
206    return ($has_module_cache{"$mod$version"}
207        ||= eval("require $mod; Exporter::require_version('$mod', $version) if ($version); 1"));
208}
209
210# Return 1 if all modules contained in the inputed array
211# are installed, 0 otherwise
212sub has_all_modules {
213    my ($mods) = @_;
214    foreach my $mod (keys %$mods) {
215        return 0 if !has_module($mod, $mods->{$mod});
216    }
217    return 1;
218}
219
220# Print a single prerequisite to the screen
221sub generate_prereq {
222    my ($feature,$dep,$modules,$install) = @_;
223    my $i = 0;
224    my $buf = "";
225    foreach my $module (keys %$modules) {
226        my $detected = (has_module($module, $modules->{$module}) ? "*" : " ");
227        $buf .= sprintf("%-29s [%s] %-24s %-8s\n",($i++ ? "" : $feature),$detected,$module . ($modules->{$module} ? " (v$modules->{$module})" : ""),($i == 1 ? ($install ? ($install == 2 ? "always" : "[ yes ]") : "[ no ]") : ""));
228    }
229    return $buf;
230}
231
232# Print the entire prerequisites table
233sub generate_prereq_table {
234    my $buf = sprintf("%-29s %-28s %-8s\n","Feature","Prerequisites","Install?");
235    $buf .= sprintf("%s %s %s\n","-" x 29,"-" x 28,"-" x 8);
236    foreach my $pre (@PREREQS) {
237        my ($feature,$dep,$modules,$default) = @{$pre};
238        $buf .= generate_prereq(@{$pre});
239    }
240    $buf .= "--- An asterix '[*]' indicates if the module is currently installed.\n";
241    return $buf;
242}
243
2441;
245