| 1 | package Dist::Zilla::Plugin::TemplateFiles; | ||
| 2 | # ABSTRACT: Use files to template a distribution | ||
| 3 | $Dist::Zilla::Plugin::TemplateFiles::VERSION = '0.03'; | ||
| 4 | use Moose; | ||
| 5 | use Moose::Autobox; | ||
| 6 | use namespace::autoclean; | ||
| 7 | |||
| 8 | with qw/ | ||
| 9 | Dist::Zilla::Role::FileMunger | ||
| 10 | Dist::Zilla::Role::TextTemplate | ||
| 11 | /; | ||
| 12 | |||
| 13 | # Don't ask me, I just copied from | ||
| 14 | sub mvp_multivalue_args { qw/ filename / } | ||
| 15 | |||
| 16 | has filename => ( | ||
| 17 | is => 'rw', | ||
| 18 | isa => 'ArrayRef', | ||
| 19 | ); | ||
| 20 | |||
| 21 | my %files; | ||
| 22 | |||
| 23 | sub munge_file { | ||
| 24 | my ($self,$file) = @_; | ||
| 25 | unless (%files) { | ||
| 26 | for my $filename (@{$self->filename}) { | ||
| 27 | $files{$filename} = 1; | ||
| 28 | } | ||
| 29 | } | ||
| 30 | return unless $files{$file->name}; | ||
| 31 | my $content = $self->fill_in_string( $file->content, { plugin => \$self, dist => \($self->zilla) } ); | ||
| 32 | $file->content( $content ) if defined $content; | ||
| 33 | } | ||
| 34 | |||
| 35 | __PACKAGE__->meta->make_immutable; | ||
| 36 | |||
| 37 | 1; | ||
| 38 | |||
| 39 | __END__ |