File Coverage

lib/Dist/Zilla/Plugin/Code/Initialization.pm
Criterion Covered Total %
statement 20 20 100.0
branch n/a
condition n/a
subroutine 7 7 100.0
pod n/a
total 27 27 100.0


line stmt bran cond sub pod time code
1             package Dist::Zilla::Plugin::Code::Initialization;
2              
3 2     2   2262 use 5.006;
  2         10  
4 2     2   12 use strict;
  2         9  
  2         45  
5 2     2   12 use warnings;
  2         4  
  2         98  
6              
7             our $VERSION = '0.007';
8              
9 2     2   593 use Moose;
  2         457638  
  2         30  
10 2     2   15131 use namespace::autoclean;
  2         5  
  2         43  
11              
12             with 'Dist::Zilla::Role::Plugin';
13              
14 2     2   1098 use Config::MVP 2.200012 (); # https://github.com/rjbs/Config-MVP/issues/13
  2         205  
  2         72  
15 2     2   460 use MooseX::Types::Moose qw(CodeRef);
  2         61991  
  2         21  
16              
17             has initialization => (
18             is => 'ro',
19             isa => 'CodeRef',
20             reader => '_initialization',
21             required => 1,
22             );
23              
24             around plugin_from_config => sub {
25             my $orig = shift @_;
26             my $plugin_class = shift @_;
27              
28             my $instance = $plugin_class->$orig(@_);
29              
30             my $code_ref = $instance->_initialization;
31             $instance->$code_ref(@_);
32              
33             return $instance;
34             };
35              
36             __PACKAGE__->meta->make_immutable;
37              
38             1;
39              
40             __END__
41              
42             =pod
43              
44             =encoding UTF-8
45              
46             =head1 NAME
47              
48             Dist::Zilla::Plugin::Code::Initialization - something that runs when plugins are initialized
49              
50             =head1 VERSION
51              
52             Version 0.007
53              
54             =head1 SYNOPSIS
55              
56             =head2 Dist::Zilla::Role::PluginBundle
57              
58             package Dist::Zilla::PluginBundle::MyBundle;
59              
60             use Moose;
61             with 'Dist::Zilla::Role::PluginBundle';
62              
63             sub bundle_config {
64             my ( $class, $section ) = @_;
65              
66             my @plugins;
67             push @plugins, [
68             'SomeUniqueName',
69             'Dist::Zilla::Plugin::Code::Initialization',
70             {
71             initialization => sub {
72             my ($self) = @_;
73             $self->log('Hello world');
74             },
75             },
76             ];
77              
78             return @plugins;
79             }
80              
81             =head2 Dist::Zilla::Role::PluginBundle::Easy
82              
83             package Dist::Zilla::PluginBundle::MyBundle;
84              
85             use Moose;
86             with 'Dist::Zilla::Role::PluginBundle::Easy';
87              
88             sub configure {
89             my ( $self ) = @_;
90              
91             $self->add_plugins([
92             'Code::Initialization',
93             {
94             initialization => sub {
95             my ($self) = @_;
96             $self->log('Hello world');
97             },
98             },
99             ]);
100              
101             return;
102             }
103              
104             =head1 DESCRIPTION
105              
106             This plugin implements the L<Dist::Zilla::Role::Plugin> role and attaches
107             to the C<plugin_from_config> method, that is fired when the plugins and
108             bundles get initialized. (This plugin runs at the same time as bundles.)
109              
110             =head1 SUPPORT
111              
112             =head2 Bugs / Feature Requests
113              
114             Please report any bugs or feature requests through the issue tracker
115             at L<https://github.com/skirmess/Dist-Zilla-Plugin-Code/issues>.
116             You will be notified automatically of any progress on your issue.
117              
118             =head2 Source Code
119              
120             This is open source software. The code repository is available for
121             public review and contribution under the terms of the license.
122              
123             L<https://github.com/skirmess/Dist-Zilla-Plugin-Code>
124              
125             git clone https://github.com/skirmess/Dist-Zilla-Plugin-Code.git
126              
127             =head1 AUTHOR
128              
129             Sven Kirmess <sven.kirmess@kzone.ch>
130              
131             =head1 COPYRIGHT AND LICENSE
132              
133             This software is Copyright (c) 2020-2021 by Sven Kirmess.
134              
135             This is free software, licensed under:
136              
137             The (two-clause) FreeBSD License
138              
139             =head1 SEE ALSO
140              
141             L<Dist::Zilla>, L<Dist::Zilla::Role::Plugin>
142              
143             =cut
144              
145             # vim: ts=4 sts=4 sw=4 et: syntax=perl