blib/lib/ExtUtils/ModuleMaker/Siffra.pm

filter: Statementstmt 84.3% 27 / 32 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 10 / 10 Podpod n/a totaltotal 88.1% 37 / 42 CC 1 SCAR 0.1
CC
1
Cov
84%
BEGIN
1.1
BEGIN
1.0
BEGIN
1.0
CRAP 1.0
↑ Summary
1 package ExtUtils::ModuleMaker::Siffra;
2  
3 2 ▶use 5.014;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶use Log::Any qw($log);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶use Scalar::Util qw(blessed);
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 BEGIN
12 {
13 2 ▶ require ExtUtils::ModuleMaker;
Subroutine BEGIN: called CC=1 SCAR=0.7
14 2 ▶ use Exporter ();
Subroutine BEGIN: called CC=1 SCAR=0.0
15 2 ▶ use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
Subroutine BEGIN: called CC=1 SCAR=0.0
16 0 $VERSION = '0.01';
17 0 @ISA = qw(Exporter ExtUtils::ModuleMaker);
18  
19 #Give a hoot don't pollute, do not export more than needed by default
20 0 @EXPORT = qw();
21 0 @EXPORT_OK = qw();
22 0 %EXPORT_TAGS = ();
23 } ## end BEGIN
24  
25 =head3 C<block_new_method()>
26
27 Usage : $self->block_new_method() within text_pm_file()
28 Purpose : Build 'new()' method as part of a pm file
29 Returns : String holding sub new.
30 Argument : $module: pointer to the module being built
31 (as there can be more than one module built by EU::MM);
32 for the primary module it is a pointer to $self
33 Throws : n/a
34 Comment : This method is a likely candidate for alteration in a subclass,
35 e.g., pass a single hash-ref to new() instead of a list of
36 parameters.
37
38 =cut
39  
40 sub block_new_method
41 {
42 my $self = shift;
43 return <<'EOFBLOCK';
44  
45 =head2 C<new()>
46
47 Usage : $self->block_new_method() within text_pm_file()
48 Purpose : Build 'new()' method as part of a pm file
49 Returns : String holding sub new.
50 Argument : $module: pointer to the module being built
51 (as there can be more than one module built by EU::MM);
52 for the primary module it is a pointer to $self
53 Throws : n/a
54 Comment : This method is a likely candidate for alteration in a subclass,
55 e.g., pass a single hash-ref to new() instead of a list of
56 parameters.
57
58 =cut
59
60 sub new
61 {
62 my ($class, %parameters) = @_;
63  
64 my $self = {};
65
66 $self = bless ($self, ref ($class) || $class);
67  
68 $log->info( "new", { progname => $0, pid => $$, perl_version => $], package => __PACKAGE__ } );
69
70 $self->_initialize( %parameters );
71 return $self;
72 }
73
74 EOFBLOCK
75 } ## end sub block_new_method
76  
77 =head3 C<block_begin()>
78
79 Usage : $self->block_begin($module) within text_pm_file()
80 Purpose : Composes the standard code for top of a Perl pm file
81 Returns : String holding code for top of pm file
82 Argument : $module: pointer to the module being built
83 (as there can be more than one module built by EU::MM);
84 for the primary module it is a pointer to $self
85 Throws : n/a
86 Comment : This method is a likely candidate for alteration in a subclass,
87 e.g., you don't need Exporter-related code if you're building
88 an OO-module.
89 Comment : References $self keys NAME and (indirectly) VERSION
90
91 =cut
92  
93 sub block_begin
94 {
95 my ( $self, $module ) = @_;
96 my $version = $self->process_attribute( $module, 'VERSION' );
97 my $package_line = "package $module->{NAME};\n\n";
98 my $min_perl_version_line = "use " . ( $self->{ MIN_PERL_VERSION } // 5.010 ) . ";\n";
99 my $Id_line = q{#$Id#} . "\n";
100 my $strict_line = "use strict;\n";
101 my $warnings_line = "use warnings;\n"; # not included in standard version
102 my $encoding_line = "use utf8;\n";
103 my $data_dumper_line = "use Data::Dumper;\n";
104 my $log_line = "use Log::Any qw(\$log);\n";
105 my $scalar_util_line = "use Scalar::Util qw(blessed);\n";
106 my $begin_block = <<"END_OF_BEGIN";
107
108 BEGIN {
109 use Exporter ();
110 use vars qw(\$VERSION \@ISA \@EXPORT \@EXPORT_OK \%EXPORT_TAGS);
111 \$VERSION = '$version';
112 \@ISA = qw(Exporter);
113 #Give a hoot don't pollute, do not export more than needed by default
114 \@EXPORT = qw();
115 \@EXPORT_OK = qw();
116 \%EXPORT_TAGS = ();
117 }
118
119 END_OF_BEGIN
120  
121 my $text = $package_line;
122 $text .= $min_perl_version_line if $self->{ MIN_PERL_VERSION };
123 $text .= $Id_line if $self->{ INCLUDE_ID_LINE };
124 $text .= $strict_line;
125 $text .= $warnings_line if $self->{ INCLUDE_WARNINGS };
126 $text .= $encoding_line;
127 $text .= $data_dumper_line;
128 $text .= $log_line;
129 $text .= $scalar_util_line;
130 $text .= $begin_block;
131 return $text;
132 } ## end sub block_begin
133  
134 =head3 C<default_values()>
135  
136 Usage : $self->default_values() within complete_build()
137 Purpose : Build Makefile
138 Returns : Hash holding default_values
139 Argument : n/a
140 Throws : n/a
141 Comment : This method is a likely candidate for alteration in a subclass
142  
143 =cut
144  
145 sub default_values
146 {
147 my $self = shift;
148 my $defaults_ref = $self->SUPER::default_values();
149  
150 $defaults_ref->{ AUTHOR } = 'Luiz Benevenuto';
151 $defaults_ref->{ EMAIL } = 'luiz@siffra.com.br';
152 $defaults_ref->{ CPANID } = 'LUIZBENE';
153 $defaults_ref->{ WEBSITE } = 'https://siffra.com.br';
154 $defaults_ref->{ ORGANIZATION } = 'Siffra TI';
155  
156 $defaults_ref->{ VERBOSE } = 1;
157 $defaults_ref->{ MIN_PERL_VERSION } = '5.014';
158  
159 $defaults_ref->{ LICENSE } = 'perl';
160 $defaults_ref->{ INCLUDE_LICENSE } = 1;
161 $defaults_ref->{ INCLUDE_WARNINGS } = 1;
162 $defaults_ref->{ INCLUDE_MANIFEST_SKIP } = 1;
163 $defaults_ref->{ INCLUDE_POD_COVERAGE_TEST } = 1;
164 $defaults_ref->{ INCLUDE_POD_TEST } = 1;
165 $defaults_ref->{ INCLUDE_PERLCRITIC_TEST } = 1;
166 $defaults_ref->{ INCLUDE_SCRIPTS_DIRECTORY } = 1;
167 $defaults_ref->{ INCLUDE_FILE_IN_PM } = '/home/luiz/.modulemaker/ExtUtils/ModuleMaker/include_module.pm';
168  
169 return $defaults_ref;
170 } ## end sub default_values
171  
172 =head3 C<text_Makefile()>
173  
174 Usage : $self->text_Makefile() within complete_build()
175 Purpose : Build Makefile
176 Returns : String holding text of Makefile
177 Argument : n/a
178 Throws : n/a
179 Comment : This method is a likely candidate for alteration in a subclass
180  
181 =cut
182  
183 sub text_Makefile
184 {
185 my $self = shift;
186  
187 my %escaped = ();
188 for my $key ( qw| NAME FILE AUTHOR EMAIL ABSTRACT LICENSE MIN_PERL_VERSION ORGANIZATION CPANID | )
189 {
190 my $value = $self->{ $key };
191 ( $escaped{ $key } = $value ) =~ s{'}{\\'}g;
192 }
193  
194 ( my $nameFormat = $escaped{ NAME } ) =~ s{\:\:}{\-}g;
195  
196 my $text_of_Makefile = <<END_OF_MAKEFILE_TEXT;
197 use ExtUtils::MakeMaker;
198 use strict;
199 use warnings;
200  
201 # Call 'perldoc ExtUtils::MakeMaker' for details of how to influence
202 # the contents of the Makefile that is written.
203  
204 my %WriteMakefileArgs = (
205 NAME => '$escaped{NAME}',
206 VERSION_FROM => '$escaped{FILE}',
207 ABSTRACT_FROM => '$escaped{FILE}',
208 AUTHOR => '$escaped{AUTHOR} ($escaped{EMAIL})',
209 MIN_PERL_VERSION => '$escaped{MIN_PERL_VERSION}',
210 LICENSE => '$escaped{LICENSE}',
211 INSTALLDIRS => (\$] < 5.011 ? 'perl' : 'site'),
212 PREREQ_PM => {
213 'strict' => 0,
214 'warnings' => 0,
215 'Test::Simple' => 0.44,
216 'Test::More' => 0,
217 'Test::Perl::Critic' => 0,
218 'version' => 0,
219 'utf8' => 0,
220 'Log::Any' => 0,
221 'Scalar::Util' => 0,
222 'Data::Dumper' => 0,
223 },
224 BUILD_REQUIRES => {
225 'Test::More' => 0,
226 'ExtUtils::MakeMaker' => 0,
227 },
228 (
229 eval { ExtUtils::MakeMaker->VERSION(6.46) }
230 ? ()
231 : (
232 META_MERGE => {
233 'meta-spec' => { version => 2 },
234 dynamic_config => 1,
235 resources => {
236 homepage => 'https://siffra.com.br',
237 repository => {
238 url => 'git\@github.com:lbenevenuto/$nameFormat.git',
239 web => 'https://github.com/lbenevenuto/$nameFormat',
240 type => 'git',
241 },
242 bugtracker => {
243 web => 'https://github.com/lbenevenuto/$nameFormat/issues',
244 },
245 },
246 }
247 )
248 ),
249 dist => { COMPRESS => 'gzip -9f', SUFFIX => 'gz', },
250 clean => { FILES => '$nameFormat-* *.old *.bak' },
251 );
252  
253 WriteMakefile(\%WriteMakefileArgs);
254 END_OF_MAKEFILE_TEXT
255  
256 return $text_of_Makefile;
257 } ## end sub text_Makefile
258  
259 =head3 C<pod_wrapper()>
260
261 Usage : $self->pod_wrapper($string) within block_pod()
262 Purpose : When writing POD sections, you have to 'escape'
263 the POD markers to prevent the compiler from treating
264 them as real POD. This method 'unescapes' them and puts header
265 and closer around main POD block in pm file, along with warning
266 about stub documentation.
267 Argument : String holding text of POD which has been built up
268 within block_pod().
269 Comment : $head and $tail inside pod_wrapper() are optional and, in a
270 subclass, could be redefined as empty strings;
271 but $cutline is mandatory as it supplies the last =cut
272
273 =cut
274  
275 sub pod_wrapper
276 {
277 my ( $self, $podtext ) = @_;
278 my $head = <<'END_OF_HEAD';
279
280 #################### main pod documentation begin ###################
281 ## Below is the stub of documentation for your module.
282 ## You better edit it!
283
284 END_OF_HEAD
285  
286 my $cutline = <<'END_OF_CUT';
287
288 ====cut
289
290 END_OF_CUT
291  
292 my $tail = <<'END_OF_TAIL';
293 #################### main pod documentation end ###################
294
295 END_OF_TAIL
296  
297 my $encoding_section = <<'END_OF_ENCODING_SECTION';
298  
299 ====encoding UTF-8
300  
301 END_OF_ENCODING_SECTION
302  
303 $cutline =~ s/\n ====/\n=/g;
304 $encoding_section =~ s/\n ====/\n=/g;
305 return join(
306 q{},
307 $head, # optional
308 $encoding_section, # optional
309 $podtext, # required
310 $cutline, # required
311 $tail # optional
312 );
313 } ## end sub pod_wrapper
314  
315 =head3 C<text_perlcritic_test()>
316
317 Usage : $self->text_perlcritic_test() within complete_build()
318 Purpose : Composes text for t/pod-coverage.t
319 Returns : String with text of t/pod-coverage.t
320 Argument : n/a
321 Throws : n/a
322 Comment : Adapted from Andy Lester's Module::Starter
323 Comment : I don't think of much of this metric, but Andy and Damian do,
324 so if you want it you set INCLUDE_POD_COVERAGE_TEST => 1
325
326 =cut
327  
328 sub text_perlcritic_test
329 {
330 my $self = shift;
331  
332 my $text_of_perlcritic_test_test = <<'END_OF_TEXT_PERLCRITIC_TEST_TEST';
333 #!perl
334  
335 if (!require Test::Perl::Critic) {
336 Test::More::plan(
337 skip_all => "Test::Perl::Critic required for testing PBP compliance"
338 );
339 }
340  
341 Test::Perl::Critic::all_critic_ok();
342 END_OF_TEXT_PERLCRITIC_TEST_TEST
343  
344 return $text_of_perlcritic_test_test;
345 } ## end sub text_perlcritic_test
346  
347 =head3 C<complete_build()>
348
349 Usage : $self->pod_wrapper($string) within block_pod()
350 Purpose : When writing POD sections, you have to 'escape'
351 the POD markers to prevent the compiler from treating
352 them as real POD. This method 'unescapes' them and puts header
353 and closer around main POD block in pm file, along with warning
354 about stub documentation.
355 Argument : String holding text of POD which has been built up
356 within block_pod().
357 Comment : $head and $tail inside pod_wrapper() are optional and, in a
358 subclass, could be redefined as empty strings;
359 but $cutline is mandatory as it supplies the last =cut
360
361 =cut
362  
363 sub complete_build
364 {
365 my $self = shift;
366  
367 $self->create_base_directory();
368  
369 $self->create_directory( map { File::Spec->catdir( $self->{ Base_Dir }, $_ ) } qw{ lib t } ); # always on
370  
371 $self->create_directory( map { File::Spec->catdir( $self->{ Base_Dir }, $_ ) } qw{ scripts } )
372 if $self->{ INCLUDE_SCRIPTS_DIRECTORY }; # default is on
373  
374 $self->print_file( 'README', $self->text_README() ); # always on
375  
376 $self->print_file( 'LICENSE', $self->{ LicenseParts }{ LICENSETEXT } )
377 if $self->{ INCLUDE_LICENSE }; # default is on
378  
379 $self->print_file( 'Todo', $self->text_Todo() )
380 if $self->{ INCLUDE_TODO }; # default is on
381  
382 $self->print_file( 'Changes', $self->text_Changes() )
383 unless ( $self->{ CHANGES_IN_POD } ); # default is off
384  
385 $self->print_file( 'MANIFEST.SKIP', $self->text_MANIFEST_SKIP() )
386 if $self->{ INCLUDE_MANIFEST_SKIP }; # default is off
387  
388 $self->print_file( qq|t/pod-coverage.t|, $self->text_pod_coverage_test() )
389 if $self->{ INCLUDE_POD_COVERAGE_TEST }; # default is off
390  
391 $self->print_file( qq|t/pod.t|, $self->text_pod_test() )
392 if $self->{ INCLUDE_POD_TEST }; # default is off
393  
394 $self->print_file( qq|t/perlcritic.t|, $self->text_perlcritic_test() )
395 if $self->{ INCLUDE_PERLCRITIC_TEST }; # default is off
396  
397 if ( $self->{ BUILD_SYSTEM } eq 'ExtUtils::MakeMaker' )
398 {
399 $self->print_file( 'Makefile.PL', $self->text_Makefile() );
400 }
401 else
402 {
403 $self->print_file( 'Build.PL', $self->text_Buildfile() );
404 if ( $self->{ BUILD_SYSTEM } eq 'Module::Build and proxy Makefile.PL'
405 or $self->{ BUILD_SYSTEM } eq 'Module::Build and Proxy' )
406 {
407 $self->print_file( 'Makefile.PL', $self->text_proxy_makefile() );
408 }
409 } ## end else [ if ( $self->{ BUILD_SYSTEM...})]
410  
411 my @pmfiles = ( $self );
412 foreach my $f ( @{ $self->{ EXTRA_MODULES } } )
413 {
414 push @pmfiles, $f;
415 }
416 foreach my $module ( @pmfiles )
417 {
418 my ( $dir, $file ) = $self->_get_dir_and_file( $module );
419 $self->create_directory( join( '/', $self->{ Base_Dir }, $dir ) );
420 my $text_of_pm_file = $self->text_pm_file( $module );
421 $self->print_file( join( '/', $dir, $file ), $text_of_pm_file );
422 } ## end foreach my $module ( @pmfiles...)
423  
424 # How test files are created depends on how tests for EXTRA_MODULES
425 # are handled: 1 test file per extra module (default) or all tests for all
426 # modules in a single file (example: PBP).
427 unless ( $self->{ EXTRA_MODULES_SINGLE_TEST_FILE } )
428 {
429 my $ct = $self->{ FIRST_TEST_NUMBER };
430 foreach my $module ( @pmfiles )
431 {
432 my ( $teststart, $testmiddle );
433  
434 # Are we going to derive the lexical part of the test name from
435 # the name of the module it is testing? (non-default)
436 # Or are we simply going to use our pre-defined test name?
437 # (default)
438 if ( $self->{ TEST_NAME_DERIVED_FROM_MODULE_NAME } )
439 {
440 $testmiddle = $self->process_attribute( $module, 'NAME' );
441 $testmiddle =~ s|::|$self->{TEST_NAME_SEPARATOR}|g;
442 }
443 else
444 {
445 $testmiddle = $self->{ TEST_NAME };
446 }
447 #
448 # Are we going to include a number at start of test name?
449 # (default) If so, what is sprintf format and what character is
450 # used to separate it from the lexical part of the test name?
451 my $testfilename;
452 if ( defined $self->{ TEST_NUMBER_FORMAT } )
453 {
454 $teststart = "t/" . $self->{ TEST_NUMBER_FORMAT } . $self->{ TEST_NAME_SEPARATOR };
455 $testfilename = sprintf( $teststart . $testmiddle . q{.t}, $ct );
456 }
457 else
458 {
459 $teststart = "t/";
460 $testfilename = $teststart . $testmiddle . q{.t};
461 }
462  
463 $self->print_file( $testfilename, $self->text_test( $testfilename, $module ) );
464 $ct++;
465 } ## end foreach my $module ( @pmfiles...)
466 } ## end unless ( $self->{ EXTRA_MODULES_SINGLE_TEST_FILE...})
467 else
468 {
469 my ( $teststart, $testfilename );
470 if ( defined $self->{ TEST_NUMBER_FORMAT } )
471 {
472 $teststart = "t/" . $self->{ TEST_NUMBER_FORMAT } . $self->{ TEST_NAME_SEPARATOR };
473 $testfilename = sprintf( $teststart . $self->{ TEST_NAME } . q{.t}, $self->{ FIRST_TEST_NUMBER } );
474 }
475 else
476 {
477 $teststart = "t/";
478 $testfilename = $teststart . $self->{ TEST_NAME } . q{.t};
479 }
480 $self->print_file( $testfilename, $self->text_test_multi( $testfilename, \@pmfiles ) );
481 } ## end else
482  
483 $self->print_file( 'MANIFEST', join( "\n", @{ $self->{ MANIFEST } } ) );
484 $self->make_selections_defaults() if $self->{ SAVE_AS_DEFAULTS };
485 return 1;
486 } ## end sub complete_build
487  
488 #################### main pod documentation begin ###################
489 ## Below is the stub of documentation for your module.
490 ## You better edit it!
491  
492 =encoding UTF-8
493  
494  
495 =head1 NAME
496  
497 ExtUtils::ModuleMaker::Siffra - Module abstract (<= 44 characters) goes here
498  
499 =head1 SYNOPSIS
500  
501 use ExtUtils::ModuleMaker::Siffra;
502 blah blah blah
503  
504  
505 =head1 DESCRIPTION
506  
507 Stub documentation for this module was created by ExtUtils::ModuleMaker.
508 It looks like the author of the extension was negligent enough
509 to leave the stub unedited.
510  
511 Blah blah blah.
512  
513  
514 =head1 USAGE
515  
516  
517  
518 =head1 BUGS
519  
520  
521  
522 =head1 SUPPORT
523  
524  
525  
526 =head1 AUTHOR
527  
528 Luiz Benevenuto
529 CPAN ID: LUIZBENE
530 Siffra TI
531 luiz@siffra.com.br
532 https://siffra.com.br
533  
534 =head1 COPYRIGHT
535  
536 This program is free software; you can redistribute
537 it and/or modify it under the same terms as Perl itself.
538  
539 The full text of the license can be found in the
540 LICENSE file included with this module.
541  
542  
543 =head1 SEE ALSO
544  
545 perl(1).
546
547 =cut
548  
549 #################### main pod documentation end ###################
550  
551 1;
552  
553 # The preceding line will help the module return a true value
554  
↑ Summary