Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added get_default method to ModuleBuild::Custom

  Added share_dir example
  Bump ModuleBuild::Custom version to 3.05
  • Loading branch information...
commit 820b7382388de4eff623bc7f70b99b77984e8ea5 1 parent 2c39c07
@madsen authored
Showing with 60 additions and 9 deletions.
  1. +3 −0  Changes
  2. +57 −9 lib/Dist/Zilla/Plugin/ModuleBuild/Custom.pm
View
3  Changes
@@ -1,6 +1,9 @@
Revision history for Dist-Zilla-Plugins-CJM
3.05 NOT
+ Dist::Zilla::Plugin::ModuleBuild::Custom
+ - Added get_default method
+
Dist::Zilla::Plugin::TemplateCJM
- Fix dependency_list to handle no dependencies
View
66 lib/Dist/Zilla/Plugin/ModuleBuild/Custom.pm
@@ -17,7 +17,7 @@ package Dist::Zilla::Plugin::ModuleBuild::Custom;
# ABSTRACT: Allow a dist to have a custom Build.PL
#---------------------------------------------------------------------
-our $VERSION = '3.01';
+our $VERSION = '3.05';
# This file is part of {{$dist}} {{$dist_version}} ({{$date}})
=head1 DEPENDENCIES
@@ -93,20 +93,30 @@ sub get_meta
my $self = shift;
# Extract the wanted keys from distmeta:
- my $distmeta = $self->distmeta1;
+ return $self->_extract_keys(distmeta1 => $self->distmeta1, @_);
+} # end get_meta
+#---------------------------------------------------------------------
+
+sub _extract_keys
+{
+ my $self = shift;
+ my $type = shift;
+ my $hash = shift;
+
+ # Extract the wanted keys from the hash:
my %want;
foreach my $key (@_) {
- $self->log_debug("Fetching distmeta1 key $key");
- next unless defined $distmeta->{$key};
+ $self->log_debug("Fetching $type key $key");
+ next unless defined $hash->{$key};
# Skip keys with empty value:
- my $reftype = reftype($distmeta->{$key});
+ my $reftype = reftype($hash->{$key});
if (not $reftype) {}
- elsif ($reftype eq 'HASH') { next unless %{ $distmeta->{$key} } }
- elsif ($reftype eq 'ARRAY') { next unless @{ $distmeta->{$key} } }
+ elsif ($reftype eq 'HASH') { next unless %{ $hash->{$key} } }
+ elsif ($reftype eq 'ARRAY') { next unless @{ $hash->{$key} } }
- $want{$key} = $distmeta->{$key};
+ $want{$key} = $hash->{$key};
} # end foreach $key
# Format them for inclusion:
@@ -121,7 +131,8 @@ sub get_meta
}
return $data;
-} # end get_meta
+} # end _extract_keys
+
#---------------------------------------------------------------------
=method get_prereqs
@@ -145,6 +156,42 @@ sub get_prereqs
} # end get_prereqs
#---------------------------------------------------------------------
+
+=method get_default
+
+ $plugin->get_default(qw(key1 key2 ...))
+
+A template can call this method to extract the specified key(s) from
+the default Module::Build arguments created by the normal ModuleBuild
+plugin and have them formatted into a comma-separated list suitable
+for a hash constructor or a method's parameter list.
+
+If any key has no value (or its value is an empty hash or array ref)
+it will be omitted from the list. If all keys are omitted, the empty
+string is returned. Otherwise, the result always ends with a comma.
+
+The most common usage would be
+
+ ##{ $plugin->get_default('share_dir') ##}
+
+=cut
+
+has _default_mb_args => (
+ is => 'ro',
+ isa => 'HashRef',
+ init_arg => undef,
+ lazy => 1,
+ builder => 'module_build_args',
+);
+
+sub get_default
+{
+ my $self = shift;
+
+ return $self->_extract_keys(module_build => $self->_default_mb_args, @_);
+} # end get_default
+
+#---------------------------------------------------------------------
sub setup_installer
{
my $self = shift;
@@ -207,6 +254,7 @@ In your F<Build.PL>:
my $builder = Module::Build->new(
module_name => 'Foo::Bar',
##{ $plugin->get_prereqs ##}
+ ##{ $plugin->get_default('share_dir') ##}
);
$builder->create_build_script;

0 comments on commit 820b738

Please sign in to comment.
Something went wrong with that request. Please try again.