Codebase list libmodule-build-tiny-perl / 422d4da
add support for config file and PERL_MB_OPT David Golden 14 years ago
2 changed file(s) with 48 addition(s) and 9 deletion(s). Raw diff Collapse all Expand all
00 Revision history for Acme::Module::Build::Tiny
11
2 0.01 Under development
2 0.02 - Tue Mar 23 15:20:19 EDT 2010
33
4 - Add support for .modulebuildrc and PERL_MB_OPT so it works
5 with local::lib
6
7 0.01 - Tue Mar 23 14:21:29 EDT 2010
8
9 - First release
10
1010 use Getopt::Long 0 ();
1111 use Test::Harness 0 ();
1212 use Tie::File 0 ();
13 use Text::ParseWords 0 ();
1314 our $VERSION = '0.01';
1415
1516 my %re = (
2425
2526 my %install_base = ( lib => [qw/lib perl5/], script => [qw/lib bin/] );
2627
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 }
3060
3161 sub run {
3262 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);
3565 __PACKAGE__->can($action)->(%$opt) or exit 1;
3666 }
3767
4171 }
4272
4373 sub import {
44 Getopt::Long::GetOptions((my $opt={}), @opts_spec);
74 _get_options('Build_PL', my $opt = {});
4575 my @f = _files('lib');
4676 my $meta = {
4777 name => _mod2dist(_path2mod($f[0])),
223253
224254 =head2 Supported
225255
226 * Pure purl distributions
256 * Pure Perl distributions
227257 * Recursive test files
228258 * Automatic 'requires' and 'build_requires' detection (see below)
229259 * Automatic MANIFEST generation
230260 * Automatic MANIFEST.SKIP generation (if not supplied)
231261 * Automatically bundles itself in inc/
262 * MYMETA
232263
233264 =head2 Not Supported
234265
302333
303334 =head1 CONFIG FILE AND ENVIRONMENT
304335
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.
306338
307339 =head1 SEE ALSO
308340