Subject: | Plugin will be more useful if it save parameters for later use |
Plugin will be more useful if it saves parameters instead of throwing them away. Possible use case is:
There are few plugins which process templates (e. g. [GatherDir::Template], [GenerateFile], and may be some others. Template is plain text with perl code injections, usually enclosed into double braces {{ ... }}. Within perl code, $dist is a reference to Dist::Zilla object, so using $dist it is possible to reach any plugin (including this one) and retrieve its parameters, e. g.:
In dist.ini:
[Extras]
Name1 = Value1
Name2 = Value2
In template:
some text {{ my ( $extras ) = grep( $_->plugin_name eq 'Extras', $dist->plugins ); $extras->args->{ Name 1 }; }}
Subject: | patch.diff |
diff --git a/lib/Dist/Zilla/Plugin/Extras.pm b/lib/Dist/Zilla/Plugin/Extras.pm
index 2a2927b..bddffda 100644
--- a/lib/Dist/Zilla/Plugin/Extras.pm
+++ b/lib/Dist/Zilla/Plugin/Extras.pm
@@ -6,6 +6,11 @@ with 'Dist::Zilla::Role::Plugin';
use namespace::autoclean;
+has args => (
+ is => 'ro',
+ default => sub { {}; },
+);
+
sub BUILDARGS {
my ($class, @arg) = @_;
my %copy = ref $arg[0] ? %{$arg[0]} : @arg;
@@ -16,6 +21,7 @@ sub BUILDARGS {
return {
zilla => $zilla,
plugin_name => $name,
+ args => \%copy,
}
}