Dist-Zilla-Plugin-MungeFile-WithConfigFile
view release on metacpan or search on metacpan
lib/Dist/Zilla/Plugin/MungeFile/WithConfigFile.pm view on Meta::CPAN
use strict;
use warnings;
package Dist::Zilla::Plugin::MungeFile::WithConfigFile; # git description: v0.004-10-g4d7a072
# vim: set ts=8 sts=4 sw=4 tw=115 et :
# ABSTRACT: Modify files in the build, with templates and config data from a file
# KEYWORDS: plugin file content injection modification template configuration file
our $VERSION = '0.005';
use Moose;
extends 'Dist::Zilla::Plugin::MungeFile';
with 'MooseX::SimpleConfig';
use Path::Tiny;
use namespace::autoclean;
has configfile => (
is => 'ro', isa => 'Str',
required => 1,
);
has _config_data => (
is => 'ro', isa => 'HashRef',
lazy => 1,
default => sub {
my $self = shift;
$self->get_config_from_file(path($self->configfile)->absolute($self->zilla->root));
},
);
around dump_config => sub
{
my $orig = shift;
my $self = shift;
my $config = $self->$orig;
$config->{+__PACKAGE__} = {
configfile => $self->configfile,
blessed($self) ne __PACKAGE__ ? ( version => $VERSION ) : (),
};
return $config;
};
sub munge_file
{
my ($self, $file) = @_;
$self->next::method(
$file,
{ config_data => \($self->_config_data) },
);
}
__PACKAGE__->meta->make_immutable;
__END__
=pod
=encoding UTF-8
=head1 NAME
Dist::Zilla::Plugin::MungeFile::WithConfigFile - Modify files in the build, with templates and config data from a file
=head1 VERSION
version 0.005
=head1 SYNOPSIS
In your F<dist.ini>:
[MungeFile::WithConfigFile]
file = lib/My/Module.pm
house = maison
configfile = data.json
And during the build, F<lib/My/Module.pm>:
my $some_string = '{{ expensive_build_time_sub($config_data{some_field}) }}';
( run in 0.479 second using v1.01-cache-2.11-cpan-39bf76dae61 )