blib/lib/Module/Starter/AddModule.pm

filter: Statementstmt 58.3% 28 / 48 Branchbran 0.0% 0 / 12 Conditioncond 0.0% 0 / 7 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 75.0% 9 / 12 Podpod 100% 2 / 2 totaltotal 45.8% 39 / 85 CC 10 SCAR 36.8
CC
10
Cov
42%
create_MANIFEST
90.0
basedir
6.0
BEGIN
1.0
CRAP 39.6
↑ Summary
1 package Module::Starter::AddModule;
2 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 2 ▶use 5.010;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶no warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 2 ▶use subs qw();
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 ▶use vars qw($VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 2 ▶use parent qw(Module::Starter::Smart);
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 BEGIN {
15 package # hide package from PAUSE
16 Module::Starter::Smart;
17 2 ▶ use parent qw(Module::Starter::Simple);
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: not called CC=1 SCAR=0.0
18 }
19  
20 2 ▶use Cwd;
Subroutine BEGIN: called CC=1 SCAR=0.0
21  
22 2 $VERSION = '1.011';
23  
24 =encoding utf8
25  
26 =head1 NAME
27  
28 Module::Starter::AddModule - Add a new module to a distribution
29  
30 =head1 SYNOPSIS
31  
32 # in the module-starter config
33  
34 plugins: Module::Starter::AddModule
35 make: /whatever/make/you/like/dmake
36  
37 # from the command line
38 # the --dist option specifies the dist directory
39 % module-starter --module=Add::This::Module --dist=.
40  
41 =head1 DESCRIPTION
42  
43 C<Module::Starter::Simple> and C<Module::Starter::Smart> (which relies
44 on C<::Simple>) try to construct the MANIFEST file themselves. This is
45 the wrong approach since it doesn't not take into account build file
46 subclasses or F<MANIFEST.SKIP>.
47  
48 Once you have the build file, let it do it's job by running its C<manifest>
49 target.
50  
51 Furthermore, C<Module::Starter::Smart> doesn't explicitly inherit from
52 C<Module::Starter::Simple>, but this module inserts the inheritance
53 relationship for you automatically.
54  
55 =over 4
56  
57 =item create_MANIFEST
58  
59 Overrides the C<create_MANIFEST> in C<Module::Starter::Simple> to use
60 the C<manifest> target of the build system instead of trying to create
61 the C<MANIFEST> file directly. It automatically figures out the build
62 system you use.
63  
64 This assumes that your C<make> program is called C<make>. If it's
65 something else, such as C<dmake>, set the C<make> configuration. This
66 only matters if you are using F<Makefile.PL>.
67  
68 =cut
69  
70 0 ▶sub create_MANIFEST {
Subroutine create_MANIFEST: not called CC=9 SCAR=45.0
Pod documented
71 0 my $self = shift;
72  
73 0 require Distribution::Guess::BuildSystem;
74  
75 0 my $dist_dir = $self->basedir;
76 0 ▶ die "The base directory" unless -d $dist_dir;
Branch: 1 branch
BranchTrueFalseTotal
unless -d $dist_dir 0 0 0
77  
78 0 $self->progress( "Regenerating MANIFEST" );
79  
80 0 ▶ my $make = $self->{make} // 'make'; #/
Condition0%0/2
$self->{"make"} // "make"
l!l
00
MC/DC0%0/1
$self->{"make"} // "make"
$self->{"make"}
Truth table0%0/2
A
A= $self->{"make"}
Aresult
11
00
81  
82 0 ▶ eval {
Branch: 1 branch
BranchTrueFalseTotal
eval { do { my $dir = cwd(); chdir $dist_dir or die "Could not change to ${dist_dir}: $!\n"; my $guesser = "Distribution::Guess::BuildSystem"->new("dist_dir", "."); if ($guesser->uses_module_build) { $self->verbose("Detected Module::Build"); system $^X, "Build.PL"; system $^X, "Build", "manifest"; } elsif ($guesser->uses_makemaker or $guesser->uses_module_install) { $self->verbose("Detected ExtUtils::Makemaker or Module::Install"); system $^X, "Makefile.PL"; system $make, "manifest"; } ; chdir $dir or die "Could not change back to ${dir}: $!\n" } } or die $@ 0 0 0
83 0 my $dir = cwd();
84 0 ▶ chdir $dist_dir or die "Could not change to $dist_dir: $!\n";
Branch: 1 branch
BranchTrueFalseTotal
chdir $dist_dir or die "Could not change to ${dist_dir}: $!\n" 0 0 0
85  
86 0 my $guesser = Distribution::Guess::BuildSystem->new(
87 dist_dir => '.'
88 );
89  
90 # it doesn't matter who makes the MANIFEST
91 0 ▶ if( $guesser->uses_module_build ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($guesser->uses_module_build) { } 0 0 0
elsif ($guesser->uses_makemaker or $guesser->uses_module_install) { } 0 0 0
92 0 $self->verbose( "Detected Module::Build" );
93 0 system( $^X, 'Build.PL' );
94 0 system( $^X, 'Build', 'manifest' );
95 }
96 ▶ elsif( $guesser->uses_makemaker or $guesser->uses_module_install ) {
Condition0%0/3
$guesser->uses_makemaker or $guesser->uses_module_install
l!l&&r!l&&!r
000
MC/DC0%0/2
$guesser->uses_makemaker or $guesser->uses_module_install
$guesser->uses_makemaker $guesser->uses_module_install
Truth table0%0/3
A or B
A= $guesser->uses_makemakerB= $guesser->uses_module_install
ABresult
1X1
011
000
97 0 $self->verbose( "Detected ExtUtils::Makemaker or Module::Install" );
98 0 system( $^X, 'Makefile.PL' );
99 0 system( $make, 'manifest' );
100 }
101  
102 0 ▶ chdir $dir or die "Could not change back to $dir: $!\n";
Condition0%0/2
chdir $dir || die("Could not change back to ${dir}: $!\n")
l!l
00
MC/DC0%0/1
chdir $dir || die("Could not change back to ${dir}: $!\n")
chdir $dir
Truth table0%0/2
A
A= chdir $dir
Aresult
11
00
103 } or die $@;
104  
105 0 return 1;
106 }
107  
108 =item basedir
109  
110 Return the top-level directory for the distribution.
111  
112 =cut
113  
114 0 ▶sub basedir { $_[0]->{basedir} || '' }
Subroutine basedir: not called CC=2 SCAR=17.9
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
$_[0]{"basedir"} or "" 0 0 0
115  
116 =back
117  
118 =head1 SEE ALSO
119  
120 L<Module::Starter::Smart>
121  
122 =head1 SOURCE AVAILABILITY
123  
124 This source is in Github:
125  
126 https://github.com/briandfoy/module-starter-addmodule/
127  
128 =head1 AUTHOR
129  
130 brian d foy, C<< <briandfoy@pobox.com> >>
131  
132 =head1 COPYRIGHT AND LICENSE
133  
134 Copyright © 2010-2025, brian d foy <briandfoy@pobox.com>. All rights reserved.
135  
136 You may redistribute this under the terms of the Artistic License 2.0.
137  
138 =cut
139  
140 2 1;
↑ Summary