File Coverage

blib/lib/Bigtop/Backend/Init/Std.pm
Criterion Covered Total %
statement 28 67 41.7
branch 0 22 0.0
condition 0 5 0.0
subroutine 10 15 66.6
pod n/a
total 38 109 34.8


line stmt bran cond sub pod time code
1             package Bigtop::Backend::Init::Std;
2 1     1   3609 use strict; use warnings;
  1     1   3  
  1         48  
  1         8  
  1         2  
  1         36  
3              
4 1     1   6 use Cwd; # for use in manifest updates
  1         3  
  1         74  
5 1     1   1609 use ExtUtils::Manifest;
  1         26431  
  1         77  
6 1     1   16 use File::Find;
  1         2  
  1         235  
7 1     1   8 use File::Spec;
  1         3  
  1         21  
8 1     1   6 use File::Basename;
  1         3  
  1         241  
9 1     1   8 use File::Copy;
  1         260  
  1         67  
10 1     1   2094 use Inline;
  1         34674  
  1         9  
11              
12             my %stubs = (
13             'Build.PL' => 1,
14             'Changes' => 1,
15             'MANIFEST.SKIP' => 1,
16             'README' => 1,
17             );
18              
19             BEGIN {
20 1     1   121 Bigtop::Parser->add_valid_keywords(
21             Bigtop::Keywords->get_docs_for(
22             'app',
23             qw(
24             authors
25             email
26             contact_us
27             copyright_holder
28             license_text
29             ),
30             )
31             );
32             }
33              
34             sub what_do_you_make {
35             return [
36 0     0     [ 'Build.PL' => 'Module::Build script' ],
37             [ 'Changes' => 'Almost empty Changes file' ],
38             [ 'README' => 'Boilerplate README' ],
39             [ 'lib/' => 'lib dir used by Control and Model backends' ],
40             [ 't/' => 'testing dir used by Control backend' ],
41             [ 'docs/name.bigtop' => 'Copy of your bigtop file [create mode only]'],
42             ];
43             }
44              
45             sub backend_block_keywords {
46 0     0     my @trailer = ( 'backward_boolean', '', '', 'no_gen' );
47             return [
48 0           { keyword => 'no_gen',
49             label => 'No Gen',
50             descr => 'Skip MANIFEST generation',
51             type => 'boolean' },
52              
53             { keyword => 'template',
54             label => 'Alternate Template',
55             descr => 'A custom TT template.',
56             type => 'text' },
57             ];
58             }
59              
60             sub validate_build_dir {
61 0     0     my $class = shift;
62 0           my $build_dir = shift;
63 0           my $tree = shift;
64 0           my $create = shift;
65              
66 0           my $warning_signs = 0;
67 0 0         if ( -d $build_dir ) {
68 0 0         unless ( $create ) {
69             # see if there are familiar surroundings in the build_dir
70 0           my $buildpl = File::Spec->catfile( $build_dir, 'Build.PL' );
71 0           my $changes = File::Spec->catfile( $build_dir, 'Changes' );
72 0           my $t = File::Spec->catdir( $build_dir, 't' );
73 0           my $lib = File::Spec->catdir( $build_dir, 'lib' );
74              
75 0 0         $warning_signs++ unless ( -f $buildpl );
76 0 0         $warning_signs++ unless ( -f $changes );
77 0 0         $warning_signs++ unless ( -d $t );
78 0 0         $warning_signs++ unless ( -d $lib );
79              
80             # dig deep for the main module
81 0           my $app_name = $tree->get_appname();
82 0           my @mod_pieces = split /::/, $app_name;
83 0           my $main_mod = pop @mod_pieces;
84 0           $main_mod .= '.pm';
85              
86 0           my $saw_base = 0;
87             my $wanted = sub {
88 0 0   0     $saw_base++ if ( $_ eq $main_mod );
89 0           };
90              
91 0           find( $wanted, $build_dir );
92              
93 0 0         $warning_signs++ unless ( $saw_base );
94             }
95             }
96             else {
97 0           die "$build_dir does not exist, and I couldn't make it.\n";
98             }
99              
100 0 0         if ( $warning_signs > 2 ) {
101 0   0       my $base_dir = $tree->{configuration}{base_dir} || '.';
102 0           my $config_build_dir = $base_dir;
103 0 0         if ( $tree->{configuration}{app_dir} ) {
104 0           $config_build_dir = File::Spec->catdir(
105             $base_dir, $tree->{configuration}{app_dir}
106             );
107             }
108 0           die "$build_dir doesn't look like a build dir (level=$warning_signs),\n"
109             . " use --create to force a build in or under $config_build_dir\n";
110             }
111             }
112              
113             our $template_is_setup = 0;
114             our $default_template_text = <<'EO_Template';
115             [% BLOCK Changes %]
116             Revision history for Perl web application [% app_name %]
117              
118             0.01 [% time_stamp %]
119             - original version created with bigtop version [% bigtop_version %][% IF flags %] using:
120             [% flags %]
121             [% END %]
122             [% END %]
123              
124             [% BLOCK README %]
125             [% app_name %] version 0.01
126             ===========================
127              
128             Place description here.
129              
130             INSTALLATION
131              
132             To install this module type:
133              
134             perl Build.PL
135             ./Build
136             ./Build test
137             ./Build install
138              
139             DEPENDENCIES
140              
141             This module requires these other modules and libraries:
142              
143             [% control_backend %]
144              
145             COPYRIGHT AND LICENCE
146              
147             Put the correct copyright and license info here.
148              
149             Copyright (c) [% year %] by [% copyright_holder %]
150              
151             [% IF license_text %]
152             [% license_text %]
153              
154             [% ELSE %]
155             This library is free software; you can redistribute it and/or modify
156             it under the same terms as Perl itself, either Perl version 5.8.6 or,
157             at your option, any later version of Perl 5 you may have available.
158             [% END %]
159             [% END %]
160              
161             [% BLOCK MANIFEST_SKIP %]
162             # Avoid version control files.
163             \bRCS\b
164             \bCVS\b
165             ,v$
166             \B\.svn\b
167              
168             # Avoid Makemaker generated and utility files.
169             \bMakefile$
170             \bblib
171             \bMakeMaker-\d
172             \bpm_to_blib$
173             \bblibdirs$
174             # ^MANIFEST\.SKIP$
175              
176             # Avoid Module::Build generated and utility files.
177             \bBuild$
178             \b_build
179              
180             # Avoid temp and backup files.
181             ~$
182             \.tmp$
183             \.old$
184             \.bak$
185             \#$
186             \b\.#
187             \.swp$
188              
189             # Avoid inline's dropings
190             _Inline
191              
192             [% END %]
193              
194             [% BLOCK Build_PL %]
195             [%# app_name %]
196             use strict;
197             use Gantry::Build;
198              
199             my $build = Gantry::Build->new(
200             build_web_directory => 'html',
201             install_web_directories => {
202             # XXX unix specific paths
203             'dev' => '/home/httpd/html/[% app_dash_name %]',
204             'qual' => '/home/httpd/html/[% app_dash_name %]',
205             'prod' => '/home/httpd/html/[% app_dash_name %]',
206             },
207             create_makefile_pl => 'passthrough',
208             license => 'perl',
209             module_name => '[% app_name %]',
210             requires => {
211             'perl' => '5',
212             'Gantry' => '3.0',
213             'HTML::Prototype' => '0',
214             },
215             create_makefile_pl => 'passthrough',
216              
217             # XXX unix specific paths
218             script_files => [ glob('bin/*') ],
219             'recursive_test_files' => 1,
220              
221             # XXX unix specific paths
222             install_path => { script => '/usr/local/bin' },
223             );
224              
225             $build->create_build_script;
226             [% END %]
227             EO_Template
228              
229             sub setup_template {
230 0     0     my $class = shift;
231 0   0       my $template_text = shift || $default_template_text;
232              
233 0 0         return if ( $template_is_setup );
234              
235 0           Inline->bind(
236             TT => $template_text,
237             PRE_CHOMP => 0,
238             POST_CHOMP => 0,
239             TRIM_LEADING_SPACE => 1,
240             TRIM_TRAILING_SPACE => 0,
241             );
242              
243 0           $template_is_setup = 1;
244             }
245              
246             sub gen_Init {
247             my $class = shift;
248             my $build_dir = shift;
249             my $tree = shift;
250             my $bigtop_file = shift;
251             my $flags = shift;
252              
253             # build dirs: lib, t
254             my $test_dir = File::Spec->catdir( $build_dir, 't' );
255             my $lib_dir = File::Spec->catdir( $build_dir, 'lib' );
256             mkdir $test_dir;
257             mkdir $lib_dir;
258              
259             # build flat files
260             foreach my $simple_file
261             qw(
262             Changes
263             MANIFEST_SKIP
264             README
265             Build_PL
266             )
267             {
268             next if ( defined $tree->{configuration}{Init}{$simple_file}
269             and
270             $tree->{configuration}{Init}{$simple_file} eq 'no_gen'
271             );
272             ( my $actual_file = $simple_file ) =~ s/_/./;
273             $class->init_simple_file( $build_dir, $tree, $actual_file, $flags );
274             }
275              
276             # copy the bigtop file to its new home
277             if ( defined $bigtop_file ) {
278             my $docs_dir = File::Spec->catdir( $build_dir, 'docs' );
279             mkdir $docs_dir;
280              
281             my $bigtop_basename = File::Basename::basename( $bigtop_file );
282             my $bigtop_copy
283             = File::Spec->catfile( $docs_dir, $bigtop_basename );
284             File::Copy::copy( $bigtop_file, $bigtop_copy )
285             unless $bigtop_copy eq $bigtop_file;
286             }
287              
288             # build the MANIFEST
289             unless ( defined $tree->{configuration}{Init}{MANIFEST}
290             and
291             $tree->{configuration}{Init}{MANIFEST} eq 'no_gen' )
292             {
293             my $original_dir = getcwd();
294             chdir $build_dir;
295              
296             $ExtUtils::Manifest::Verbose = 0;
297             ExtUtils::Manifest::mkmanifest();
298              
299             chdir $original_dir;
300             }
301             }
302              
303             sub init_simple_file {
304             my $class = shift;
305             my $build_dir = shift;
306             my $tree = shift;
307             my $file_base = shift;
308             my $flags = shift;
309              
310             # where does this belong?
311             my $file_name = File::Spec->catfile( $build_dir, $file_base );
312             my $app_name = $tree->get_appname();
313             my $app_dash_name= $app_name;
314             $app_dash_name =~ s/::/-/g;
315              
316             # should we really build this file?
317             return if ( $stubs{ $file_base } and -f $file_name );
318              
319             # get the time
320             my $right_now = scalar localtime;
321             my $year = ( localtime )[5];
322             $year += 1900;
323              
324             # who owns this?
325             my $statements = $tree->{application}{lookup}{app_statements};
326             my $copyright_holder = $tree->get_copyright_holder();
327             my $license_text;
328              
329             # what framework?
330              
331             my $control_backend;
332             my $config = $tree->get_config;
333             if ( defined $config->{__BACKENDS__}{ Control } ) {
334             $control_backend =
335             $tree->get_config->{__BACKENDS__}{ Control }[0]{ __NAME__ };
336             }
337              
338             if ( defined $statements->{license_text} ) {
339             $license_text = $statements->{license_text}[0];
340             }
341              
342             # what Inline::TT sub are we calling?
343             my $block_sub = "$class\::$file_base";
344             $block_sub =~ s/\./_/g;
345              
346             # open wide
347             my $SIMPLE_FILE;
348             unless ( open $SIMPLE_FILE, '>', $file_name ) {
349             warn "Couldn't write $file_name: $!\n";
350             return;
351             }
352              
353             # make and print file
354             {
355             no strict 'refs';
356             print $SIMPLE_FILE $block_sub->( {
357             time_stamp => $right_now,
358             app_name => $app_name,
359             app_dash_name => $app_dash_name,
360             copyright_holder => $copyright_holder,
361             year => $year,
362             license_text => $license_text,
363             flags => $flags,
364             control_backend => $control_backend,
365             bigtop_version => $Bigtop::VERSION,
366             } );
367             }
368              
369             # all done
370             close $SIMPLE_FILE or warn "Problem closing $file_name: $!\n";
371             }
372              
373             1;
374              
375             __END__