File Coverage

blib/lib/Dist/Zilla/App/Command/add.pm
Criterion Covered Total %
statement 33 34 97.0
branch 2 4 50.0
condition n/a
subroutine 8 9 88.8
pod 5 5 100.0
total 48 52 92.3


line stmt bran cond sub pod time code
1             package Dist::Zilla::App::Command::add 6.029;
2             # ABSTRACT: add a module to a dist
3              
4 4     4   158001 use Dist::Zilla::Pragmas;
  4         25  
  4         42  
5              
6 4     4   32 use Dist::Zilla::App -command;
  4         13  
  4         59  
7 4     4   1541 use Dist::Zilla::Path;
  4         13  
  4         38  
8              
9 4     4   1618 use namespace::autoclean;
  4         14  
  4         36  
10              
11             #pod =head1 SYNOPSIS
12             #pod
13             #pod Adds a new module to a Dist::Zilla-based distribution
14             #pod
15             #pod $ dzil add Some::New::Module
16             #pod
17             #pod There are two arguments, C<-p> and C<-P>. C<-P> specify the minting profile
18             #pod provider and C<-p> - the profile name. These work just like C<dzil new>.
19             #pod
20             #pod =cut
21              
22 0     0 1 0 sub abstract { 'add modules to an existing dist' }
23              
24 1     1 1 25251 sub usage_desc { '%c %o <ModuleName>' }
25              
26             sub opt_spec {
27 1     1 1 51 [ 'profile|p=s', 'name of the profile to use',
28             { default => 'default' } ],
29              
30             [ 'provider|P=s', 'name of the profile provider to use',
31             { default => 'Default' } ],
32              
33             # [ 'module|m=s@', 'module(s) to create; may be given many times' ],
34             }
35              
36             sub validate_args {
37 1     1 1 891 my ($self, $opt, $args) = @_;
38              
39 1         10 require MooseX::Types::Perl;
40              
41 1 50       6 $self->usage_error('dzil add takes one or more arguments') if @$args < 1;
42              
43 1         4 for my $name ( @$args ) {
44 1 50       7 $self->usage_error("$name is not a valid module name")
45             unless MooseX::Types::Perl::is_ModuleName($name);
46             }
47             }
48              
49             sub execute {
50 1     1 1 339 my ($self, $opt, $arg) = @_;
51              
52 1         10 my $zilla = $self->zilla;
53 1         31 my $dist = $zilla->name;
54            
55 1         7 require File::pushd;
56              
57 1         5 require Dist::Zilla::Dist::Minter;
58 1         9 my $minter = Dist::Zilla::Dist::Minter->_new_from_profile(
59             [ $opt->provider, $opt->profile ],
60             {
61             chrome => $self->app->chrome,
62             name => $dist,
63             _global_stashes => $self->app->_build_global_stashes,
64             },
65             );
66              
67 1         38 my $root = path($zilla->root)->absolute;
68 1         145 my $wd = File::pushd::pushd($minter->root);
69              
70 1         233 my $factory = $minter->plugin_named(':DefaultModuleMaker');
71              
72 1         6 for my $name ( @$arg ) {
73 1         8 $factory->make_module({ name => $name });
74             }
75              
76 1         3 for my $file ( @{ $factory->zilla->files} ) {
  1         32  
77 1         11 $zilla->_write_out_file($file, $root);
78             }
79             }
80              
81             1;
82              
83             __END__
84              
85             =pod
86              
87             =encoding UTF-8
88              
89             =head1 NAME
90              
91             Dist::Zilla::App::Command::add - add a module to a dist
92              
93             =head1 VERSION
94              
95             version 6.029
96              
97             =head1 SYNOPSIS
98              
99             Adds a new module to a Dist::Zilla-based distribution
100              
101             $ dzil add Some::New::Module
102              
103             There are two arguments, C<-p> and C<-P>. C<-P> specify the minting profile
104             provider and C<-p> - the profile name. These work just like C<dzil new>.
105              
106             =head1 PERL VERSION
107              
108             This module should work on any version of perl still receiving updates from
109             the Perl 5 Porters. This means it should work on any version of perl released
110             in the last two to three years. (That is, if the most recently released
111             version is v5.40, then this module should work on both v5.40 and v5.38.)
112              
113             Although it may work on older versions of perl, no guarantee is made that the
114             minimum required version will not be increased. The version may be increased
115             for any reason, and there is no promise that patches will be accepted to lower
116             the minimum required perl.
117              
118             =head1 AUTHOR
119              
120             Ricardo SIGNES 😏 <cpan@semiotic.systems>
121              
122             =head1 COPYRIGHT AND LICENSE
123              
124             This software is copyright (c) 2022 by Ricardo SIGNES.
125              
126             This is free software; you can redistribute it and/or modify it under
127             the same terms as the Perl 5 programming language system itself.
128              
129             =cut