File Coverage

lib/Dist/Zilla/PluginBundle/Code.pm
Criterion Covered Total %
statement 22 22 100.0
branch n/a
condition n/a
subroutine 7 7 100.0
pod 0 1 0.0
total 29 30 96.6


line stmt bran cond sub pod time code
1             package Dist::Zilla::PluginBundle::Code;
2              
3 2     2   1972 use 5.006;
  2         10  
4 2     2   10 use strict;
  2         7  
  2         43  
5 2     2   10 use warnings;
  2         4  
  2         113  
6              
7             our $VERSION = '0.007';
8              
9 2     2   559 use Moose;
  2         448937  
  2         13  
10 2     2   14282 use namespace::autoclean;
  2         15  
  2         17  
11              
12             with 'Dist::Zilla::Role::PluginBundle';
13              
14 2     2   829 use MooseX::Types::Moose qw(CodeRef HashRef Str);
  2         54833  
  2         17  
15              
16             has bundle_config => (
17             is => 'ro',
18             isa => CodeRef,
19             reader => '_bundle_config',
20             required => 1,
21             );
22              
23             has name => (
24             is => 'ro',
25             isa => Str,
26             required => 1,
27             );
28              
29             has payload => (
30             is => 'ro',
31             isa => HashRef,
32             required => 1,
33             );
34              
35             sub bundle_config {
36 2     2 0 2743159 my ( $class, $section ) = @_;
37              
38 2         7 $section->{bundle_config} = delete $section->{payload}->{bundle_config};
39              
40 2         95 my $self = $class->new($section);
41              
42 1         45 my $code_ref = $self->_bundle_config;
43 1         4 return $self->$code_ref;
44             }
45              
46             __PACKAGE__->meta->make_immutable;
47              
48             1;
49              
50             __END__
51              
52             =pod
53              
54             =encoding UTF-8
55              
56             =head1 NAME
57              
58             Dist::Zilla::PluginBundle::Code - a dynamic bundle
59              
60             =head1 VERSION
61              
62             Version 0.007
63              
64             =head1 SYNOPSIS
65              
66             package Dist::Zilla::PluginBundle::MyBundle;
67              
68             use Moose;
69             with 'Dist::Zilla::Role::PluginBundle';
70              
71             sub bundle_config {
72             my ( $class, $section ) = @_;
73              
74             my @plugins;
75             push @plugins, [
76             'SomeUniqueName',
77             'Dist::Zilla::PluginBundle::Code',
78             {
79             bundle_config => sub {
80             my ($self) = @_;
81             print $self->payload->{some_arg}, "\n";
82              
83             # Dist::Zilla expects you to return plugins and bundles
84             # or nothing.
85             return;
86             },
87             some_arg => 'some value',
88             another_arg => 'another value',
89             },
90             ];
91              
92             return @plugins;
93             }
94              
95             =head1 DESCRIPTION
96              
97             This bundle implements the L<Dist::Zilla::Role::PluginBundle> role. It
98             can be returned from another bundle by the C<bundle_config> method.
99              
100             L<Dist::Zilla> will then run the C<bundle_config> method of this code bundle.
101             This is mainly useful if your bundle wants to return a plugin that runs
102             in the initialization phase (e.g. L<Dist::Zilla::Plugin::lib>) and run a
103             function after that plugin run.
104              
105             This, being a bundle, has no access to the C<zilla> object nor the various
106             C<log> methods. But you can access the C<name> and C<payload> attributes.
107             The C<payload> attribute is a hash ref that contains the arguments given to
108             the code bundle.
109              
110             B<Note:> Bundles that consume the L<Dist::Zilla::Role::PluginBundle::Easy>
111             role immediately resolve other bundles themselves, there is no way to push
112             a bundle back onto the stack. Therefore it doesn't make sense to use this
113             code bundle inside L<Dist::Zilla::Role::PluginBundle::Easy> bundles.
114              
115             =head1 SUPPORT
116              
117             =head2 Bugs / Feature Requests
118              
119             Please report any bugs or feature requests through the issue tracker
120             at L<https://github.com/skirmess/Dist-Zilla-Plugin-Code/issues>.
121             You will be notified automatically of any progress on your issue.
122              
123             =head2 Source Code
124              
125             This is open source software. The code repository is available for
126             public review and contribution under the terms of the license.
127              
128             L<https://github.com/skirmess/Dist-Zilla-Plugin-Code>
129              
130             git clone https://github.com/skirmess/Dist-Zilla-Plugin-Code.git
131              
132             =head1 AUTHOR
133              
134             Sven Kirmess <sven.kirmess@kzone.ch>
135              
136             =head1 COPYRIGHT AND LICENSE
137              
138             This software is Copyright (c) 2020-2021 by Sven Kirmess.
139              
140             This is free software, licensed under:
141              
142             The (two-clause) FreeBSD License
143              
144             =head1 SEE ALSO
145              
146             L<Dist::Zilla>, L<Dist::Zilla::Role::PluginBundle>
147              
148             =cut
149              
150             # vim: ts=4 sts=4 sw=4 et: syntax=perl