3
# name: Module::Install::Package
4
# abstract: Module::Install support for Module::Package
5
# author: Ingy döt Net <ingy@cpan.org>
11
# This module contains the Module::Package logic that must be available to
12
# both the Author and the End User. Author-only logic goes in a
13
# Module::Package::Plugin subclass.
14
package Module::Install::Package;
16
use Module::Install::Base;
17
use vars qw'@ISA $VERSION';
18
@ISA = 'Module::Install::Base';
21
#-----------------------------------------------------------------------------#
23
# This is here to try to get us out of Module-Package-0.11 cpantesters hell...
24
# Remove this when the situation has blown over.
26
*inc::Module::Package::VERSION = sub { $VERSION };
28
$self->module_package_internals_init($@);
31
#-----------------------------------------------------------------------------#
32
# We allow the author to specify key/value options after the plugin. These
33
# options need to be available both at author time and install time.
34
#-----------------------------------------------------------------------------#
35
# OO accessor for command line options:
37
@_>1?($_[0]->{package_options}=$_[1]):$_[0]->{package_options}}
39
my $default_options = {
47
#-----------------------------------------------------------------------------#
48
# Module::Install plugin directives. Use long, ugly names to not pollute the
49
# Module::Install plugin namespace. These are only intended to be called from
51
#-----------------------------------------------------------------------------#
53
# Module::Package starts off life as a normal call to this Module::Install
55
my $module_install_plugin;
56
my $module_package_plugin;
57
# XXX ARGVHACK This @argv thing is a temporary fix for an ugly bug somewhere in the
58
# Wikitext module usage.
60
sub module_package_internals_init {
61
my $self = $module_install_plugin = shift;
62
my ($plugin_spec, %options) = @_;
63
$self->package_options({%$default_options, %options});
65
if ($module_install_plugin->is_admin) {
66
$module_package_plugin = $self->_load_plugin($plugin_spec);
67
$module_package_plugin->mi($module_install_plugin);
68
$module_package_plugin->version_check($VERSION);
70
# NOTE - This is the point in time where the body of Makefile.PL runs...
74
return unless $module_install_plugin;
75
return if $Module::Package::ERROR;
77
if ($module_install_plugin->is_admin) {
78
$module_package_plugin->initial();
79
$module_package_plugin->main();
82
$module_install_plugin->_initial();
83
$module_install_plugin->_main();
87
$Module::Package::ERROR = $@;
90
@argv = @ARGV; # XXX ARGVHACK
93
# If this Module::Install plugin was used (by Module::Package) then wrap
94
# up any loose ends. This will get called after Makefile.PL has completed.
96
@ARGV = @argv; # XXX ARGVHACK
97
return unless $module_install_plugin;
98
return if $Module::Package::ERROR;
99
$module_package_plugin
101
$module_package_plugin->final;
102
$module_package_plugin->replicate_module_package;
104
: $module_install_plugin->_final;
108
# Module::Package, Module::Install::Package and Module::Package::Plugin
109
# must all have the same version. Seems wise.
110
sub module_package_internals_version_check {
111
my ($self, $version) = @_;
112
return if $version < 0.1800001; # XXX BOOTBUGHACK!!
113
die <<"..." unless $version == $VERSION;
115
Error! Something has gone awry:
116
Module::Package version=$version is using
117
Module::Install::Package version=$VERSION
118
If you are the author of this module, try upgrading Module::Package.
119
Otherwise, please notify the author of this error.
124
# Find and load the author side plugin:
126
my ($self, $spec) = @_;
129
$Module::Package::plugin_version = 0;
130
if ($spec =~ s/\s+(\S+)\s*//) {
132
$Module::Package::plugin_version = $version;
134
my ($module, $plugin) =
135
not($spec) ? ('Plugin', "Plugin::basic") :
136
($spec =~ /^\w(\w|::)*$/) ? ($spec, $spec) :
137
($spec =~ /^:(\w+)$/) ? ('Plugin', "Plugin::$1") :
138
($spec =~ /^(\S*\w):(\w+)$/) ? ($1, "$1::$2") :
139
die "$spec is invalid";
140
$module = "Module::Package::$module";
141
$plugin = "Module::Package::$plugin";
142
eval "use $module $version (); 1" or die $@;
143
return $plugin->new();
146
#-----------------------------------------------------------------------------#
147
# These are the user side analogs to the author side plugin API calls.
148
# Prefix with '_' to not pollute Module::Install plugin space.
149
#-----------------------------------------------------------------------------#
158
# NOTE These must match Module::Package::Plugin::final.
162
$self->_requires_from;
164
$self->_install_share;
168
#-----------------------------------------------------------------------------#
169
# This section is where all the useful code bits go. These bits are needed by
170
# both Author and User side runs.
171
#-----------------------------------------------------------------------------#
176
return if $all_from++;
177
return if $self->name;
178
my $file = shift || "$main::PM" or die "all_from has no file";
179
$self->all_from($file);
182
my $requires_from = 0;
185
return if $requires_from++;
186
return unless $self->package_options->{requires_from};
187
my $file = shift || "$main::PM" or die "requires_from has no file";
188
$self->requires_from($main::PM)
194
return if $install_bin++;
195
return unless $self->package_options->{install_bin};
196
return unless -d 'bin';
198
File::Find::find(sub {
200
push @bin, $File::Find::name;
202
$self->install_script($_) for @bin;
205
my $install_share = 0;
208
return if $install_share++;
209
return unless $self->package_options->{install_share};
210
return unless -d 'share';
211
$self->install_share;
217
return if $WriteAll++;
221
#-----------------------------------------------------------------------------#
222
# Take a guess at the primary .pm and .pod files for 'all_from', and friends.
223
# Put them in global magical vars in the main:: namespace.
224
#-----------------------------------------------------------------------------#
225
package Module::Package::PM;
226
use overload '""' => sub {
227
$_[0]->guess_pm unless @{$_[0]};
230
sub set { $_[0]->[0] = $_[1] }
235
open META, 'META.yml' or die "Can't open 'META.yml' for input:\n$!";
236
my $meta = do { local $/; <META> };
238
$meta =~ /^module_name: (\S+)$/m
239
or die "Can't get module_name from META.yml";
247
File::Find::find(sub {
248
return unless /\.pm$/;
249
my $name = $File::Find::name;
250
my $num = ($name =~ s!/+!/!g);
251
my $ary = $array[$num] ||= [];
254
shift @array while @array and not defined $array[0];
255
die "Can't guess main module" unless @array;
256
(($pm) = sort @{$array[0]}) or
257
die "Can't guess main module";
260
$pm = $pmc if -e $pmc;
263
$main::PM = bless [$main::PM ? ($main::PM) : ()], __PACKAGE__;
265
package Module::Package::POD;
266
use overload '""' => sub {
267
return $_[0]->[0] if @{$_[0]};
268
(my $pod = "$main::PM") =~ s/\.pm/.pod/
269
or die "Module::Package's \$main::PM value should end in '.pm'";
270
return -e $pod ? $pod : '';
272
sub set { $_[0][0] = $_[1] }
273
$main::POD = bless [$main::POD ? ($main::POD) : ()], __PACKAGE__;