Skip to content

Commit

Permalink
Added get_default method to ModuleBuild::Custom
Browse files Browse the repository at this point in the history
  Added share_dir example
  Bump ModuleBuild::Custom version to 3.05
  • Loading branch information
madsen committed May 5, 2011
1 parent 2c39c07 commit 820b738
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 9 deletions.
3 changes: 3 additions & 0 deletions Changes
Original file line number Original file line Diff line number Diff line change
@@ -1,6 +1,9 @@
Revision history for Dist-Zilla-Plugins-CJM Revision history for Dist-Zilla-Plugins-CJM


3.05 NOT 3.05 NOT
Dist::Zilla::Plugin::ModuleBuild::Custom
- Added get_default method

Dist::Zilla::Plugin::TemplateCJM Dist::Zilla::Plugin::TemplateCJM
- Fix dependency_list to handle no dependencies - Fix dependency_list to handle no dependencies


Expand Down
66 changes: 57 additions & 9 deletions lib/Dist/Zilla/Plugin/ModuleBuild/Custom.pm
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ package Dist::Zilla::Plugin::ModuleBuild::Custom;
# ABSTRACT: Allow a dist to have a custom Build.PL # 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}}) # This file is part of {{$dist}} {{$dist_version}} ({{$date}})


=head1 DEPENDENCIES =head1 DEPENDENCIES
Expand Down Expand Up @@ -93,20 +93,30 @@ sub get_meta
my $self = shift; my $self = shift;


# Extract the wanted keys from distmeta: # 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; my %want;


foreach my $key (@_) { foreach my $key (@_) {
$self->log_debug("Fetching distmeta1 key $key"); $self->log_debug("Fetching $type key $key");
next unless defined $distmeta->{$key}; next unless defined $hash->{$key};


# Skip keys with empty value: # Skip keys with empty value:
my $reftype = reftype($distmeta->{$key}); my $reftype = reftype($hash->{$key});
if (not $reftype) {} if (not $reftype) {}
elsif ($reftype eq 'HASH') { next unless %{ $distmeta->{$key} } } elsif ($reftype eq 'HASH') { next unless %{ $hash->{$key} } }
elsif ($reftype eq 'ARRAY') { next unless @{ $distmeta->{$key} } } elsif ($reftype eq 'ARRAY') { next unless @{ $hash->{$key} } }


$want{$key} = $distmeta->{$key}; $want{$key} = $hash->{$key};
} # end foreach $key } # end foreach $key


# Format them for inclusion: # Format them for inclusion:
Expand All @@ -121,7 +131,8 @@ sub get_meta
} }


return $data; return $data;
} # end get_meta } # end _extract_keys

#--------------------------------------------------------------------- #---------------------------------------------------------------------


=method get_prereqs =method get_prereqs
Expand All @@ -144,6 +155,42 @@ sub get_prereqs
conflicts)); conflicts));
} # end 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 sub setup_installer
{ {
Expand Down Expand Up @@ -207,6 +254,7 @@ In your F<Build.PL>:
my $builder = Module::Build->new( my $builder = Module::Build->new(
module_name => 'Foo::Bar', module_name => 'Foo::Bar',
##{ $plugin->get_prereqs ##} ##{ $plugin->get_prereqs ##}
##{ $plugin->get_default('share_dir') ##}
); );
$builder->create_build_script; $builder->create_build_script;
Expand Down

0 comments on commit 820b738

Please sign in to comment.