File Coverage

lib/Dist/Zilla/Plugin/Code/FileMunger.pm
Criterion Covered Total %
statement 30 30 100.0
branch 3 4 75.0
condition 3 3 100.0
subroutine 10 10 100.0
pod 0 2 0.0
total 46 49 93.8


line stmt bran cond sub pod time code
1             package Dist::Zilla::Plugin::Code::FileMunger;
2              
3 2     2   2263 use 5.006;
  2         12  
4 2     2   10 use strict;
  2         4  
  2         49  
5 2     2   9 use warnings;
  2         5  
  2         89  
6              
7             our $VERSION = '0.007';
8              
9 2     2   702 use Moose;
  2         496807  
  2         13  
10 2     2   14569 use namespace::autoclean;
  2         6  
  2         21  
11              
12             with 'Dist::Zilla::Role::FileMunger';
13              
14 2     2   206 use Carp qw(confess);
  2         5  
  2         159  
15 2     2   752 use Config::MVP 2.200012 (); # https://github.com/rjbs/Config-MVP/issues/13
  2         196  
  2         68  
16 2     2   505 use MooseX::Types::Moose qw(CodeRef);
  2         56385  
  2         18  
17              
18             has munge_file => (
19             is => 'ro',
20             isa => 'CodeRef',
21             reader => '_munge_file',
22             );
23              
24             has munge_files => (
25             is => 'ro',
26             isa => 'CodeRef',
27             reader => '_munge_files',
28             );
29              
30             sub BUILD {
31 5     5 0 27 my ($self) = @_;
32              
33 5 100 100     223 confess 'Attribute (munge_file) or (munge_files) is required at constructor ' . __PACKAGE__ . '::new' if !defined $self->_munge_file && !defined $self->_munge_files;
34              
35 4         140 return;
36             }
37              
38             sub munge_file {
39 2     2 0 295 my $self = shift;
40              
41 2         75 my $code_ref = $self->_munge_file;
42 2 50       8 return if !defined $code_ref;
43 2         12 return $self->$code_ref(@_);
44             }
45              
46             around munge_files => sub {
47             my $next = shift;
48             my $self = shift;
49              
50             my $code_ref = $self->_munge_files;
51             return $self->$code_ref() if defined $code_ref;
52             return $self->$next();
53             };
54              
55             __PACKAGE__->meta->make_immutable;
56              
57             1;
58              
59             __END__
60              
61             =pod
62              
63             =encoding UTF-8
64              
65             =head1 NAME
66              
67             Dist::Zilla::Plugin::Code::FileMunger - something that munges files within the distribution
68              
69             =head1 VERSION
70              
71             Version 0.007
72              
73             =head1 SYNOPSIS
74              
75             =head2 Dist::Zilla::Role::PluginBundle (munge_file)
76              
77             package Dist::Zilla::PluginBundle::MyBundle;
78              
79             use Moose;
80             with 'Dist::Zilla::Role::PluginBundle';
81              
82             sub bundle_config {
83             my ( $class, $section ) = @_;
84              
85             my @plugins;
86             push @plugins, [
87             'SomeUniqueName',
88             'Dist::Zilla::Plugin::Code::FileMunger',
89             {
90             munge_file => sub {
91             my ($self) = @_;
92             $self->log('Hello world');
93             },
94             },
95             ];
96              
97             return @plugins;
98             }
99              
100             =head2 Dist::Zilla::Role::PluginBundle (munge_files)
101              
102             package Dist::Zilla::PluginBundle::MyBundle;
103              
104             use Moose;
105             with 'Dist::Zilla::Role::PluginBundle';
106              
107             sub bundle_config {
108             my ( $class, $section ) = @_;
109              
110             my @plugins;
111             push @plugins, [
112             'SomeUniqueName',
113             'Dist::Zilla::Plugin::Code::FileMunger',
114             {
115             munge_files => sub {
116             my ($self) = @_;
117             $self->log('Hello world');
118             },
119             },
120             ];
121              
122             return @plugins;
123             }
124              
125             =head2 Dist::Zilla::Role::PluginBundle::Easy (munge_file)
126              
127             package Dist::Zilla::PluginBundle::MyBundle;
128              
129             use Moose;
130             with 'Dist::Zilla::Role::PluginBundle::Easy';
131              
132             sub configure {
133             my ( $self ) = @_;
134              
135             $self->add_plugins([
136             'Code::FileMunger',
137             {
138             munge_file => sub {
139             my ($self) = @_;
140             $self->log('Hello world');
141             },
142             },
143             ]);
144              
145             return;
146             }
147              
148             =head2 Dist::Zilla::Role::PluginBundle::Easy (munge_files)
149              
150             package Dist::Zilla::PluginBundle::MyBundle;
151              
152             use Moose;
153             with 'Dist::Zilla::Role::PluginBundle::Easy';
154              
155             sub configure {
156             my ( $self ) = @_;
157              
158             $self->add_plugins([
159             'Code::FileMunger',
160             {
161             munge_files => sub {
162             my ($self) = @_;
163             $self->log('Hello world');
164             },
165             },
166             ]);
167              
168             return;
169             }
170              
171             =head1 DESCRIPTION
172              
173             This plugin implements the L<Dist::Zilla::Role::FileMunger> role.
174              
175             =head1 SUPPORT
176              
177             =head2 Bugs / Feature Requests
178              
179             Please report any bugs or feature requests through the issue tracker
180             at L<https://github.com/skirmess/Dist-Zilla-Plugin-Code/issues>.
181             You will be notified automatically of any progress on your issue.
182              
183             =head2 Source Code
184              
185             This is open source software. The code repository is available for
186             public review and contribution under the terms of the license.
187              
188             L<https://github.com/skirmess/Dist-Zilla-Plugin-Code>
189              
190             git clone https://github.com/skirmess/Dist-Zilla-Plugin-Code.git
191              
192             =head1 AUTHOR
193              
194             Sven Kirmess <sven.kirmess@kzone.ch>
195              
196             =head1 COPYRIGHT AND LICENSE
197              
198             This software is Copyright (c) 2020-2021 by Sven Kirmess.
199              
200             This is free software, licensed under:
201              
202             The (two-clause) FreeBSD License
203              
204             =head1 SEE ALSO
205              
206             L<Dist::Zilla>, L<Dist::Zilla::Role::FileMunger>
207              
208             =cut
209              
210             # vim: ts=4 sts=4 sw=4 et: syntax=perl