File Coverage

blib/lib/Dist/Zilla/Role/PluginBundle/Config/Slicer.pm
Criterion Covered Total %
statement 12 12 100.0
branch n/a
condition n/a
subroutine 4 4 100.0
pod n/a
total 16 16 100.0


line stmt bran cond sub pod time code
1             # vim: set ts=2 sts=2 sw=2 expandtab smarttab:
2             #
3             # This file is part of Dist-Zilla-Config-Slicer
4             #
5             # This software is copyright (c) 2011 by Randy Stauner.
6             #
7             # This is free software; you can redistribute it and/or modify it under
8             # the same terms as the Perl 5 programming language system itself.
9             #
10 2     2   397213 use strict;
  2         7  
  2         65  
11 2     2   40 use warnings;
  2         6  
  2         133  
12              
13             package Dist::Zilla::Role::PluginBundle::Config::Slicer;
14             our $AUTHORITY = 'cpan:RWSTAUNER';
15             # ABSTRACT: Pass Portions of Bundle Config to Plugins
16             $Dist::Zilla::Role::PluginBundle::Config::Slicer::VERSION = '0.202';
17 2     2   632 use Dist::Zilla::Config::Slicer ();
  2         8  
  2         63  
18 2     2   44 use Moose::Role;
  2         5  
  2         15  
19              
20             requires 'bundle_config';
21              
22             # TODO: around add_bundle => sub { ($self, $bundle, $payload) = @_; $slicer->merge([$bundle, _bundle_class($bundle), $payload || {}]);
23              
24             around bundle_config => sub {
25             my ($orig, $class, $section) = @_;
26              
27             my @plugins = $orig->($class, $section);
28              
29             my $slicer = Dist::Zilla::Config::Slicer->new({
30             config => $section->{payload},
31             });
32              
33             $slicer->merge($_) for @plugins;
34              
35             return @plugins;
36             };
37              
38             1;
39              
40             __END__
41              
42             =pod
43              
44             =encoding UTF-8
45              
46             =for :stopwords Randy Stauner ACKNOWLEDGEMENTS
47              
48             =head1 NAME
49              
50             Dist::Zilla::Role::PluginBundle::Config::Slicer - Pass Portions of Bundle Config to Plugins
51              
52             =head1 VERSION
53              
54             version 0.202
55              
56             =head1 SYNOPSIS
57              
58             # in Dist::Zilla::PluginBundle::MyBundle
59              
60             with (
61             'Dist::Zilla::Role::PluginBundle', # or PluginBundle::Easy
62             'Dist::Zilla::Role::PluginBundle::Config::Slicer'
63             );
64              
65             # Config::Slicer should probably be last
66             # (unless you're doing something more complex)
67              
68             =head1 DESCRIPTION
69              
70             This role enables your L<Dist::Zilla> Plugin Bundle
71             to accept configuration customizations for the plugins it will load
72             and merge them transparently.
73              
74             # dist.ini
75             [@MyBundle]
76             option = 1
77             Included::Plugin.attribute = overwrite value
78             AnotherPlug.array[0] = append value
79             AnotherPlug.array[1] = append another value
80              
81             See L<Config::MVP::Slicer/CONFIGURATION SYNTAX> for details
82             on how the configurations are handled.
83              
84             This role adds a method modifier to C<bundle_config>,
85             which is the method that the root C<PluginBundle> role requires,
86             and that C<PluginBundle::Easy> wraps.
87              
88             After C<bundle_config> is called
89             the modifier will update the returned plugin configurations
90             with any values that were customized in the main bundle config.
91              
92             Most of the work is done by L<Dist::Zilla::Config::Slicer>
93             (a subclass of L<Config::MVP::Slicer>).
94             Check out those modules if you want the same functionality
95             but don't want to consume this role in your bundle.
96              
97             =head1 SEE ALSO
98              
99             =over 4
100              
101             =item *
102              
103             L<Config::MVP::Slicer>
104              
105             =item *
106              
107             L<Dist::Zilla>
108              
109             =item *
110              
111             L<Dist::Zilla::Config::Slicer>
112              
113             =item *
114              
115             L<Dist::Zilla::Role::PluginBundle>
116              
117             =item *
118              
119             L<Dist::Zilla::Role::PluginBundle::Easy>
120              
121             =item *
122              
123             L<Dist::Zilla::PluginBundle::ConfigSlicer>
124              
125             =back
126              
127             =head1 AUTHOR
128              
129             Randy Stauner <rwstauner@cpan.org>
130              
131             =head1 COPYRIGHT AND LICENSE
132              
133             This software is copyright (c) 2011 by Randy Stauner.
134              
135             This is free software; you can redistribute it and/or modify it under
136             the same terms as the Perl 5 programming language system itself.
137              
138             =cut