ForExample.pm

filter: Statementstmt 89.7% 158 / 176 Branchbran 71.2% 57 / 80 Conditioncond 71.6% 43 / 60 MC/DCmcdc 12.5% 3 / 24 Subroutinesub 89.4% 17 / 19 Podpod 0.0% 0 / 5 totaltotal 76.3% 278 / 364 CC 66 SCAR 29.9
CC
66
Cov
82%
__ANON__
38.2
parse_catalyst
15.5
output
12.3
CRAP 19.8
« ForExample/ModuleEmbedCatalog.pm ↑ Summary ForExample/Catalog.pm »
1 package App::ForExample;
2  
3 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 =head1 NAME
7  
8 App::ForExample - A guide through Catalyst, Apache, lighttpd, nginx, monit, ..., configuration hell
9  
10 =head1 VERSION
11  
12 Version 0.024
13  
14 =cut
15  
16 4 our $VERSION = '0.024';
17  
18 =head1 SYNOPSIS
19  
20 # To output a FastCGI (ExternalServer)/Apache configuration (with monit stub and start-stop script), run:
21 for-example catalyst/fastcgi apache2 standalone --class My::App --hostname example.com --output my-app
22  
23 # The above command would have created the following:
24  
25 my-app.apache2 The Apache2 virtual host configuration (hosted at (www.)example.com)
26 my-app.start-stop The start/stop script to launch the FastCGI process
27 my-app.monit A monit stub used for monitoring the FastCGI process
28  
29 # This will generate a basic, stripped-down monit configuration (monitrc) suitable for a non-root user:
30 for-example monit --home $HOME/monit --output $HOME/monit/monitrc
31  
32 # A mod_perl configuration for Catalyst:
33 for-example catalyst/mod_perl --class Project::Xyzzy --hostname xyzzy.com --home Project-Xyzzy
34  
35 =head1 DESCRIPTION
36  
37 App::ForExample is a command-line tool for generating sample configurations. It is not designed to do configuration
38 management, but rather as a guide to get you 80% of the way there
39  
40 Besides the usual Apache, lighttpd, nginx, and FastCGI configurations, App::ForExample can create a FastCGI start-stop script and a
41 monit configuration for monitoring those processes
42  
43 =head1 USAGE
44  
45 Usage: for-example ACTION
46  
47 Where ACTION can be
48  
49 (Note: Every option below is, well, optional. If not specified, a fun default will be chosen/guessed for you)
50  
51 catalyst/fastcgi ...
52  
53 Generate a Catalyst FastCGI configuration (for monit, start-stop, or the specified http daemon and fastcgi method)
54  
55 --class The Catalyst class for your application (e.g. Project::Xyzzy or My::App)
56 --home The path to your Catalyst home directory, default: . (The current directory)
57 --log-home The directory to log into, default: <home>/log (Below the directory given by --home)
58 --base The base for your application, default: / (At the root)
59 --hostname The hostname from which your application is served (e.g. example.com)
60  
61 --bare Do not output anything BUT the configuration (no monit, no start-stop)
62 --output - Print output to stdout
63 --output <path> Write output to <path> (which can be either a directory or file)
64 This will split output appropiately (e.g. <file>.apache2, <file>.start-stop, <file>.monit)
65  
66 --fastcgi-script The <path> to the Catalyst fastcgi script (e.g. script/xyzzy_fastcgi.pl)
67 --fastcgi-socket <path> Have fastcgi use <path> for the file socket
68 --fastcgi-socket <host:port> Have fastcgi use <host:port> for the socket
69 --fastcgi-pid-file <path> Store the pid for the process in <path>
70  
71 apache2 standalone Apache2 with standalone FastCGI (mod_fastcgi)
72 apache2 static Apache2 with static FastCGI (mod_fastcgi)
73 apache2 dynamic Apache2 with dynamic FastCGI (mod_fastcgi)
74  
75 lighttpd standalone lighttpd with dynamic FastCGI
76 lighttpd static lighttpd with static FastCGI
77  
78 nginx nginx with standalone FastCGI (the only kind supported)
79  
80 monit A monit configuration for a standalone FastCGI setup
81 start-stop A start-stop script for a standalone FastCGI setup
82
83 catalyst/mod_perl
84  
85 Generate a mod_perl2 (for Apache2) Catalyst configuration
86  
87 --class The Catalyst class for your application (e.g. Project::Xyzzy or My::App)
88 --home The path to your Catalyst home directory, default: . (The current directory)
89 --log-home The directory to log into, default: <home>/log (Below the directory given by --home)
90 --base The base for your application, default: / (At the root)
91 --hostname The hostname from which your application is served (e.g. example.com)
92  
93 monit
94  
95 Generate a basic, stripped-down monit configuration suitable for a non-root user
96  
97 --home The directory designated monit home (containing the pid file, log, rc, ...)
98  
99 =head1 TUTORIAL
100  
101 =head2 Apache2 with FastCGI on Ubuntu
102  
103 Install apache2, mod_fastcgi, and L<FCGI>
104  
105 sudo apt-get install apache2 libapache2-mod-fastcgi
106  
107 cpan -i FCGI
108  
109 Create the Catalyst application C<My::App>
110  
111 catalyst.pl My::App
112  
113 Use L<App::ForExample> to generate the configuration
114  
115 cd My-App
116 for-example catalyst/fastcgi apache2 standalone --class My::App --hostname my-app.localhost --output my-app
117  
118 Make the log directory
119  
120 mkdir log
121  
122 Install the apache2 configuration
123  
124 sudo cp my-app.apache2 /etc/apache2/sites-enabled
125  
126 Enable the fastcgi start-stop script (with execute permissions)
127  
128 chmod +x my-app.start-stop
129  
130 Add a C<my-app.localhost> entry to C</etc/hosts>
131  
132 127.0.0.1 my-app.localhost
133
134 Start your application
135  
136 ./my-app.start-stop start
137 sudo /etc/init.d/apache restart
138  
139 Visit your application at L<http://my-app.localhost>
140  
141 =head1 INSTALL
142  
143 You can install L<App::ForExample> by using L<CPAN>:
144  
145 cpan -i App::ForExample
146  
147 If that doesn't work properly, you can find help at:
148  
149 http://sial.org/howto/perl/life-with-cpan/
150 http://sial.org/howto/perl/life-with-cpan/macosx/ # Help on Mac OS X
151 http://sial.org/howto/perl/life-with-cpan/non-root/ # Help with a non-root account
152  
153 =head1 CONTRIBUTE
154  
155 You can contribute or fork this project via GitHub:
156  
157 L<http://github.com/robertkrimen/App-ForExample/tree/master>
158  
159 git clone git://github.com/robertkrimen/App-ForExample.git
160  
161 =cut
162  
163 4 ▶use App::ForExample::Catalog;
Subroutine BEGIN: called CC=1 SCAR=0.0
164  
165 4 ▶use Template;
Subroutine BEGIN: called CC=1 SCAR=0.0
166 4 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
167 4 ▶use Path::Class;
Subroutine BEGIN: called CC=1 SCAR=0.0
168  
169 4 my $catalog = App::ForExample::Catalog->catalog;
170 4 my $tt = Template->new({ BLOCKS => $catalog->{common} });
171  
172 22 ▶sub process ($@) {
Subroutine process: called CC=4 SCAR=14.8
Pod undocumented
173 22 my $given = shift;
174  
175 22 my ($template);
176 22 ▶ if ( ref $given eq 'SCALAR' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $given eq 'SCALAR') { } 0 22 22
177 0 $template = $given;
178 }
179 else {
180 22 ▶ $template = $catalog->{$given} or croak "Template \"$given\" does not exist in the catalog";
Branch: 1 branch
BranchTrueFalseTotal
$template = $catalog->{$given} or croak(qq[Template "$given" does not exist in the catalog]) 22 0 22
181 }
182  
183 22 my $output;
184 22 ▶ $tt->process( $template => { @_ }, \$output ) or croak "Error processing template \"$given\": ", $tt->error;
Branch: 1 branch
BranchTrueFalseTotal
$tt->process($template, {@_}, \$output) or croak(qq[Error processing template "$given": ], $tt->error) 22 0 22
185 22 return $output;
186 }
187  
188 18 ▶sub output ($@) {
Subroutine output: called CC=12 SCAR=25.1
Pod undocumented
189 18 my $ctx = shift;
190  
191 18 my $to = $ctx->option( 'output' );
192 18 ▶ $to = '-' unless defined $to && length $to;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $to and length $to 15 3 18
Condition66%2/3
defined $to and length $to
!ll&&!rl&&r
1503
MC/DC50%1/2
defined $to and length $to
defined $to length $to
Truth table66%2/3
A and B
A= defined $toB= length $to
ABresult
0X0
100
111
193  
194 18 ▶ if ( $to eq '-' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($to eq '-') { } 15 3 18
195 15 my $ii = 0;
196 15 ▶ while ( @_ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 15 15 30
197 15 shift;
198 15 ▶ print "---\n" if $ii++ > 0;
Branch: 1 branch
BranchTrueFalseTotal
if $ii++ > 0 0 15 15
199 15 print shift;
200 }
201 }
202 else {
203 3 my $name_hint = shift;
204  
205 3 ▶ if ( $name_hint =~ m/^(.*)\.(.*)$/ ) { # E.g. catalyst-fastcgi.apache or .lighttpd
Branch: 1 branch
BranchTrueFalseTotal
if ($name_hint =~ /^(.*)\.(.*)$/) 3 0 3
206 3 $name_hint = $1;
207 3 unshift @_, $2;
208 }
209  
210 3 ▶ if ( ! -f $to && ( $to =~ m/\/$/ || -d _ ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not -f $to and $to =~ m[/$] || -d _) { } 2 1 3
Condition66%4/6
not -f $to and $to =~ m[/$] || -d _
!ll&&!rl&&r
012
$to =~ m[/$] or -d _
l!l&&r!l&&!r
021
MC/DC33%1/3
not -f $to and $to =~ m[/$] || -d _
not -f $to $to =~ m[/$] -d _
Truth table50%2/4
not(A) and B or C
A= not -f $toB= $to =~ m[/$]C= -d _
ABCresult
0XX0
1000
11X1
1011
211 2 $to = file( $to, $name_hint );
212 }
213 else {
214 1 $to = file $to;
215 }
216  
217 3 my $parent = $to->parent;
218 3 ▶ $parent->mkpath unless -d $parent;
Branch: 1 branch
BranchTrueFalseTotal
unless -d $parent 0 3 3
219  
220 3 ▶ while ( @_ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 7 3 10
221 7 my $name = shift;
222 7 my $content = shift;
223  
224 7 my $file = file( join '.', $to, $name );
225 7 $file->openw->print( $content );
226 7 print "Made $file\n";
227 }
228 }
229 }
230  
231 4 ▶use Getopt::Chain::Declare;
Subroutine BEGIN: called CC=1 SCAR=0.0
232  
233 17 ▶sub package2name ($) {
Subroutine package2name: called CC=1 SCAR=0.0
Pod undocumented
234 17 my $package = shift;
235 17 my $name = $package;
236 17 $name =~ s/::/-/g;
237 17 $name = lc $name;
238 17 my $name_underscore = $name;
239 17 $name_underscore =~ s/-/_/g;
240 17 return ( $name, $name_underscore );
241 }
242  
243 4 my @parse_catalyst = qw/ package|class=s name=s home=s log-home=s base=s hostname=s fastcgi-script=s fastcgi-socket=s fastcgi-socket-path=s fastcgi-pid-file=s/;
244 17 ▶sub parse_catalyst ($) {
Subroutine parse_catalyst: called CC=14 SCAR=27.4
Pod undocumented
245 17 my $ctx = shift;
246  
247 # Catalyst package
248 17 ▶ my $package = $ctx->option( 'package' ) || 'Project::Xyzzy';
Condition50%1/2
$ctx->option('package') || 'Project::Xyzzy'
l!l
170
MC/DC0%0/1
$ctx->option('package') || 'Project::Xyzzy'
$ctx->option('package')
Truth table50%1/2
A
A= $ctx->option('package')
Aresult
11
00
249 17 my ($package_name, $name_underscore) = package2name $package;
250  
251 # Catalyst name
252 17 my $name = $ctx->option( 'name' );
253 17 ▶ $name = $package_name unless defined $name;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $name 17 0 17
254  
255 # Catalyst home
256 17 ▶ my $home = $ctx->option( 'home' ) || "./";
Condition50%1/2
$ctx->option('home') || './'
l!l
170
MC/DC0%0/1
$ctx->option('home') || './'
$ctx->option('home')
Truth table50%1/2
A
A= $ctx->option('home')
Aresult
11
00
257 17 $home = dir( $home )->absolute;
258  
259 17 ▶ my $log_home = $ctx->option( 'log_home' ) || $home->subdir( 'log' );
Condition33%1/3
$ctx->option('log_home') || $home->subdir('log')
l!l&&r!l&&!r
0170
MC/DC0%0/2
$ctx->option('log_home') || $home->subdir('log')
$ctx->option('log_home') $home->subdir('log')
Truth table33%1/3
A || B
A= $ctx->option('log_home')B= $home->subdir('log')
ABresult
1X1
011
000
260 17 $log_home = dir( $log_home )->absolute;
261  
262 # Catalyst application base
263 17 ▶ my $base = $ctx->option( 'base' ) || '/';
Condition50%1/2
$ctx->option('base') || '/'
l!l
017
MC/DC0%0/1
$ctx->option('base') || '/'
$ctx->option('base')
Truth table50%1/2
A
A= $ctx->option('base')
Aresult
11
00
264 17 $base =~ s/^\/+//;
265 17 ▶ my $alias_base = $base eq '' ? '/' : "/$base/";
Branch: 1 branch
BranchTrueFalseTotal
$base eq '' ? : 17 0 17
266  
267 # Hostname
268 17 ▶ my $hostname = $ctx->option( 'hostname' ) || "$name.example.com";
Condition50%1/2
$ctx->option('hostname') || "$name.example.com"
l!l
170
MC/DC0%0/1
$ctx->option('hostname') || "$name.example.com"
$ctx->option('hostname')
Truth table50%1/2
A
A= $ctx->option('hostname')
Aresult
11
00
269  
270 17 my $fastcgi_script = $ctx->option( 'fastcgi-script' );
271 17 ▶ $fastcgi_script = join '/', $home, 'script', "${name_underscore}_fastcgi.pl" unless defined $fastcgi_script;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $fastcgi_script 17 0 17
272 17 my $fastcgi_script_basename = file( $fastcgi_script )->basename;
273 17 my $fastcgi_socket = $ctx->option( 'fastcgi-socket' );
274 17 ▶ $fastcgi_socket = "/tmp/$name.socket" unless defined $fastcgi_socket;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $fastcgi_socket 12 5 17
275 17 my $fastcgi_host_port;
276 17 ▶ if ( $fastcgi_socket =~ m/^(.+):(\d+)$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($fastcgi_socket =~ /^(.+):(\d+)$/) 4 13 17
277 4 $fastcgi_host_port = [ $1, $2 ];
278 }
279 17 my $fastcgi_socket_path = $ctx->option( 'fastcgi-socket-path' );
280 17 ▶ $fastcgi_socket_path = "/tmp/$name.fcgi" unless defined $fastcgi_socket_path;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $fastcgi_socket_path 17 0 17
281 17 my $fastcgi_pid_file = $ctx->option( 'fastcgi-pid-file' );
282 17 ▶ $fastcgi_pid_file = "$name-fastcgi.pid" unless $fastcgi_pid_file;
Branch: 1 branch
BranchTrueFalseTotal
unless $fastcgi_pid_file 13 4 17
283 17 ▶ $fastcgi_pid_file = join '/', $home, $fastcgi_pid_file unless $fastcgi_pid_file =~ m/^\//;
Branch: 1 branch
BranchTrueFalseTotal
unless $fastcgi_pid_file =~ m[^/] 17 0 17
284  
285 17 my @data;
286 17 push @data, package => $package,
287 name => $name,
288 name_underscore => $name_underscore,
289 home => $home,
290 log_home => $log_home,
291 base => $base,
292 alias_base => $alias_base,
293 hostname => $hostname,
294 fastcgi_script => $fastcgi_script,
295 fastcgi_script_basename => $fastcgi_script_basename,
296 fastcgi_socket => $fastcgi_socket,
297 fastcgi_host_port => $fastcgi_host_port,
298 fastcgi_socket_path => $fastcgi_socket_path,
299 fastcgi_pid_file => $fastcgi_pid_file,
300 ;
301 17 return { @data };
302 }
303  
304 1 ▶sub do_help ($) {
Subroutine do_help: called CC=1 SCAR=0.0
Pod undocumented
305 1 my $ctx = shift;
306  
307 1 print <<_END_;
308 Usage: for-example ACTION
309  
310 Where ACTION can be
311  
312 (Note: Every option below is, well, optional. If not specified, a fun default will be chosen/guessed for you)
313  
314 catalyst/fastcgi ...
315  
316 Generate a Catalyst FastCGI configuration (for monit, start-stop, or the specified http daemon and fastcgi method)
317  
318 --class The Catalyst class for your application (e.g. Project::Xyzzy or My::App)
319 --home The path to your Catalyst home directory, default: . (The current directory)
320 --log-home The directory to log into, default: <home>/log (Below the directory given by --home)
321 --base The base for your application, default: / (At the root)
322 --hostname The hostname from which your application is served (e.g. example.com)
323  
324 --bare Do not output anything BUT the configuration (no monit, no start-stop)
325 --output - Print output to stdout
326 --output <path> Write output to <path> (which can be either a directory or file)
327 This will split output appropiately (e.g. <file>.apache2, <file>.start-stop, <file>.monit)
328  
329 --fastcgi-script The <path> to the Catalyst fastcgi script (e.g. script/xyzzy_fastcgi.pl)
330 --fastcgi-socket <path> Have fastcgi use <path> for the file socket
331 --fastcgi-socket <host:port> Have fastcgi use <host:port> for the socket
332 --fastcgi-pid-file <path> Store the pid for the process in <path>
333  
334 apache2 standalone Apache2 with standalone FastCGI (mod_fastcgi)
335 apache2 static Apache2 with static FastCGI (mod_fastcgi)
336 apache2 dynamic Apache2 with dynamic FastCGI (mod_fastcgi)
337  
338 lighttpd standalone lighttpd with dynamic FastCGI
339 lighttpd static lighttpd with static FastCGI
340  
341 nginx nginx with standalone FastCGI (the only kind supported)
342  
343 monit A monit configuration for a standalone FastCGI setup
344 start-stop A start-stop script for a standalone FastCGI setup
345
346 catalyst/mod_perl
347  
348 Generate a mod_perl2 (for Apache2) Catalyst configuration
349  
350 --class The Catalyst class for your application (e.g. Project::Xyzzy or My::App)
351 --home The path to your Catalyst home directory, default: . (The current directory)
352 --log-home The directory to log into, default: <home>/log (Below the directory given by --home)
353 --base The base for your application, default: / (At the root)
354 --hostname The hostname from which your application is served (e.g. example.com)
355  
356 monit
357  
358 Generate a basic, stripped-down monit configuration suitable for a non-root user
359  
360 --home The directory designated monit home (containing the pid file, log, rc, ...)
361  
362 For example:
363  
364 for-example catalyst/fastcgi apache2 standalone --class My::App --hostname example.com
365 for-example monit --home \$HOME/my-monit
366 for-example catalyst/mod_perl --class Project::Xyzzy --hostname xyzzy.com --home Project-Xyzzy
367  
368 _END_
369 }
370  
371 19 ▶start [qw/ help|h|? /], sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
372 19 my $ctx = shift;
373  
374 19 ▶ if ( $ctx->option( 'help' ) || $ctx->last ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ctx->option("help") or $ctx->last) 1 18 19
Condition66%2/3
$ctx->option("help") or $ctx->last
l!l&&r!l&&!r
1018
MC/DC50%1/2
$ctx->option("help") or $ctx->last
$ctx->option("help") $ctx->last
Truth table66%2/3
A or B
A= $ctx->option("help")B= $ctx->last
ABresult
1X1
011
000
375 1 do_help $ctx;
376 1 exit 0;
377 }
378 4 };
379  
380 4 rewrite qr#catalyst/(?:mod_perl[12]|modperl[12]?)# => 'catalyst/mod_perl';
381  
382 on 'catalyst/mod_perl *' =>
383 1 ▶ [ qw/ output=s /, @parse_catalyst ] => sub {
Subroutine __ANON__: called CC=5 SCAR=19.7
384 1 my $ctx = shift;
385
386 1 my ($server);
387 1 for ( @_ ) {
388 0 ▶ m/(apache2?)/ and ($server) = ($1) or
Branch: 1 branch
BranchTrueFalseTotal
/(apache2?)/ and ($server) = $1 or croak("Don't understand argument $_ (@_)") 0 0 0
Condition0%0/3
/(apache2?)/ and ($server) = $1
!ll&&!rl&&r
000
MC/DC0%0/2
/(apache2?)/ and ($server) = $1
/(apache2?)/ ($server) = $1
Truth table0%0/3
A and B
A= /(apache2?)/B= ($server) = $1
ABresult
0X0
100
111
389  
390 croak "Don't understand argument $_ (@_)";
391 }
392 1 ($server) = qw/apache2/;
393  
394 1 my @data;
395 1 my $catalyst_data = parse_catalyst $ctx;
396 1 push @data, %$catalyst_data;
397  
398 1 ▶ if ( $server =~ m/^apache2?$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($server =~ /^apache2?$/) { } 1 0 1
399 1 output( $ctx, 'catalyst-mod_perl' => process 'catalyst/mod_perl/apache2' => @data );
400 }
401 else {
402 0 croak "Don't understand server \"$server\""
403 }
404  
405 4 };
406  
407 on 'catalyst/fastcgi *' =>
408 16 ▶ [ @parse_catalyst, qw/ bare output=s /] => sub {
Subroutine __ANON__: called CC=32 SCAR=36.4
409 16 my $ctx = shift;
410
411 16 my ($server, $server_module, $mode);
412 16 for ( @_ ) {
413 26 ▶ m/(apache2?)(?:=(?:mod_)?(fastcgi|fcgid))?/ and ($server, $server_module) = ($1, $2) or
Branch: 1 branch
BranchTrueFalseTotal
/(apache2?)(?:=(?:mod_)?(fastcgi|fcgid))?/ and () = ($1, $2) or /lighttpd/ and $server = "lighttpd" or /nginx/ and $server = "nginx" or /(monit|start-stop)/ and $server = $1 or /standalone/ and $mode = "standalone" or /static/ and $mode = "static" or /dynamic/ and $mode = "dynamic" or croak("Don't understand argument $_ (@_)") 26 0 26
Condition88%30/34
/(apache2?)(?:=(?:mod_)?(fastcgi|fcgid))?/ and () = ($1, $2) or /lighttpd/ and $server = "lighttpd" or /nginx/ and $server = "nginx" or /(monit|start-stop)/ and $server = $1 or /standalone/ and $mode = "standalone" or /static/ and $mode = "static" or /dynamic/ and $mode = "dynamic"
l!l&&r!l&&!r
2510
/(apache2?)(?:=(?:mod_)?(fastcgi|fcgid))?/ and () = ($1, $2) or /lighttpd/ and $server = "lighttpd" or /nginx/ and $server = "nginx" or /(monit|start-stop)/ and $server = $1 or /standalone/ and $mode = "standalone" or /static/ and $mode = "static"
l!l&&r!l&&!r
2321
/(apache2?)(?:=(?:mod_)?(fastcgi|fcgid))?/ and () = ($1, $2) or /lighttpd/ and $server = "lighttpd" or /nginx/ and $server = "nginx" or /(monit|start-stop)/ and $server = $1 or /standalone/ and $mode = "standalone"
l!l&&r!l&&!r
1673
/(apache2?)(?:=(?:mod_)?(fastcgi|fcgid))?/ and () = ($1, $2) or /lighttpd/ and $server = "lighttpd" or /nginx/ and $server = "nginx" or /(monit|start-stop)/ and $server = $1
l!l&&r!l&&!r
12410
/(apache2?)(?:=(?:mod_)?(fastcgi|fcgid))?/ and () = ($1, $2) or /lighttpd/ and $server = "lighttpd" or /nginx/ and $server = "nginx"
l!l&&r!l&&!r
10214
/(apache2?)(?:=(?:mod_)?(fastcgi|fcgid))?/ and () = ($1, $2) or /lighttpd/ and $server = "lighttpd"
l!l&&r!l&&!r
7316
/(apache2?)(?:=(?:mod_)?(fastcgi|fcgid))?/ and () = ($1, $2)
!ll&&!rl&&r
1907
/lighttpd/ and $server = "lighttpd"
!ll
163
/nginx/ and $server = "nginx"
!ll
142
/(monit|start-stop)/ and $server = $1
!ll&&!rl&&r
1004
/standalone/ and $mode = "standalone"
!ll
37
/static/ and $mode = "static"
!ll
12
/dynamic/ and $mode = "dynamic"
!ll
01
MC/DC0%0/9
/(apache2?)(?:=(?:mod_)?(fastcgi|fcgid))?/ and () = ($1, $2) or /lighttpd/ and $server = "lighttpd" or /nginx/ and $server = "nginx" or /(monit|start-stop)/ and $server = $1 or /standalone/ and $mode = "standalone" or /static/ and $mode = "static" or /dynamic/ and $mode = "dynamic"
/(apache2?)(?:=(?:mod_)?(fastcgi|fcgid))?/ () = ($1, $2) /lighttpd/ /nginx/ /(monit|start-stop)/ $server = $1 /standalone/ /static/ /dynamic/
Truth table30%7/23
A and B or C or D or E and F or G or H or I
A= /(apache2?)(?:=(?:mod_)?(fastcgi|fcgid))?/B= () = ($1, $2)C= /lighttpd/D= /nginx/E= /(monit|start-stop)/F= $server = $1G= /standalone/H= /static/I= /dynamic/
ABCDEFGHIresult
11XXXXXXX1
0X1XXXXXX1
101XXXXXX1
0X01XXXXX1
1001XXXXX1
0X0011XXX1
100011XXX1
0X000X1XX1
0X00101XX1
10000X1XX1
1000101XX1
0X000X01X1
0X001001X1
10000X01X1
10001001X1
0X000X0011
0X00100011
10000X0011
1000100011
0X000X0000
0X00100000
10000X0000
1000100000
414 m/lighttpd/ and $server = 'lighttpd' or
415 m/nginx/ and $server = 'nginx' or
416 m/(monit|start-stop)/ and $server = $1 or # Not really a server, but...
417  
418 m/standalone/ and $mode = 'standalone' or
419 m/static/ and $mode = 'static' or
420 m/dynamic/ and $mode = 'dynamic' or
421  
422 croak "Don't understand argument $_ (@_)";
423 }
424  
425 16 ▶ ($server, $server_module) = qw/apache2 fastcgi/ unless $server;
Branch: 1 branch
BranchTrueFalseTotal
unless $server 0 16 16
426 16 ▶ ($mode) = qw/standalone/ unless $mode;
Branch: 1 branch
BranchTrueFalseTotal
unless $mode 6 10 16
427  
428 16 my @data;
429  
430 16 my $bare = $ctx->option( 'bare' );
431  
432 16 my $catalyst_data = parse_catalyst $ctx;
433 16 push @data, %$catalyst_data;
434 16 my $name = $catalyst_data->{name};
435  
436 16 ▶ if ( $server =~ m/^apache2?$/ ) {
Branch: 5 branches
BranchTrueFalseTotal
if ($server =~ /^apache2?$/) { } 7 9 16
elsif ($server eq 'lighttpd') { } 3 6 9
elsif ($server eq 'nginx') { } 2 4 6
elsif ($server eq 'start-stop') { } 2 2 4
elsif ($server eq 'monit') { } 2 0 2
437  
438 7 ▶ if ( $mode eq 'standalone' ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($mode eq 'standalone') { } 5 2 7
elsif ($mode eq 'dynamic') { } 1 1 2
elsif ($mode eq 'static') { } 1 0 1
439 # TODO Error in Catalyst::Engine::FastCGI dox?
440 5 my @output;
441 5 push @output, 'catalyst-fastcgi.apache2' => process 'catalyst/fastcgi/apache2/standalone' => @data;
442 5 ▶ unless ($bare) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($bare) 2 3 5
443 2 push @output, 'start-stop' => process 'catalyst/fastcgi/start-stop' => @data;
444 2 push @output, 'monit' => process 'catalyst/fastcgi/monit' => @data;
445 }
446 5 output( $ctx, @output );
447 }
448 elsif ( $mode eq 'dynamic' ) {
449 1 output( $ctx, 'catalyst-fastcgi.apache2' => process 'catalyst/fastcgi/apache2/dynamic' => @data );
450 }
451 elsif ( $mode eq 'static' ) {
452 1 output( $ctx, 'catalyst-fastcgi.apache2' => process 'catalyst/fastcgi/apache2/static' => @data );
453 }
454 else {
455 0 croak "Don't understand mode \"$mode\""
456 }
457 }
458 elsif ( $server eq 'lighttpd' ) {
459  
460 3 ▶ if ( $mode eq 'standalone' ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($mode eq 'standalone') { } 2 1 3
elsif ($mode eq 'static') { } 1 0 1
461 2 my @output;
462 2 push @output, 'catalyst-fastcgi.lighttpd' => process 'catalyst/fastcgi/lighttpd/standalone' => @data;
463 2 ▶ unless ($bare) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($bare) 0 2 2
464 0 push @output, 'start-stop' => process 'catalyst/fastcgi/start-stop' => @data;
465 0 push @output, 'monit' => process 'catalyst/fastcgi/monit' => @data;
466 }
467 2 output( $ctx, @output );
468 }
469 elsif ( $mode eq 'static' ) {
470 1 output( $ctx, 'catalyst-fastcgi.lighttpd' => process 'catalyst/fastcgi/lighttpd/static' => @data );
471 }
472 else {
473 0 croak "Don't understand mode \"$mode\""
474 }
475 }
476 elsif ( $server eq 'nginx' ) {
477  
478 2 ▶ if ( $mode eq 'standalone' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($mode eq 'standalone') { } 2 0 2
479 2 my @output;
480 2 push @output, 'catalyst-fastcgi.nginx' => process 'catalyst/fastcgi/nginx' => @data;
481 2 ▶ unless ($bare) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($bare) 0 2 2
482 0 push @output, 'start-stop' => process 'catalyst/fastcgi/start-stop' => @data;
483 0 push @output, 'monit' => process 'catalyst/fastcgi/monit' => @data;
484 }
485 2 output( $ctx, @output );
486 }
487 else {
488 0 croak "Don't understand mode \"$mode\""
489 }
490 }
491 elsif ( $server eq 'start-stop' ) {
492 2 output( $ctx, 'catalyst-fastcgi-start-stop' => process 'catalyst/fastcgi/start-stop' => @data );
493 }
494 elsif ( $server eq 'monit' ) {
495 2 output( $ctx, 'catalyst-fastcgi-monit' => process 'catalyst/fastcgi/monit' => @data );
496 }
497 else {
498 0 croak "Don't understand server \"$server\""
499 }
500  
501 4 };
502  
503 on 'monit' =>
504 1 ▶ [qw/ output=s home=s monit-home=s /] => sub {
Subroutine __ANON__: called CC=2 SCAR=7.1
505 1 my $ctx = shift;
506  
507 1 my @home;
508 1 ▶ unless ($home[0] = $ctx->option( 'home' )) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($home[0] = $ctx->option("home")) 0 1 1
509 0 @home = qw/ . my-monit /;
510 }
511 1 my $home = dir @home;
512 1 $home = $home->absolute;
513 1 output( $ctx, monit => process 'monit' => ( home => $home ) );
514 4 };
515  
516 on 'help' =>
517 0 ▶ undef, sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
518 0 my $ctx = shift;
519  
520 0 do_help $ctx;
521 4 };
522  
523 0 ▶on qr/.*/ => undef, sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
524 0 my $ctx = shift;
525  
526 0 my $path = join ' ', $ctx->path;
527 0 print <<_END_;
528 Don't understand command: $path
529  
530 Usage: for-example [--help] ...
531  
532 catalyst/fastcgi apache2 standalone|static|dynamic
533 catalyst/fastcgi lighttpd standalone|static
534 catalyst/fastcgi nginx
535 catalyst/fastcgi start-stop|monit
536 catalyst/mod_perl
537 monit
538  
539 help
540  
541 _END_
542 0 exit -1;
543 4 };
544  
545 4 ▶no Getopt::Chain::Declare;
Subroutine BEGIN: called CC=1 SCAR=0.0
546  
547 =head1 SEE ALSO
548  
549 L<http://dev.catalystframework.org/wiki/deployment>
550  
551 L<Catalyst::Engine::Apache>
552  
553 L<Catalyst::Engine::FastCGI>
554  
555 =head1 ACKNOWLEDGEMENTS
556  
557 All the people that have put effort into the Catalyst documentation, including the pod, advent, and wiki
558  
559 Dan Dascalescu, Jay Shirley, Tomas Doran, Daniel Austin, Jason Felds, Moritz Onken, and Brian Friday, who all put effort into the deployment wiki, which
560 formed the basis for many parts of this tool
561  
562 =head1 AUTHOR
563  
564 Robert Krimen, C<< <rkrimen at cpan.org> >>
565  
566 =head1 BUGS
567  
568 Please report any bugs or feature requests to C<bug-app-forexample at rt.cpan.org>, or through
569 the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=App-ForExample>. I will be notified, and then you'll
570 automatically be notified of progress on your bug as I make changes.
571  
572  
573  
574  
575 =head1 SUPPORT
576  
577 You can find documentation for this module with the perldoc command.
578  
579 perldoc App::ForExample
580  
581  
582 You can also look for information at:
583  
584 =over 4
585  
586 =item * RT: CPAN's request tracker
587  
588 L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=App-ForExample>
589  
590 =item * AnnoCPAN: Annotated CPAN documentation
591  
592 L<http://annocpan.org/dist/App-ForExample>
593  
594 =item * CPAN Ratings
595  
596 L<http://cpanratings.perl.org/d/App-ForExample>
597  
598 =item * Search CPAN
599  
600 L<http://search.cpan.org/dist/App-ForExample/>
601  
602 =back
603  
604  
605 =head1 ACKNOWLEDGEMENTS
606  
607  
608 =head1 COPYRIGHT & LICENSE
609  
610 Copyright 2009 Robert Krimen, all rights reserved.
611  
612 This program is free software; you can redistribute it and/or modify it
613 under the same terms as Perl itself.
614  
615  
616 =cut
617  
618 4 __PACKAGE__; # End of App::ForExample
« ForExample/ModuleEmbedCatalog.pm ↑ Summary ForExample/Catalog.pm »