Dist::Zilla::Plugin::MungeFile::WithData - Modify files in the build, with templates and DATA section
version 0.001
In your dist.ini:
[MungeFile::WithData] finder = :MainModule
And during the build, lib/My/Module.pm:
my @stuff = qw( {{ join " \n", map { expensive_build_time_sub($_) } split(' ', $DATA) # awk-style whitespace splitting }} ); __DATA__ alpha beta gamma
Is transformed to:
my @stuff = qw( SOMETHING_WITH_ALPHA SOMETHING_WITH_BETA SOMETHING_WITH_GAMMA );
This is a FileMunger plugin for Dist::Zilla that passes the main module through a Text::Template, with a variable provided that contain the content from the file's __DATA__ section.
FileMunger
__DATA__
Text::Template is used to transform the file by making the $DATA variable available to all code blocks within {{ }} sections.
$DATA
{{ }}
The module being transformed is loaded first, before the template content is transformed, in order to extract the __DATA__ section. While it would seem that the module will not compile in this state, it is possible to craft the file content in order to allow the file to parse (e.g. see Acme::CPANAuthors::Nonhuman version 0.005).
This is a wacky idea though (ether discovered she could be clever! What fun!) and this will not be a permanent feature of this plugin - in the future it is intended that the __DATA__ section will instead be extracted by scanning the file for qr/^__DATA__$/.
qr/^__DATA__$/
This is not the feature set that is intended to be provided by this plugin. Use with discretion until the interface and features have stabilized!
finder
This is the name of a FileFinder for finding files to modify.
Other pre-defined finders are listed in FileFinder. You can define your own with the Dist::Zilla::Plugin::FileFinder::ByName plugin.
The default is :MainModule.
:MainModule
This module was originally a part of the Acme::CPANAuthors::Nonhuman distribution, used to transform a DATA section containing a list of PAUSE ids to their corresponding names, as well as embedded HTML with everyone's avatar images.
DATA
Bugs may be submitted through the RT bug tracker (or bug-Dist-Zilla-Plugin-MungeFile::WithData@rt.cpan.org). I am also usually active on irc, as 'ether' at irc.perl.org.
irc.perl.org
Dist::Zilla::Plugin::Substitute
Dist::Zilla::Plugin::TemplateFiles
Karen Etheridge <ether@cpan.org>
This software is copyright (c) 2013 by Karen Etheridge.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
To install Dist::Zilla::Plugin::MungeFile::WithData, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Dist::Zilla::Plugin::MungeFile::WithData
CPAN shell
perl -MCPAN -e shell install Dist::Zilla::Plugin::MungeFile::WithData
For more information on module installation, please visit the detailed CPAN module installation guide.