GX/Script/Build/Application.pm

filter: Statementstmt 9.3% 9 / 96 Branchbran 0.0% 0 / 16 Conditioncond 0.0% 0 / 5 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 13.3% 2 / 15 Podpod 0.0% 0 / 11 totaltotal 7.5% 11 / 146 CC 13 SCAR 26.0
CC
13
Cov
8%
_process_argv
42.0
build_default_template_view
12.0
build_application_module
6.0
CRAP 13.4
« GX/Database/SQLite.pm ↑ Summary GX/Cache/Memcached.pm »
1 # ----------------------------------------------------------------------------------------------------------------------
2 # GX Framework (c) 2009-2011 Jörg A. Uzarek <uzarek@runlevelnull.de>
3 # File: GX/Script/Build/Application.pm
4 # ----------------------------------------------------------------------------------------------------------------------
5  
6 package GX::Script::Build::Application;
7  
8 1 ▶use GX::Meta::Constants qw( REGEX_CLASS_NAME );
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10  
11 # ----------------------------------------------------------------------------------------------------------------------
12 # Class setup
13 # ----------------------------------------------------------------------------------------------------------------------
14  
15 1 ▶use GX::Class;
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 1 extends 'GX::Script::Build';
18  
19 1 build;
20  
21  
22 # ----------------------------------------------------------------------------------------------------------------------
23 # Public methods
24 # ----------------------------------------------------------------------------------------------------------------------
25  
26 0 ▶sub build_application_module {
Subroutine build_application_module: not called CC=2 SCAR=17.9
Pod undocumented
27  
28 0 my $self = shift;
29  
30 0 my $file = $self->construct_path( 'lib', split( /::/, $self->application_class ) ) . '.pm';
31  
32 $self->render_template(
33 'application',
34 {
35 0 ▶ 'engine' => $self->options->{'engine'} || 'FCGI'
Condition0%0/2
$self->options->{'engine'} || 'FCGI'
l!l
00
MC/DC0%0/1
$self->options->{'engine'} || 'FCGI'
$self->options->{'engine'}
Truth table0%0/2
A
A= $self->options->{'engine'}
Aresult
11
00
36 },
37 $file
38 );
39  
40 0 return;
41  
42 }
43  
44 0 ▶sub build_default_controller {
Subroutine build_default_controller: not called CC=1 SCAR=6.9
Pod undocumented
45  
46 0 my $self = shift;
47  
48 0 my $file = $self->construct_path(
49 'lib',
50 split( /::/, $self->application_class ),
51 'Controller',
52 'Root.pm'
53 );
54  
55 0 $self->render_template( 'default_controller', undef, $file );
56  
57 0 return;
58  
59 }
60  
61 0 ▶sub build_default_error_view {
Subroutine build_default_error_view: not called CC=1 SCAR=6.9
Pod undocumented
62  
63 0 my $self = shift;
64  
65 0 my $file = $self->construct_path(
66 'lib',
67 split( /::/, $self->application_class ),
68 'View',
69 'Error.pm'
70 );
71  
72 0 $self->render_template( 'default_error_view', undef, $file );
73  
74 0 return;
75  
76 }
77  
78 0 ▶sub build_default_logger {
Subroutine build_default_logger: not called CC=1 SCAR=6.9
Pod undocumented
79  
80 0 my $self = shift;
81  
82 0 my $file = $self->construct_path(
83 'lib',
84 split( /::/, $self->application_class ),
85 'Logger',
86 'Default.pm'
87 );
88  
89 0 $self->render_template( 'default_logger', undef, $file );
90  
91 0 return;
92  
93 }
94  
95 0 ▶sub build_default_template_view {
Subroutine build_default_template_view: not called CC=3 SCAR=24.8
Pod undocumented
96  
97 0 my $self = shift;
98  
99 0 for my $subclass ( qw( TT HTC ) ) {
100  
101 0 my $base_class = "GX::View::Template::$subclass";
102  
103 0 local $@;
104  
105 0 ▶ if ( eval "require $base_class" ) {
Branch: 1 branch
BranchTrueFalseTotal
if (eval "require $base_class") 0 0 0
106  
107 0 my $application_class = $self->application_class;
108  
109 0 my $file = $self->construct_path(
110 'lib',
111 split( /::/, $application_class ),
112 'View',
113 $subclass . '.pm'
114 );
115  
116 0 $self->render_template(
117 'default_template_view',
118 {
119 'class' => "${application_class}::View::${subclass}",
120 'base_class' => $base_class
121 },
122 $file
123 );
124  
125 0 last;
126  
127 }
128  
129 }
130  
131 0 return;
132  
133 }
134  
135 0 ▶sub build_directory_structure {
Subroutine build_directory_structure: not called CC=2 SCAR=17.9
Pod undocumented
136  
137 0 my $self = shift;
138  
139 0 my @directories;
140  
141 0 push @directories, $self->application_path;
142  
143 push @directories, map {
144 0 $self->construct_path( $_ )
145 } qw( cache lib log public script t templates tmp );
146  
147 0 push @directories, $self->construct_path( 'public', 'static' );
148  
149 0 my @lib_dir = ( 'lib', split( /::/, $self->application_class ) );
150  
151 push @directories, map {
152 0 $self->construct_path( @lib_dir, $_ )
153 } qw( Cache Controller Database Logger Model Session View );
154  
155 0 for ( sort @directories ) {
156 0 $self->create_directory( $_ );
157 }
158  
159 0 return;
160  
161 }
162  
163 0 ▶sub build_fcgi_script {
Subroutine build_fcgi_script: not called CC=2 SCAR=17.9
Pod undocumented
164  
165 0 my $self = shift;
166  
167 0 my $file = $self->construct_path( 'script', 'server', 'fcgi.pl' );
168  
169 0 ▶ $self->render_template( 'fcgi_script', undef, $file ) or return;
Branch: 1 branch
BranchTrueFalseTotal
$self->render_template("fcgi_script", undef, $file) or return 0 0 0
170  
171 0 $self->chmod_file( $file, 0755 );
172  
173 0 return;
174  
175 }
176  
177 0 ▶sub build_test_script {
Subroutine build_test_script: not called CC=2 SCAR=17.9
Pod undocumented
178  
179 0 my $self = shift;
180  
181 0 my $file = $self->construct_path( 't', '01_load.t' );
182  
183 0 ▶ $self->render_template( 'test_script', undef, $file ) or return;
Branch: 1 branch
BranchTrueFalseTotal
$self->render_template("test_script", undef, $file) or return 0 0 0
184  
185 0 $self->chmod_file( $file, 0755 );
186  
187 0 return;
188  
189 }
190  
191 0 ▶sub build_welcome_html_file {
Subroutine build_welcome_html_file: not called CC=1 SCAR=6.9
Pod undocumented
192  
193 0 my ( $self ) = @_;
194  
195 0 my $file = $self->construct_path( 'public', 'welcome.html' );
196  
197 0 $self->render_template( 'welcome_html_file', undef, $file );
198  
199 0 return;
200  
201 }
202  
203 0 ▶sub run {
Subroutine run: not called CC=2 SCAR=17.9
Pod undocumented
204  
205 0 ▶ my $self = ref $_[0] ? shift : shift->new;
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] ? : 0 0 0
206  
207 0 $self->_process_argv;
208  
209 0 $self->print_message(
210 sprintf(
211 "Creating '%s' in %s ...",
212 $self->application_class,
213 $self->application_path
214 )
215 );
216  
217 0 $self->build_directory_structure;
218 0 $self->build_application_module;
219 0 $self->build_default_controller;
220 0 $self->build_default_logger;
221 0 $self->build_default_error_view;
222 0 $self->build_default_template_view;
223 0 $self->build_fcgi_script;
224 0 $self->build_test_script;
225 0 $self->build_welcome_html_file;
226  
227 0 $self->print_message( "Done." );
228  
229 0 return;
230  
231 }
232  
233 0 ▶sub show_help {
Subroutine show_help: not called CC=1 SCAR=6.9
Pod undocumented
234  
235 0 my $self = shift;
236  
237 0 my $script_name = $self->script_name;
238  
239 0 $self->print_message( <<EOT );
240 NAME
241  
242 $script_name - Bootstrap a GX Application
243  
244 USAGE
245  
246 $script_name <application> [OPTIONS]
247  
248 OPTIONS
249  
250 <application>
251 The class name of the application.
252  
253 -e <engine>, --engine <engine>
254 The engine base class, e.g. "Apache2" or "FCGI". Defaults to "FCGI".
255  
256 MORE OPTIONS
257  
258 -h, --help
259 Print this help and exit.
260  
261 -v, --version
262 Print the version information for this script and exit.
263  
264 --copyright
265 Print the copyright notice for this script and exit.
266  
267 EXAMPLE
268  
269 $script_name MyApp --engine FCGI
270 EOT
271  
272 0 return;
273  
274 }
275  
276  
277 # ----------------------------------------------------------------------------------------------------------------------
278 # Private methods
279 # ----------------------------------------------------------------------------------------------------------------------
280  
281 0 ▶sub _argv_options {
Subroutine _argv_options: not called CC=1 SCAR=6.9
282  
283 0 my $self = shift;
284  
285 return (
286 0 $self->SUPER::_argv_options,
287 'engine=s'
288 );
289  
290 }
291  
292 0 ▶sub _process_argv {
Subroutine _process_argv: not called CC=6 SCAR=37.4
293  
294 0 my $self = shift;
295  
296 0 my @argv = $self->SUPER::_process_argv( @_ );
297  
298 0 my $application_class = shift @argv;
299  
300 0 ▶ if ( ! defined $application_class || @argv ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $application_class or @argv) 0 0 0
Condition0%0/3
not defined $application_class or @argv
l!l&&r!l&&!r
000
MC/DC0%0/2
not defined $application_class or @argv
not defined $application_class @argv
Truth table0%0/3
not(A) or B
A= not defined $application_classB= @argv
ABresult
1X1
011
000
301 0 $self->show_help;
302 0 $self->exit( 1 );
303 }
304  
305 0 ▶ if ( $application_class !~ REGEX_CLASS_NAME ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($application_class =~ /^[a-zA-Z_]\w*(?:::[a-zA-Z_]\w*)*$/) 0 0 0
306 0 die "Invalid application class name. Aborting.\n";
307 }
308  
309 0 $self->application_class( $application_class );
310  
311 0 my $application_path = File::Spec->rel2abs(
312 join( '-', split( /::/, $application_class ) ),
313 $self->cwd
314 );
315  
316 0 $self->application_path( $application_path );
317  
318 0 ▶ if ( defined $self->options->{'engine'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->options->{"engine"}) 0 0 0
319  
320 0 ▶ if ( $self->options->{'engine'} !~ REGEX_CLASS_NAME ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->options->{"engine"} =~ /^[a-zA-Z_]\w*(?:::[a-zA-Z_]\w*)*$/) 0 0 0
321 0 die "Invalid engine class name. Aborting.\n";
322 }
323  
324 }
325  
326 0 return;
327  
328 }
329  
330  
331 1 1;
332  
333 =head1 NAME
334  
335 GX::Script::Build::Application - Script class
336  
337 =head1 SYNOPSIS
338  
339 None.
340  
341 =head1 DESCRIPTION
342  
343 This module provides the L<GX::Script::Build::Application> class which extends
344 the L<GX::Script::Build> class.
345  
346 =head1 AUTHOR
347  
348 JE<ouml>rg A. Uzarek E<lt>uzarek@runlevelnull.deE<gt>
349  
350 =head1 COPYRIGHT AND LICENSE
351  
352 Copyright (c) 2009-2011 JE<ouml>rg A. Uzarek.
353  
354 This module is free software: you can redistribute it and/or modify it under
355 the terms of the GNU General Public License Version 3 as published by the
356 Free Software Foundation.
357  
358 =cut
359  
360 __DATA__
« GX/Database/SQLite.pm ↑ Summary GX/Cache/Memcached.pm »