File Coverage

blib/lib/Dist/Zilla/App/Command/add.pm
Criterion Covered Total %
statement 36 37 97.3
branch 2 4 50.0
condition 6 16 37.5
subroutine 8 9 88.8
pod 5 5 100.0
total 57 71 80.2


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