10 | 10 |
use Getopt::Long 0 ();
|
11 | 11 |
use Test::Harness 0 ();
|
12 | 12 |
use Tie::File 0 ();
|
|
13 |
use Text::ParseWords 0 ();
|
13 | 14 |
our $VERSION = '0.01';
|
14 | 15 |
|
15 | 16 |
my %re = (
|
|
24 | 25 |
|
25 | 26 |
my %install_base = ( lib => [qw/lib perl5/], script => [qw/lib bin/] );
|
26 | 27 |
|
27 | |
my @opts_spec = (
|
28 | |
'install_base:s','uninst:i'
|
29 | |
);
|
|
28 |
my @opts_spec = ( 'install_base:s', 'uninst:i' );
|
|
29 |
|
|
30 |
sub _split_like_shell {
|
|
31 |
my $string = shift;
|
|
32 |
$string =~ s/^\s+|\s+$//g;
|
|
33 |
return Text::ParseWords::shellwords($string);
|
|
34 |
}
|
|
35 |
|
|
36 |
sub _home { return $ENV{HOME} || $ENV{USERPROFILE} }
|
|
37 |
|
|
38 |
sub _default_rc { return File::Spec->catfile( _home(), '.modulebuildrc' ) }
|
|
39 |
|
|
40 |
sub _get_rc_opts {
|
|
41 |
my $rc_file = ($ENV{MODULEBUILDRC} || _default_rc());
|
|
42 |
return {} unless -f $rc_file;
|
|
43 |
my $guts = _slurp( $rc_file );
|
|
44 |
$guts =~ s{\n[ \t]+}{ }mg; # join lines with leading whitespace
|
|
45 |
$guts =~ s{^#.*$}{}mg; # strip comments
|
|
46 |
$guts =~ s{\n\s*\n}{\n}mg; # empty lines
|
|
47 |
my %opt = map { my ($k,$v) = $_ =~ /(\S+)\s+(.*)/; $k => $v }
|
|
48 |
grep { /\S/ } split /\n/, $guts;
|
|
49 |
return \%opt;
|
|
50 |
}
|
|
51 |
|
|
52 |
sub _get_options {
|
|
53 |
my ($action,$opt) = @_;
|
|
54 |
my $rc_opts = _get_rc_opts;
|
|
55 |
for my $s ( $ENV{PERL_MB_OPT}, $rc_opts->{$action}, $rc_opts->{'*'} ) {
|
|
56 |
unshift @ARGV, _split_like_shell($s) if defined $s && length $s;
|
|
57 |
}
|
|
58 |
Getopt::Long::GetOptions($opt, @opts_spec);
|
|
59 |
}
|
30 | 60 |
|
31 | 61 |
sub run {
|
32 | 62 |
my $opt = eval { do '_build/build_params' } || {};
|
33 | |
Getopt::Long::GetOptions($opt, @opts_spec);
|
34 | |
my $action = shift(@ARGV) || 'build';
|
|
63 |
my $action = $ARGV[0] =~ /\A\w+\z/ ? $ARGV[0] : 'build';
|
|
64 |
_get_options($action, $opt);
|
35 | 65 |
__PACKAGE__->can($action)->(%$opt) or exit 1;
|
36 | 66 |
}
|
37 | 67 |
|
|
41 | 71 |
}
|
42 | 72 |
|
43 | 73 |
sub import {
|
44 | |
Getopt::Long::GetOptions((my $opt={}), @opts_spec);
|
|
74 |
_get_options('Build_PL', my $opt = {});
|
45 | 75 |
my @f = _files('lib');
|
46 | 76 |
my $meta = {
|
47 | 77 |
name => _mod2dist(_path2mod($f[0])),
|
|
223 | 253 |
|
224 | 254 |
=head2 Supported
|
225 | 255 |
|
226 | |
* Pure purl distributions
|
|
256 |
* Pure Perl distributions
|
227 | 257 |
* Recursive test files
|
228 | 258 |
* Automatic 'requires' and 'build_requires' detection (see below)
|
229 | 259 |
* Automatic MANIFEST generation
|
230 | 260 |
* Automatic MANIFEST.SKIP generation (if not supplied)
|
231 | 261 |
* Automatically bundles itself in inc/
|
|
262 |
* MYMETA
|
232 | 263 |
|
233 | 264 |
=head2 Not Supported
|
234 | 265 |
|
|
302 | 333 |
|
303 | 334 |
=head1 CONFIG FILE AND ENVIRONMENT
|
304 | 335 |
|
305 | |
Not yet supported.
|
|
336 |
Options can be provided in a F<.modulebuildrc> file or in the C<PERL_MB_OPT>
|
|
337 |
environment variable the same way they can with Module::Build.
|
306 | 338 |
|
307 | 339 |
=head1 SEE ALSO
|
308 | 340 |
|