Minty.pm

filter: Statementstmt 28.5% 36 / 126 Branchbran 21.4% 6 / 28 Conditioncond 0.0% 0 / 18 MC/DCmcdc 0.0% 0 / 10 Subroutinesub 40.9% 9 / 22 Podpod 87.5% 7 / 8 totaltotal 27.3% 58 / 212 CC 25 SCAR 40.5
CC
25
Cov
24%
set_defaults
182.0
create_author_tests
20.0
_fill_in_template
16.8
CRAP 57.2
↑ Summary Bovine.pm »
1 1 ▶use 5.010001;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 package Dist::Inktly::Minty;
6  
7 1 our $AUTHORITY = 'cpan:TOBYINK';
8 1 our $VERSION = '0.005';
9  
10 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use File::chdir;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶use Path::Tiny 'path';
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶use Software::License;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 1 ▶use Text::Template;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 1 ▶use URI::Escape qw[];
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 {
18 1 my %templates;
19 1 my $key = undef;
20 1 ▶ while (my $line = <DATA>)
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $line = readline DATA)) 201 1 202
21 {
22 201 ▶ if ($line =~ /^COMMENCE\s+(.+)\s*$/)
Branch: 2 branches
BranchTrueFalseTotal
if ($line =~ /^COMMENCE\s+(.+)\s*$/) { } 9 192 201
elsif (defined $key) { } 191 1 192
23 {
24 9 $key = $1;
25 }
26 elsif (defined $key)
27 {
28 191 $templates{$key} .= $line;
29 }
30 }
31 sub _has_template
32 0 ▶ {
Subroutine _has_template: not called CC=1 SCAR=6.9
33 0 my $class = shift;
34 0 my ($key) = @_;
35 0 exists $templates{$key};
36 }
37 sub _get_template
38 0 ▶ {
Subroutine _get_template: not called CC=1 SCAR=6.9
39 0 my $class = shift;
40 0 my ($key) = @_;
41 0 'Text::Template'->new(-type=>'string', -source=>$templates{$key});
42 }
43 sub _get_template_names
44 0 ▶ {
Subroutine _get_template_names: not called CC=1 SCAR=6.9
45 0 my $class = shift;
46 0 return keys %templates;
47 }
48 }
49  
50 sub _fill_in_template
51 1 ▶{
Subroutine _fill_in_template: not called CC=4 SCAR=28.2
52 0 my $self = shift;
53 0 my ($template) = @_;
54 0 ▶ $template = $self->_get_template($template) unless ref $template;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $template 0 0 0
55
56 0 my %hash = ();
57 0 ▶ while (my ($k, $v) = each %$self)
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %$self) 0 0 0
58 {
59 0 ▶ $hash{$k} = ref $v ? \$v : $v;
Branch: 1 branch
BranchTrueFalseTotal
ref $v ? : 0 0 0
60 }
61
62 0 $template->fill_in(-hash => \%hash);
63 }
64  
65 sub _file
66 0 ▶{
Subroutine _file: not called CC=1 SCAR=6.9
67 0 my $self = shift;
68 my $file = path(
69 $self->{destination},
70 0 sprintf('p5-%s', lc($self->{dist_name}))
71 )->child($_[0]);
72 0 $file->parent->mkpath;
73 0 return $file;
74 }
75  
76 sub create
77 0 ▶{
Subroutine create: not called CC=3 SCAR=24.8
Pod documented
78 0 my $class = shift;
79 0 my ($name, %options) = @_;
80
81 0 $options{module_name} = $name;
82 0 $options{dist_name} = $name;
83
84 0 ▶ if ($name =~ /::/)
Branch: 2 branches
BranchTrueFalseTotal
if ($name =~ /::/) { } 0 0 0
elsif ($name =~ /\-/) { } 0 0 0
85 {
86 0 $options{dist_name} =~ s/::/-/g;
87 }
88 elsif ($name =~ /\-/)
89 {
90 0 $options{module_name} =~ s/\-/::/g;
91 }
92
93 0 my $self = bless \%options, $class;
94 0 $self->set_defaults;
95 0 $self->create_module;
96 0 $self->create_dist_ini;
97 0 $self->create_metadata;
98 0 $self->create_tests;
99 0 $self->create_author_tests;
100 0 $self->run_then;
101 0 return $self;
102 }
103  
104 sub set_defaults
105 0 ▶{
Subroutine set_defaults: not called CC=13 SCAR=52.0
Pod documented
106 0 my $self = shift;
107
108 0 ▶ croak "Need an author name." unless defined $self->{author}{name};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"author"}{"name"} 0 0 0
109 0 ▶ croak "Need an author cpanid." unless defined $self->{author}{cpanid};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"author"}{"cpanid"} 0 0 0
110
111 0 $self->{author}{cpanid} = lc $self->{author}{cpanid};
112 0 ▶ $self->{author}{mbox} ||= sprintf('%s@cpan.org', $self->{author}{cpanid});
Condition0%0/2
$self->{"author"}{"mbox"} ||= sprintf('%s@cpan.org', $self->{"author"}{"cpanid"})
l!l
00
MC/DC0%0/1
$self->{"author"}{"mbox"} ||= sprintf('%s@cpan.org', $self->{"author"}{"cpanid"})
$self->{"author"}{"mbox"}
Truth table0%0/2
A
A= $self->{"author"}{"mbox"}
Aresult
11
00
113  
114 $self->{backpan} ||= sprintf('http://backpan.cpan.org/authors/id/%s/%s/%s/',
115 substr(uc $self->{author}{cpanid}, 0, 1),
116 substr(uc $self->{author}{cpanid}, 0, 2),
117 uc $self->{author}{cpanid},
118 0 ▶ );
Condition0%0/2
$self->{"backpan"} ||= sprintf('http://backpan.cpan.org/authors/id/%s/%s/%s/', substr(uc $self->{"author"}{"cpanid"}, 0, 1), substr(uc $self->{"author"}{"cpanid"}, 0, 2), uc $self->{"author"}{"cpanid"})
l!l
00
MC/DC0%0/1
$self->{"backpan"} ||= sprintf('http://backpan.cpan.org/authors/id/%s/%s/%s/', substr(uc $self->{"author"}{"cpanid"}, 0, 1), substr(uc $self->{"author"}{"cpanid"}, 0, 2), uc $self->{"author"}{"cpanid"})
$self->{"backpan"}
Truth table0%0/2
A
A= $self->{"backpan"}
Aresult
11
00
119
120 0 ▶ $self->{abstract} ||= 'a module that does something-or-other';
Condition0%0/2
$self->{"abstract"} ||= "a module that does something-or-other"
l!l
00
MC/DC0%0/1
$self->{"abstract"} ||= "a module that does something-or-other"
$self->{"abstract"}
Truth table0%0/2
A
A= $self->{"abstract"}
Aresult
11
00
121 0 ▶ $self->{version} ||= '0.001';
Condition0%0/2
$self->{"version"} ||= "0.001"
l!l
00
MC/DC0%0/1
$self->{"version"} ||= "0.001"
$self->{"version"}
Truth table0%0/2
A
A= $self->{"version"}
Aresult
11
00
122 0 $self->{version_ident} = 'v_'.$self->{version};
123 0 $self->{version_ident} =~ s/\./-/g;
124 0 ▶ $self->{destination} ||= './';
Condition0%0/2
$self->{"destination"} ||= "./"
l!l
00
MC/DC0%0/1
$self->{"destination"} ||= "./"
$self->{"destination"}
Truth table0%0/2
A
A= $self->{"destination"}
Aresult
11
00
125
126 0 ▶ unless ($self->{module_filename})
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"module_filename"}) 0 0 0
127 {
128 0 $self->{module_filename} = 'lib::'.$self->{module_name};
129 0 $self->{module_filename} =~ s/::/\//g;
130 0 $self->{module_filename} .= '.pm';
131 }
132
133 0 ▶ unless ($self->{unit_test_filename})
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"unit_test_filename"}) 0 0 0
134 {
135 0 $self->{unit_test_filename} = $self->{module_filename};
136 0 $self->{unit_test_filename} =~ s/\.pm$/\.t/;
137 0 $self->{unit_test_filename} =~ s/lib/t\/unit/;
138 }
139
140 0 ▶ $self->{copyright}{holder} ||= $self->{author}{name};
Condition0%0/3
$self->{"copyright"}{"holder"} ||= $self->{"author"}{"name"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"copyright"}{"holder"} ||= $self->{"author"}{"name"}
$self->{"copyright"}{"holder"} $self->{"author"}{"name"}
Truth table0%0/3
A ||= B
A= $self->{"copyright"}{"holder"}B= $self->{"author"}{"name"}
ABresult
1X1
011
000
141 0 ▶ $self->{copyright}{year} ||= 1900 + [localtime]->[5];
Condition0%0/3
$self->{"copyright"}{"year"} ||= 1900 + [localtime]->[5]
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"copyright"}{"year"} ||= 1900 + [localtime]->[5]
$self->{"copyright"}{"year"} 1900 + [localtime]->[5]
Truth table0%0/3
A ||= B
A= $self->{"copyright"}{"year"}B= 1900 + [localtime]->[5]
ABresult
1X1
011
000
142
143 0 ▶ $self->{licence_class} ||= 'Software::License::Perl_5';
Condition0%0/2
$self->{"licence_class"} ||= "Software::License::Perl_5"
l!l
00
MC/DC0%0/1
$self->{"licence_class"} ||= "Software::License::Perl_5"
$self->{"licence_class"}
Truth table0%0/2
A
A= $self->{"licence_class"}
Aresult
11
00
144 0 eval sprintf('use %s;', $self->{licence_class});
145 $self->{licence} = $self->{licence_class}->new({
146 year => $self->{copyright}{year},
147 holder => $self->{copyright}{holder},
148 0 });
149 }
150  
151 sub create_module
152 0 ▶{
Subroutine create_module: not called CC=1 SCAR=6.9
Pod documented
153 0 my $self = shift;
154 0 $self->_file( $self->{module_filename} )->spew( $self->_fill_in_template('module') );
155 0 return;
156 }
157  
158 sub create_dist_ini
159 0 ▶{
Subroutine create_dist_ini: not called CC=1 SCAR=6.9
Pod documented
160 0 my $self = shift;
161 0 $self->_file('dist.ini')->spew($self->_fill_in_template('dist.ini'));
162 0 return;
163 }
164  
165 sub create_metadata
166 0 ▶{
Subroutine create_metadata: not called CC=2 SCAR=17.9
Pod documented
167 0 my $self = shift;
168 $self->_file($_)->spew($self->_fill_in_template($_))
169 0 for grep { m#^meta/# } $self->_get_template_names;
170 0 return;
171 }
172  
173 sub create_tests
174 0 ▶{
Subroutine create_tests: not called CC=2 SCAR=17.9
Pod documented
175 0 my $self = shift;
176 $self->_file($_)->spew($self->_fill_in_template($_))
177 0 for grep { m#^t/# } $self->_get_template_names;
178 0 mkdir( $self->_file('t/unit') );
179 0 mkdir( $self->_file('t/integration') );
180 0 $self->_file( $self->{unit_test_filename} )->spew( $self->_fill_in_template('unit-test') );
181 0 return;
182 }
183  
184 sub create_author_tests
185 0 ▶{
Subroutine create_author_tests: not called CC=4 SCAR=30.0
Pod documented
186 0 my $self = shift;
187
188 $self->_file($_)->spew($self->_fill_in_template($_))
189 0 for grep { m#^xt/# } $self->_get_template_names;
190
191 0 my $xtdir = path("~/perl5/xt");
192 0 ▶ if ( $xtdir->exists ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($xtdir->exists) 0 0 0
193 $self->_file("xt/" . $_->relative($xtdir))->spew(scalar $_->slurp)
194 0 for grep { $_ =~ /\.t$/ } $xtdir->children;
195 }
196
197 0 return;
198 }
199  
200 0 ▶sub run_then {
Subroutine run_then: not called CC=3 SCAR=24.8
Pod undocumented
201 0 my $self = shift;
202 0 ▶ ref $self->{then} or return;
Branch: 1 branch
BranchTrueFalseTotal
ref $self->{"then"} or return 0 0 0
203 my $dir = path(
204 $self->{destination},
205 0 sprintf('p5-%s', lc($self->{dist_name})),
206 );
207 0 local $CWD = "$dir";
208 0 system($_) for @{ $self->{then} };
209 }
210  
211 1 1;
212  
213 =head1 NAME
214  
215 Dist::Inktly::Minty - create distributions that will use Dist::Inkt
216  
217 =head1 SYNOPSIS
218  
219 distinkt-mint Local::Example::Useful
220  
221 =head1 STATUS
222  
223 Experimental.
224  
225 =head1 DESCRIPTION
226  
227 Sets up a new distribution in the style TOBYINK likes.
228  
229 This package provides just one (class) method:
230  
231 =over
232  
233 =item C<< Dist::Inktly::Minty->create($distname, %options) >>
234  
235 Create a distribution directory including all needed files.
236  
237 =back
238  
239 There are various methods that may be useful for people subclassing this
240 class to look at (and possibly override).
241  
242 =over
243  
244 =item C<< set_defaults >>
245  
246 =item C<< create_module >>
247  
248 =item C<< create_dist_ini >>
249  
250 =item C<< create_metadata >>
251  
252 =item C<< create_tests >>
253  
254 =item C<< create_author_tests >>
255  
256 =back
257  
258 =head1 SEE ALSO
259  
260 L<Dist::Inkt>.
261  
262 =head1 AUTHOR
263  
264 Toby Inkster E<lt>tobyink@cpan.orgE<gt>.
265  
266 =head1 COPYRIGHT AND LICENCE
267  
268 This software is copyright (c) 2013-2023 by Toby Inkster.
269  
270 This is free software; you can redistribute it and/or modify it under
271 the same terms as the Perl 5 programming language system itself.
272  
273 =head1 DISCLAIMER OF WARRANTIES
274  
275 THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
276 WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
277 MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
278  
279 =cut
280  
281 __DATA__
↑ Summary Bovine.pm »