File Coverage

blib/lib/Dist/Zilla/Plugin/Run/Clean.pm
Criterion Covered Total %
statement 27 27 100.0
branch 1 2 50.0
condition n/a
subroutine 7 7 100.0
pod 0 1 0.0
total 35 37 94.5


line stmt bran cond sub pod time code
1 1     1   3261187 use strict;
  1         3  
  1         36  
2 1     1   7 use warnings;
  1         2  
  1         73  
3             package Dist::Zilla::Plugin::Run::Clean;
4             # ABSTRACT: execute a command of the distribution on 'dzil clean'
5             # vim: set ts=8 sts=4 sw=4 tw=115 et :
6              
7             our $VERSION = '0.048';
8              
9 1     1   8 use Moose;
  1         2  
  1         9  
10             with
11             'Dist::Zilla::Role::Plugin',
12             'Dist::Zilla::Plugin::Run::Role::Runner';
13              
14 1     1   6916 use Moose::Util ();
  1         3  
  1         32  
15 1     1   8 use namespace::autoclean;
  1         3  
  1         12  
16              
17             {
18 1     1   99 use Dist::Zilla::Dist::Builder;
  1         2  
  1         342  
19             my $meta = Moose::Util::find_meta('Dist::Zilla::Dist::Builder');
20             $meta->make_mutable;
21             Moose::Util::add_method_modifier($meta, 'after',
22             [
23             clean => sub {
24             my ($zilla, $dry_run) = @_;
25             foreach my $plugin (grep { $_->isa(__PACKAGE__) } @{ $zilla->plugins })
26             {
27             # Dist::Zilla really ought to have a -CleanerProvider hook...
28             $plugin->clean($dry_run);
29             }
30             },
31             ],
32             );
33             $meta->make_immutable;
34             }
35              
36             sub clean
37             {
38 2     2 0 8 my ($self, $dry_run) = @_;
39              
40             # may need some subrefs for positional parameters?
41 2         6 my $params = {};
42              
43 2         6 foreach my $run_cmd (@{$self->run}) {
  2         70  
44 2         14 $self->_run_cmd($run_cmd, $params, $dry_run);
45             }
46              
47 2 50       1465 if (my @code = @{ $self->eval }) {
  2         107  
48 2         30 my $code = join "\n", @code;
49 2         22 $self->_eval_cmd($code, $params, $dry_run);
50             }
51             }
52              
53             __PACKAGE__->meta->make_immutable;
54              
55             __END__
56              
57             =pod
58              
59             =encoding UTF-8
60              
61             =head1 NAME
62              
63             Dist::Zilla::Plugin::Run::Clean - execute a command of the distribution on 'dzil clean'
64              
65             =head1 VERSION
66              
67             version 0.048
68              
69             =head1 SYNOPSIS
70              
71             In your F<dist.ini>:
72              
73             [Run::Clean]
74             run = script/do_that.pl
75             eval = unlink scratch.dat
76              
77             =head1 DESCRIPTION
78              
79             This plugin executes the specified command(s) when cleaning the distribution.
80              
81             =head1 POSITIONAL PARAMETERS
82              
83             See L<Dist::Zilla::Plugin::Run/CONVERSIONS>
84             for the list of common formatting variables available to all plugins.
85             (Some of them may not work properly, because the distribution is not built
86             when running the clean command. These are not tested yet - patches welcome!)
87              
88             =head1 SUPPORT
89              
90             Bugs may be submitted through L<the RT bug tracker|https://rt.cpan.org/Public/Dist/Display.html?Name=Dist-Zilla-Plugin-Run>
91             (or L<bug-Dist-Zilla-Plugin-Run@rt.cpan.org|mailto:bug-Dist-Zilla-Plugin-Run@rt.cpan.org>).
92              
93             There is also a mailing list available for users of this distribution, at
94             L<http://dzil.org/#mailing-list>.
95              
96             There is also an irc channel available for users of this distribution, at
97             L<C<#distzilla> on C<irc.perl.org>|irc://irc.perl.org/#distzilla>.
98              
99             =head1 AUTHOR
100              
101             Torsten Raudssus <torsten@raudss.us> L<https://raudss.us/>
102              
103             =head1 COPYRIGHT AND LICENCE
104              
105             This software is copyright (c) 2010 by L<Raudssus Social Software|https://raudss.us/>.
106              
107             This is free software; you can redistribute it and/or modify it under
108             the same terms as the Perl 5 programming language system itself.
109              
110             =cut