File Coverage

blib/lib/ExtUtils/ModuleMaker/StandardText.pm
Criterion Covered Total %
statement 168 177 94.9
branch 39 50 78.0
condition 3 3 100.0
subroutine 34 34 100.0
pod 25 26 96.1
total 269 290 92.7


line stmt bran cond sub pod time code
1             package ExtUtils::ModuleMaker::StandardText;
2             #$Id$
3 86     86   392 use strict;
  86         92  
  86         2020  
4 86     86   265 use warnings;
  86         80  
  86         1836  
5 86     86   244 use vars qw ( $VERSION );
  86         94  
  86         3352  
6             $VERSION = 0.56;
7 86         3508 use ExtUtils::ModuleMaker::Licenses::Standard qw(
8             Get_Standard_License
9             Verify_Standard_License
10 86     86   301 );
  86         86  
11 86         2942 use ExtUtils::ModuleMaker::Licenses::Local qw(
12             Get_Local_License
13             Verify_Local_License
14 86     86   296 );
  86         93  
15 86     86   283 use File::Path;
  86         106  
  86         3314  
16 86     86   311 use File::Spec;
  86         85  
  86         1420  
17 86     86   233 use Carp;
  86         75  
  86         133078  
18              
19             =head1 NAME
20              
21             ExtUtils::ModuleMaker::StandardText - Methods used within ExtUtils::ModuleMaker
22              
23             =head1 DESCRIPTION
24              
25             The methods described below are 'quasi-private' methods which are called by
26             the publicly available methods of ExtUtils::ModuleMaker and
27             ExtUtils::ModuleMaker::Interactive. They are 'quasi-private' in the sense
28             that they are not intended to be called by the everyday user of
29             ExtUtils::ModuleMaker. Nothing prevents a user from calling these
30             methods, but they are documented here primarily so that users
31             writing plug-ins for ExtUtils::ModuleMaker's standard text will know what methods
32             need to be subclassed.
33              
34             The methods below are called in C
35             but not in that same package's C. For methods called in
36             C, please see ExtUtils::ModuleMaker::Initializers.
37              
38             The descriptions below are presented in hierarchical order rather than
39             alphabetically. The order is that of ''how close to the surface can a
40             particular method called?'', where 'surface' means being called within
41             C.
42             So methods called within C are described before
43             methods which are only called within other quasi-private methods. Some of the
44             methods described are also called within ExtUtils::ModuleMaker::Interactive
45             methods. And some quasi-private methods are called within both public and
46             other quasi-private methods. Within each heading, methods are presented more
47             or less as they are first called within the public or higher-order
48             quasi-private methods.
49              
50             Happy subclassing!
51              
52             =head1 METHODS
53              
54             =head2 Methods Called within C
55              
56             =head3 C
57              
58             Usage : $self->create_base_directory within complete_build()
59             Purpose : Create the directory where all the files will be created.
60             Returns : $DIR = directory name where the files will live
61             Argument : n/a
62             Comment : $self keys Base_Dir, COMPACT, NAME. Calls method create_directory.
63              
64             =cut
65              
66             sub create_base_directory {
67 75     75 1 113 my $self = shift;
68              
69             $self->{Base_Dir} = File::Spec->rel2abs(
70 75 100       2556 join( ( $self->{COMPACT} ) ? q{-} : q{/}, split( /::/, $self->{NAME} ) )
71             );
72              
73 75         465 $self->create_directory( $self->{Base_Dir} );
74             }
75              
76             =head3 C
77              
78             Usage : create_directory( [ I ] )
79             in complete_build; create_base_directory; create_pm_basics
80             Purpose : Creates directory(ies) requested.
81             Returns : n/a
82             Argument : Reference to an array holding list of directories to be created.
83             Comment : Essentially a wrapper around File::Path::mkpath. Will use
84             values in $self keys VERBOSE and PERMISSIONS to provide
85             2nd and 3rd arguments to mkpath if requested.
86             Comment : Adds to death message in event of failure.
87              
88             =cut
89              
90             sub create_directory {
91 314     314 1 364 my $self = shift;
92              
93 314         36472 return mkpath( \@_, $self->{VERBOSE}, $self->{PERMISSIONS} );
94 0         0 $self->death_message( [ "Can't create a directory: $!" ] );
95             }
96              
97             =head3 C
98              
99             Usage : $self->print_file($filename, $filetext) within complete_build()
100             Purpose : Adds the file being created to MANIFEST, then prints text to new
101             file. Logs file creation under verbose. Adds info for
102             death_message in event of failure.
103             Returns : n/a
104             Argument : 2 arguments: filename and text to be printed
105             Comment :
106              
107             =cut
108              
109             sub print_file {
110 623     623 1 984 my ( $self, $filename, $filetext ) = @_;
111              
112 623 100       1191 push( @{ $self->{MANIFEST} }, $filename )
  548         1047  
113             unless ( $filename eq 'MANIFEST' );
114 623         1676 $self->log_message( qq{writing file '$filename'});
115              
116 623         4810 my $file = File::Spec->catfile( $self->{Base_Dir}, $filename );
117 623         1271 local *FILE;
118 623 50       30763 open( FILE, ">$file" )
119             or $self->death_message( [ qq{Could not write '$filename', $!} ] );
120 623         6249 print FILE $filetext;
121 623         15143 close FILE;
122             }
123              
124             =head2 Methods Called within C as an Argument to C
125              
126             =head3 C
127              
128             Usage : $self->text_README() within complete_build()
129             Purpose : Build README
130             Returns : String holding text of README
131             Argument : n/a
132             Throws : n/a
133             Comment : This method is a likely candidate for alteration in a subclass
134              
135             =cut
136              
137             sub text_README {
138 75     75 1 148 my $self = shift;
139 75         518 my %README_text = (
140             eumm_instructions => <<'END_OF_MAKE',
141             perl Makefile.PL
142             make
143             make test
144             make install
145             END_OF_MAKE
146             mb_instructions => <<'END_OF_BUILD',
147             perl Build.PL
148             ./Build
149             ./Build test
150             ./Build install
151             END_OF_BUILD
152             readme_top => <<'END_OF_TOP',
153              
154             If this is still here it means the programmer was too lazy to create the readme file.
155              
156             You can create it now by using the command shown above from this directory.
157              
158             At the very least you should be able to use this set of instructions
159             to install the module...
160              
161             END_OF_TOP
162             readme_bottom => <<'END_OF_BOTTOM',
163              
164             If you are on a windows box you should use 'nmake' rather than 'make'.
165             END_OF_BOTTOM
166             );
167              
168 75         238 my $pod2textline = "pod2text $self->{NAME}.pm > README\n";
169             my $build_instructions =
170             ( $self->{BUILD_SYSTEM} eq 'ExtUtils::MakeMaker' )
171             ? $README_text{eumm_instructions}
172 75 100       290 : $README_text{mb_instructions};
173             return $pod2textline .
174             $README_text{readme_top} .
175             $build_instructions .
176 75         548 $README_text{readme_bottom};
177             }
178              
179             =head3 C
180              
181             Usage : $self->text_Todo() within complete_build()
182             Purpose : Composes text for Todo file
183             Returns : String with text of Todo file
184             Argument : n/a
185             Throws : n/a
186             Comment : This method is a likely candidate for alteration in a subclass
187             Comment : References $self key NAME
188              
189             =cut
190              
191             sub text_Todo {
192 74     74 1 138 my $self = shift;
193              
194 74         239 my $text = <
195             TODO list for Perl module $self->{NAME}
196              
197             - Nothing yet
198              
199              
200             EOF
201              
202 74         207 return $text;
203             }
204              
205             =head3 C
206              
207             Usage : $self->text_Changes($only_in_pod) within complete_build;
208             block_pod()
209             Purpose : Composes text for Changes file
210             Returns : String holding text for Changes file
211             Argument : $only_in_pod: True value to get only a HISTORY section for POD
212             False value to get whole Changes file
213             Throws : n/a
214             Comment : This method is a likely candidate for alteration in a subclass
215             Comment : Accesses $self keys NAME, VERSION, timestamp, eumm_version
216              
217             =cut
218              
219             sub text_Changes {
220 75     75 1 153 my ( $self, $only_in_pod ) = @_;
221              
222 75         103 my $text_of_Changes;
223              
224 75 100       209 unless ($only_in_pod) {
225 71         811 $text_of_Changes = <
226             Revision history for Perl module $self->{NAME}
227              
228             $self->{VERSION} $self->{timestamp}
229             - original version; created by ExtUtils::ModuleMaker $self->{eumm_version}
230              
231              
232             EOF
233             }
234             else {
235 4         45 $text_of_Changes = <
236             $self->{VERSION} $self->{timestamp}
237             - original version; created by ExtUtils::ModuleMaker $self->{eumm_version}
238             EOF
239             }
240              
241 75         211 return $text_of_Changes;
242             }
243              
244             =head3 C
245              
246             Usage : $self->text_test within complete_build($testnum, $module)
247             Purpose : Composes text for a test for each pm file being requested in
248             call to EU::MM
249             Returns : String holding complete text for a test file.
250             Argument : Two arguments: $testnum and $module
251             Throws : n/a
252             Comment : This method is a likely candidate for alteration in a subclass
253             Will make a test with or without a checking for method new.
254              
255             =cut
256              
257             sub text_test {
258 82     82 1 136 my ( $self, $testfilename, $module ) = @_;
259              
260 82         173 my $name = $self->process_attribute( $module, 'NAME' );
261 82         191 my $neednew = $self->process_attribute( $module, 'NEED_NEW_METHOD' );
262              
263 82         103 my %test_file_texts;
264 82         393 $test_file_texts{neednew} = <
265             # -*- perl -*-
266              
267             # $testfilename - check module loading and create testing directory
268              
269             use Test::More tests => 2;
270              
271             BEGIN { use_ok( '$module->{NAME}' ); }
272              
273             my \$object = ${name}->new ();
274             isa_ok (\$object, '$module->{NAME}');
275              
276              
277             MFNN
278              
279 82         287 $test_file_texts{zeronew} = <
280             # -*- perl -*-
281              
282             # $testfilename - check module loading and create testing directory
283              
284             use Test::More tests => 1;
285              
286             BEGIN { use_ok( '$module->{NAME}' ); }
287              
288              
289             MFZN
290              
291             return $neednew ? $test_file_texts{neednew}
292 82 100       328 : $test_file_texts{zeronew};
293             }
294              
295             sub text_test_multi {
296 2     2 0 4 my ( $self, $testfilename, $pmfilesref ) = @_;
297 2         2 my @pmfiles = @{$pmfilesref};
  2         6  
298              
299 2         4 my $top = <
300             # -*- perl -*-
301              
302             # $testfilename - check module loading and create testing directory
303             END_OF_TOP
304              
305 2         5 my $number_line = q{use Test::More tests => } . scalar(@pmfiles) . q{;};
306              
307 2         4 my $begin_block = "BEGIN {\n";
308 2         4 foreach my $f (@pmfiles) {
309 8         13 $begin_block .= " use_ok( '$f->{NAME}' );\n";
310             }
311 2         4 $begin_block .= "}\n";
312              
313 2         4 my $text_of_test_file = join("\n", (
314             $top,
315             $number_line,
316             $begin_block,
317             )
318             );
319 2         6 return $text_of_test_file;
320             }
321              
322             =head3 C
323              
324             Usage : $self->text_Makefile() within complete_build()
325             Purpose : Build Makefile
326             Returns : String holding text of Makefile
327             Argument : n/a
328             Throws : n/a
329             Comment : This method is a likely candidate for alteration in a subclass
330              
331             =cut
332              
333             sub text_Makefile {
334 72     72 1 125 my $self = shift;
335 72         157 my $Makefile_format = q~
336              
337             use ExtUtils::MakeMaker;
338             # See lib/ExtUtils/MakeMaker.pm for details of how to influence
339             # the contents of the Makefile that is written.
340             WriteMakefile(
341             NAME => '%s',
342             VERSION_FROM => '%s', # finds \$VERSION
343             AUTHOR => '%s (%s)',
344             ABSTRACT => '%s',
345             PREREQ_PM => {
346             'Test::Simple' => 0.44,
347             },
348             );
349             ~;
350             my $text_of_Makefile = sprintf $Makefile_format,
351 360         283 map { my $s = $_; $s =~ s{'}{\\'}g; $s; }
  360         367  
  360         727  
352             $self->{NAME},
353             $self->{FILE},
354             $self->{AUTHOR},
355             $self->{EMAIL},
356 72         216 $self->{ABSTRACT};
357 72         215 return $text_of_Makefile;
358             }
359              
360             =head3 C
361              
362             Usage : $self->text_Buildfile() within complete_build()
363             Purpose : Composes text for a Buildfile for Module::Build
364             Returns : String holding text for Buildfile
365             Argument : n/a
366             Throws : n/a
367             Comment : This method is a likely candidate for alteration in a subclass,
368             e.g., respond to improvements in Module::Build
369             Comment : References $self keys NAME and LICENSE
370              
371             =cut
372              
373             sub text_Buildfile {
374 3     3 1 6 my $self = shift;
375              
376             # As of 0.15, Module::Build only allows a few licenses
377 3 50       19 my $license_line = 1 if $self->{LICENSE} =~ /^(?:perl|gpl|artistic)$/;
378              
379 3         10 my $text_of_Buildfile = <
380             use Module::Build;
381             # See perldoc Module::Build for details of how this works
382              
383             Module::Build->new
384             ( module_name => '$self->{NAME}',
385             EOF
386              
387 3 50       6 if ($license_line) {
388              
389 3         8 $text_of_Buildfile .= <
390             license => '$self->{LICENSE}',
391             EOF
392              
393             }
394              
395 3         6 $text_of_Buildfile .= <
396             )->create_build_script;
397             EOF
398              
399 3         8 return $text_of_Buildfile;
400              
401             }
402              
403             =head3 C
404              
405             Usage : $self->text_proxy_makefile() within complete_build()
406             Purpose : Composes text for proxy makefile
407             Returns : String holding text for proxy makefile
408             Argument : n/a
409             Throws : n/a
410             Comment : This method is a likely candidate for alteration in a subclass
411              
412             =cut
413              
414             sub text_proxy_makefile {
415 2     2 1 2 my $self = shift;
416              
417             # This comes directly from the docs for Module::Build::Compat
418 2         4 my $text_of_proxy = <<'EOF';
419             unless (eval "use Module::Build::Compat 0.02; 1" ) {
420             print "This module requires Module::Build to install itself.\n";
421              
422             require ExtUtils::MakeMaker;
423             my $yn = ExtUtils::MakeMaker::prompt
424             (' Install Module::Build from CPAN?', 'y');
425              
426             if ($yn =~ /^y/i) {
427             require Cwd;
428             require File::Spec;
429             require CPAN;
430              
431             # Save this 'cause CPAN will chdir all over the place.
432             my $cwd = Cwd::cwd();
433             my $makefile = File::Spec->rel2abs($0);
434              
435             CPAN::Shell->install('Module::Build::Compat');
436              
437             chdir $cwd or die "Cannot chdir() back to $cwd: $!";
438             exec $^X, $makefile, @ARGV; # Redo now that we have Module::Build
439             } else {
440             warn " *** Cannot install without Module::Build. Exiting ...\n";
441             exit 1;
442             }
443             }
444             Module::Build::Compat->run_build_pl(args => \@ARGV);
445             Module::Build::Compat->write_makefile();
446             EOF
447              
448 2         3 return $text_of_proxy;
449             }
450              
451             =head3 C
452              
453             Usage : $self->text_MANIFEST_SKIP() within complete_build()
454             Purpose : Composes text for MANIFEST.SKIP file
455             Returns : String with text of MANIFEST.SKIP file
456             Argument : n/a
457             Throws : n/a
458             Comment : References $self key NAME
459             Comment : Adapted from David Golden's ExtUtils::ModuleMaker::TT
460              
461             =cut
462              
463             sub text_MANIFEST_SKIP {
464 1     1 1 2 my $self = shift;
465              
466 1         2 my $text_of_SKIP = <<'END_OF_SKIP';
467             # Version control files and dirs.
468             \bRCS\b
469             \bCVS\b
470             ,v$
471             .svn/
472              
473             # ExtUtils::MakeMaker generated files and dirs.
474             ^MANIFEST\.(?!SKIP)
475             ^Makefile$
476             ^blib/
477             ^blibdirs$
478             ^PM_to_blib$
479             ^MakeMaker-\d
480            
481             # Module::Build
482             ^Build$
483             ^_build
484              
485             # Temp, old, vi and emacs files.
486             ~$
487             \.old$
488             ^#.*#$
489             ^\.#
490             \.swp$
491             \.bak$
492             END_OF_SKIP
493              
494 1         3 return $text_of_SKIP;
495             }
496              
497             =head3 C
498              
499             Usage : $self->text_pod_coverage_test() within complete_build()
500             Purpose : Composes text for t/pod-coverage.t
501             Returns : String with text of t/pod-coverage.t
502             Argument : n/a
503             Throws : n/a
504             Comment : Adapted from Andy Lester's Module::Starter
505             Comment : I don't think of much of this metric, but Andy and Damian do,
506             so if you want it you set INCLUDE_POD_COVERAGE_TEST => 1
507              
508             =cut
509              
510             sub text_pod_coverage_test {
511 1     1 1 2 my $self = shift;
512              
513 1         2 my $text_of_pod_coverage_test = <<'END_OF_POD_COVERAGE_TEST';
514             #!perl -T
515              
516             use Test::More;
517             eval "use Test::Pod::Coverage 1.04";
518             plan skip_all => "Test::Pod::Coverage 1.04 required for testing POD coverage"
519             if $@;
520             all_pod_coverage_ok();
521             END_OF_POD_COVERAGE_TEST
522              
523 1         2 return $text_of_pod_coverage_test;
524             }
525              
526             =head3 C
527              
528             Usage : $self->text_pod_test() within complete_build()
529             Purpose : Composes text for t/pod.t
530             Returns : String with text of t/pod.t
531             Argument : n/a
532             Throws : n/a
533             Comment : Adapted from Andy Lester's Module::Starter
534             Comment : I don't think of much of this metric, but Andy and Damian do,
535             so if you want it you set INCLUDE_POD_TEST => 1
536              
537             =cut
538              
539             sub text_pod_test {
540 1     1 1 2 my $self = shift;
541              
542 1         1 my $text_of_pod_test = <<'END_OF_POD_TEST';
543             #!perl -T
544              
545             use Test::More;
546             eval "use Test::Pod 1.14";
547             plan skip_all => "Test::Pod 1.14 required for testing POD" if $@;
548             all_pod_files_ok();
549             END_OF_POD_TEST
550              
551 1         3 return $text_of_pod_test;
552             }
553              
554             =head3 C
555              
556             Usage : $self->text_pm_file($module) within complete_build()
557             Purpose : Composes a string holding all elements for a pm file
558             Returns : String holding text for a pm file
559             Argument : $module: pointer to the module being built
560             (as there can be more than one module built by EU::MM);
561             for the primary module it is a pointer to $self
562              
563             =cut
564              
565             sub text_pm_file {
566 90     90 1 141 my $self = shift;
567 90         111 my $module = shift;
568            
569 90         430 my $text_of_pm_file = $self->block_begin($module);
570              
571 90 100 100     210 $text_of_pm_file .= (
572             (
573             (
574             ( $self->process_attribute( $module, 'NEED_POD' ) )
575             && ( $self->process_attribute( $module, 'NEED_NEW_METHOD' ) )
576             )
577             ? $self->block_subroutine_header($module)
578             : q{}
579             )
580             );
581              
582 90 100       200 $text_of_pm_file .= (
583             ( $self->process_attribute( $module, 'NEED_NEW_METHOD' ) )
584             ? $self->block_new_method()
585             : q{}
586             );
587              
588 90 100       195 $text_of_pm_file .= (
589             ( $self->process_attribute( $module, 'INCLUDE_FILE_IN_PM' ) )
590             ? $self->block_include_file_in_pm()
591             : q{}
592             );
593              
594 90 100       200 $text_of_pm_file .= (
595             ( $self->process_attribute( $module, 'NEED_POD' ) )
596             ? $self->block_pod($module)
597             : q{}
598             );
599              
600 90         477 $text_of_pm_file .= $self->block_final();
601 90         325 return ($module, $text_of_pm_file);
602             }
603              
604             =head2 Methods Called within C
605              
606             =head3 C
607              
608             Usage : $self->block_begin($module) within text_pm_file()
609             Purpose : Composes the standard code for top of a Perl pm file
610             Returns : String holding code for top of pm file
611             Argument : $module: pointer to the module being built
612             (as there can be more than one module built by EU::MM);
613             for the primary module it is a pointer to $self
614             Throws : n/a
615             Comment : This method is a likely candidate for alteration in a subclass,
616             e.g., you don't need Exporter-related code if you're building
617             an OO-module.
618             Comment : References $self keys NAME and (indirectly) VERSION
619              
620             =cut
621              
622             sub block_begin {
623 90     90 1 133 my ( $self, $module ) = @_;
624 90         421 my $version = $self->process_attribute( $module, 'VERSION' );
625 90         245 my $package_line = "package $module->{NAME};\n";
626 90         124 my $Id_line = q{#$Id#} . "\n";
627 90         148 my $strict_line = "use strict;\n";
628 90         124 my $warnings_line = "use warnings;\n"; # not included in standard version
629 90         199 my $begin_block = <<"END_OF_BEGIN";
630              
631             BEGIN {
632             use Exporter ();
633             use vars qw(\$VERSION \@ISA \@EXPORT \@EXPORT_OK \%EXPORT_TAGS);
634             \$VERSION = '$version';
635             \@ISA = qw(Exporter);
636             #Give a hoot don't pollute, do not export more than needed by default
637             \@EXPORT = qw();
638             \@EXPORT_OK = qw();
639             \%EXPORT_TAGS = ();
640             }
641              
642             END_OF_BEGIN
643             # my $text =
644             # $package_line .
645             # $strict_line .
646             # # $warnings_line .
647             # $begin_block;
648 90         128 my $text = $package_line;
649 90 100       214 $text .= $Id_line if $self->{INCLUDE_ID_LINE};
650 90         148 $text .= $strict_line;
651 90 100       210 $text .= $warnings_line if $self->{INCLUDE_WARNINGS};
652 90         149 $text .= $begin_block;
653 90         161 return $text;
654             }
655              
656             =head3 C
657              
658             Usage : $self->process_attribute($module, @keys)
659             within block_begin(), text_test(),
660             text_pm_file(), block_pod(), complete_build()
661             Purpose :
662             For the particular .pm file now being processed (value of the
663             NAME key of the first argument: $module), see if there exists a
664             key whose name is the second argument. If so, return it.
665             Otherwise, return the value of the key by that name in the
666             EU::MM object. If we have a two-level hash (currently only in
667             License_Parts, process down to that level.
668             Arguments : First argument is a reference to an anonymous hash which has at
669             least one element with key NAME and value of the module being
670             processed. Second is an array of key names, although in all but
671             one case it's a single-element (NAME) array.
672             Comment : [The method's name is very opaque and not self-documenting.
673             Function of the code is not easily evident. Rename? Refactor?]
674              
675             =cut
676              
677             sub process_attribute {
678 1058     1058 1 1336 my ( $self, $module, @keys ) = @_;
679              
680 1058 100       1532 if ( scalar(@keys) == 1 ) {
681             return ( $module->{ $keys[0] } )
682 970 100       3816 if ( exists( ( $module->{ $keys[0] } ) ) );
683 129         252 return ( $self->{ $keys[0] } );
684             }
685             else { # only alternative currently possible is @keys == 2
686             return ( $module->{ $keys[0] }{ $keys[1] } )
687 88 100       415 if ( exists( ( $module->{ $keys[0] }{ $keys[1] } ) ) );
688 15         27 return ( $self->{ $keys[0] }{ $keys[1] } );
689             }
690             }
691              
692             =head3 C
693              
694             Usage : $self->block_subroutine_header($module) within text_pm_file()
695             Purpose : Composes an inline comment for pm file (much like this inline
696             comment) which documents purpose of a subroutine
697             Returns : String containing text for inline comment
698             Argument : $module: pointer to the module being built
699             (as there can be more than one module built by EU::MM);
700             for the primary module it is a pointer to $self
701             Throws : n/a
702             Comment : This method is a likely candidate for alteration in a subclass
703             E.g., some may prefer this info to appear in POD rather than
704             inline comments.
705              
706             =cut
707              
708             sub block_subroutine_header {
709 87     87 1 130 my ( $self, $module ) = @_;
710 87         167 my $text_of_subroutine_pod = <
711              
712             #################### subroutine header begin ####################
713              
714             ====head2 sample_function
715              
716             Usage : How to use this function/method
717             Purpose : What it does
718             Returns : What it returns
719             Argument : What it wants to know
720             Throws : Exceptions and other anomolies
721             Comment : This is a sample subroutine header.
722             : It is polite to include more pod and fewer comments.
723              
724             See Also :
725              
726             ====cut
727              
728             #################### subroutine header end ####################
729              
730             EOFBLOCK
731              
732 87         477 $text_of_subroutine_pod =~ s/\n ====/\n=/g;
733 87         248 return $text_of_subroutine_pod;
734             }
735              
736             =head3 C
737              
738             Usage : $self->block_new_method() within text_pm_file()
739             Purpose : Build 'new()' method as part of a pm file
740             Returns : String holding sub new.
741             Argument : $module: pointer to the module being built
742             (as there can be more than one module built by EU::MM);
743             for the primary module it is a pointer to $self
744             Throws : n/a
745             Comment : This method is a likely candidate for alteration in a subclass,
746             e.g., pass a single hash-ref to new() instead of a list of
747             parameters.
748              
749             =cut
750              
751             sub block_new_method {
752 87     87 1 113 my $self = shift;
753 87         193 return <<'EOFBLOCK';
754              
755             sub new
756             {
757             my ($class, %parameters) = @_;
758              
759             my $self = bless ({}, ref ($class) || $class);
760              
761             return $self;
762             }
763              
764             EOFBLOCK
765             }
766              
767             =head3 C
768              
769             Usage : $self->block_include_file_in_pm() within text_pm_file()
770             Purpose : Include text from an arbitrary file on disk in .pm file,
771             e.g., subroutine stubs you want in each of several extra
772             modules.
773             Returns : String holding text of arbitrary file.
774             Argument : $module: pointer to the module being built
775             (as there can be more than one module built by EU::MM);
776             for the primary module it is a pointer to $self
777             Throws : n/a
778             Comment : References $self->{INCLUDE_FILE_IN_PM}, whose value must be a
779             path to a single, readable file
780              
781             =cut
782              
783             sub block_include_file_in_pm {
784 4     4 1 3 my ( $self, $module ) = @_;
785 4         5 my $arb = $self->{INCLUDE_FILE_IN_PM};
786 4         7 local *ARB;
787 4 50       107 open ARB, $arb or croak "Could not open $arb for inclusion: $!";
788 4         5 my $text_included = do { local $/; };
  4         10  
  4         49  
789 4 50       20 close ARB or croak "Could not close $arb after reading: $!";
790 4         12 return $text_included;
791             }
792              
793             =head3 C
794              
795             Usage : $self->block_pod($module) inside text_pm_file()
796             Purpose : Compose the main POD section within a pm file
797             Returns : String holding main POD section
798             Argument : $module: pointer to the module being built
799             (as there can be more than one module built by EU::MM);
800             for the primary module it is a pointer to $self
801             Throws : n/a
802             Comment : This method is a likely candidate for alteration in a subclass
803             Comment : In StandardText formulation, contains the following components:
804             warning about stub documentation needing editing
805             pod wrapper top
806             NAME - ABSTRACT
807             SYNOPSIS
808             DESCRIPTION
809             USAGE
810             BUGS
811             SUPPORT
812             HISTORY (as requested)
813             AUTHOR
814             COPYRIGHT
815             SEE ALSO
816             pod wrapper bottom
817              
818             =cut
819              
820             sub block_pod {
821 88     88 1 132 my ( $self, $module ) = @_;
822              
823 88         188 my $name = $self->process_attribute( $module, 'NAME' );
824 88         180 my $abstract = $self->process_attribute( $module, 'ABSTRACT' );
825 88         216 my $synopsis = qq{ use $name;\n blah blah blah\n};
826 88         123 my $description = <
827             Stub documentation for this module was created by ExtUtils::ModuleMaker.
828             It looks like the author of the extension was negligent enough
829             to leave the stub unedited.
830              
831             Blah blah blah.
832             END_OF_DESC
833 88         174 my $author_composite = $self->process_attribute( $module, 'COMPOSITE' );
834 88         205 my $copyright = $self->process_attribute( $module, 'LicenseParts', 'COPYRIGHT');
835 88         143 my $see_also = q{perl(1).};
836              
837             my $text_of_pod = join(
838             q{},
839             $self->pod_section( NAME => $name .
840             ( (defined $abstract) ? qq{ - $abstract} : q{} )
841             ),
842             $self->pod_section( SYNOPSIS => $synopsis ),
843             $self->pod_section( DESCRIPTION => $description ),
844             $self->pod_section( USAGE => q{} ),
845             $self->pod_section( BUGS => q{} ),
846             $self->pod_section( SUPPORT => q{} ),
847             (
848             ( $self->{CHANGES_IN_POD} )
849 88 50       650 ? $self->pod_section(
    100          
850             HISTORY => $self->text_Changes('only pod')
851             )
852             : q{}
853             ),
854             $self->pod_section( AUTHOR => $author_composite),
855             $self->pod_section( COPYRIGHT => $copyright),
856             $self->pod_section( 'SEE ALSO' => $see_also),
857             );
858              
859 88         677 return $self->pod_wrapper($text_of_pod);
860             }
861              
862             =head3 C
863              
864             Usage : $self->block_final() within text_pm_file()
865             Purpose : Compose code and comment that conclude a pm file and guarantee
866             that the module returns a true value
867             Returns : String containing code and comment concluding a pm file
868             Argument : $module: pointer to the module being built
869             (as there can be more than one module built by EU::MM);
870             for the primary module it is a pointer to $self
871             Throws : n/a
872             Comment : This method is a likely candidate for alteration in a subclass,
873             e.g., some may not want the comment line included.
874              
875             =cut
876              
877              
878             sub block_final {
879 90     90 1 107 my $self = shift;
880 90         263 return <
881              
882             1;
883             # The preceding line will help the module return a true value
884              
885             EOFBLOCK
886             }
887              
888             =head2 All Other Methods
889              
890             =head3 C
891              
892             Usage : $self->death_message( [ I ] )
893             in validate_values; create_directory; print_file
894             Purpose : Croaks with error message composed from elements in the list
895             passed by reference as argument
896             Returns : [ To come. ]
897             Argument : Reference to an array holding list of error messages accumulated
898             Comment : Different functioning in modulemaker interactive mode
899              
900             =cut
901              
902             sub death_message {
903 9     9 1 10 my $self = shift;
904 9         14 my $errorref = shift;
905 9         15 my @errors = @{$errorref};
  9         17  
906              
907             croak( join "\n", @errors, q{}, $self->{USAGE_MESSAGE} )
908 9 50       1650 unless $self->{INTERACTIVE};
909 0         0 my %err = map {$_, 1} @errors;
  0         0  
910 0 0       0 delete $err{'NAME is required'} if $err{'NAME is required'};
911 0         0 @errors = keys %err;
912 0 0       0 if (@errors) {
913 0         0 print( join "\n",
914             'Oops, there are the following errors:', @errors, q{} );
915 0         0 return 1;
916             } else {
917 0         0 return;
918             }
919             }
920              
921             =head3 C
922              
923             Usage : $self->log_message( $message ) in print_file;
924             Purpose : Prints log_message (currently, to STDOUT) if $self->{VERBOSE}
925             Returns : n/a
926             Argument : Scalar holding message to be logged
927             Comment :
928              
929             =cut
930              
931             sub log_message {
932 623     623 1 579 my ( $self, $message ) = @_;
933 623 100       1307 print "$message\n" if $self->{VERBOSE};
934             }
935              
936             =head3 C
937              
938             Usage : $self->pod_section($heading, $content) within
939             block_pod()
940             Purpose : When writing POD sections, you have to 'escape'
941             the POD markers to prevent the compiler from treating
942             them as real POD. This method 'unescapes' them and puts header
943             and closer around individual POD headings within pm file.
944             Arguments : Variables holding POD section name and text of POD section.
945              
946             =cut
947              
948             sub pod_section {
949 796     796 1 740 my ( $self, $heading, $content ) = @_;
950 796         1140 my $text_of_pod_section = <
951              
952             ====head1 $heading
953              
954             $content
955             END_OF_SECTION
956              
957 796         1464 $text_of_pod_section =~ s/\n ====/\n=/g;
958 796         1917 return $text_of_pod_section;
959             }
960              
961             =head3 C
962              
963             Usage : $self->pod_wrapper($string) within block_pod()
964             Purpose : When writing POD sections, you have to 'escape'
965             the POD markers to prevent the compiler from treating
966             them as real POD. This method 'unescapes' them and puts header
967             and closer around main POD block in pm file, along with warning
968             about stub documentation.
969             Argument : String holding text of POD which has been built up
970             within block_pod().
971             Comment : $head and $tail inside pod_wrapper() are optional and, in a
972             subclass, could be redefined as empty strings;
973             but $cutline is mandatory as it supplies the last =cut
974              
975             =cut
976              
977             sub pod_wrapper {
978 88     88 1 130 my ( $self, $podtext ) = @_;
979 88         157 my $head = <<'END_OF_HEAD';
980              
981             #################### main pod documentation begin ###################
982             ## Below is the stub of documentation for your module.
983             ## You better edit it!
984              
985             END_OF_HEAD
986 88         112 my $cutline = <<'END_OF_CUT';
987              
988             ====cut
989              
990             END_OF_CUT
991 88         136 my $tail = <<'END_OF_TAIL';
992             #################### main pod documentation end ###################
993              
994             END_OF_TAIL
995              
996 88         211 $cutline =~ s/\n ====/\n=/g;
997 88         491 return join( q{},
998             $head, # optional
999             $podtext, # required
1000             $cutline, # required
1001             $tail # optional
1002             );
1003             }
1004              
1005             =head1 SEE ALSO
1006              
1007             F, F.
1008              
1009             =cut
1010              
1011             1;
1012              
1013