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.037;
2             # ABSTRACT: add a module to a dist
3              
4 4     4   163921 use Dist::Zilla::Pragmas;
  4         9  
  4         40  
5              
6 4     4   30 use Dist::Zilla::App -command;
  4         9  
  4         57  
7 4     4   71546 use Dist::Zilla::Path;
  4         10  
  4         35  
8              
9 4     4   1588 use namespace::autoclean;
  4         10  
  4         42  
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 26719 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 1537 my ($self, $opt, $args) = @_;
36              
37 1         13 require MooseX::Types::Perl;
38              
39 1 50       6 $self->usage_error('dzil add takes one or more arguments') if @$args < 1;
40              
41 1         4 for my $name ( @$args ) {
42 1 50       9 $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 480 my ($self, $opt, $arg) = @_;
49              
50 1         18 my $zilla = $self->zilla;
51 1         44 my $dist = $zilla->name;
52              
53 1         8 require File::pushd;
54              
55 1         9 my $mint_stash = $zilla->stash_named('%Mint');
56              
57 1   33     9 my $provider = $opt->provider
      33        
      50        
58             // ($mint_stash && $mint_stash->provider)
59             // 'Default';
60              
61 1   33     30 my $profile = $opt->profile
      33        
      50        
62             // ($mint_stash && $mint_stash->profile)
63             // 'default';
64              
65 1         20 require Dist::Zilla::Dist::Minter;
66 1         12 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         48 my $root = path($zilla->root)->absolute;
76 1         207 my $wd = File::pushd::pushd($minter->root);
77              
78 1         255 my $factory = $minter->plugin_named(':DefaultModuleMaker');
79              
80 1         6 for my $name ( @$arg ) {
81 1         11 $factory->make_module({ name => $name });
82             }
83              
84 1         5 for my $file ( @{ $factory->zilla->files} ) {
  1         44  
85 1         12 $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.037
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
118             released in the last two to three years. (That is, if the most recently
119             released version is v5.40, then this module should work on both v5.40 and
120             v5.38.)
121              
122             Although it may work on older versions of perl, no guarantee is made that the
123             minimum required version will not be increased. The version may be increased
124             for any reason, and there is no promise that patches will be accepted to
125             lower the minimum required perl.
126              
127             =head1 AUTHOR
128              
129             Ricardo SIGNES 😏 <cpan@semiotic.systems>
130              
131             =head1 COPYRIGHT AND LICENSE
132              
133             This software is copyright (c) 2026 by Ricardo SIGNES.
134              
135             This is free software; you can redistribute it and/or modify it under
136             the same terms as the Perl 5 programming language system itself.
137              
138             =cut