VW/Setup.pm untested

filter: Statementstmt 0.0% 0 / 46 Branchbran 0.0% 0 / 8 Conditioncond 0.0% 0 / 10 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 0.0% 0 / 9 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 79 CC 5 SCAR 25.5
CC
5
Cov
0%
run
30.0
options
2.0
BEGIN
2.0
CRAP 12.8
1 package App::VW::Setup;
2 use strict;
3 use warnings;
4 use App::VW;
5 use Cwd;
6 use base 'App::VW::Command';
7 use File::ShareDir 'module_dir';
8 use YAML 'DumpFile';
9  
10 my $config = App::VW->config;
11  
12 sub options {
13 my ($class) = @_;
14 (
15 $class->SUPER::options,
16 'port|p=i' => 'port',
17 'size|s=s' => 'size',
18 'modules|m=s@' => 'modules',
19 );
20 }
21  
22 sub run {
23 my ($self, $app) = @_;
24  
25 die("Please specify an App to start.\n")
26 if (not defined $app);
27  
28 my $cwd = getcwd;
29 my $cluster_description = {
30 app => $app,
31 dir => $cwd,
32 port => $self->{port} || 4000,
33 cluster_size => $self->{size} || 1,
34 };
35  
36 if ($self->{modules}) {
37 $cluster_description->{modules} =
38 join(" ", @{ $self->{modules} });
39 }
40  
41 my $app_name = lc $cluster_description->{app};
42 $app_name =~ s/::/_/g;
43 my $yaml_file = "$config->{etc}/$app_name.yml";
44 print "Creating $yaml_file.\n" if ($self->{verbose});
45 DumpFile($yaml_file, $cluster_description) || die($!);
46  
47 my $src = module_dir('App::VW') . "/etc/vw_harness.tmpl";
48 my $harness_file = "$cwd/vw_harness.pl";
49 print "Creating $harness_file.\n" if ($self->{verbose});
50  
51 open(IN, "<", $src) || die ($!);
52 my $tmpl = join('', <IN>);
53 close(IN);
54  
55 $tmpl =~ s/\[%\s*(\w+)\s*%\]/$cluster_description->{$1}/eg;
56  
57 open(OUT, ">", $harness_file) || die($!);
58 print OUT $tmpl;
59 close(OUT);
60 }
61  
62 1;
63  
64 =head1 NAME
65  
66 App::VW::Setup - setup a Squatting app for deployment via Continuity
67  
68 =head1 SYNOPSIS
69  
70 Usage:
71  
72 vw setup <App> [OPTION]...
73  
74 Example: How to setup a Squatting app called 'Bavl'
75  
76 # Go to the directory your squatting app is in.
77 cd /www/towr.of.bavl.org
78  
79 # Run the setup command
80 sudo vw setup Bavl --port 6000
81  
82 # You should have 2 new files in your system, now:
83 /etc/vw/bavl.yml
84 /www/towr.of.bavl.org/vw_harness.pl
85  
86 =head1 DESCRIPTION
87  
88 The C<setup> command installs 2 files into your system so that vw will be able
89 to start your app as a daemonized server at boot time. See L<App::VW> for
90 details.
91  
92 =head1 OPTIONS
93  
94 =over 4
95  
96 =item -p, --port=PORT
97  
98 This is the port that the first process in the cluster will listen to. Its
99 default value is C<4000>, but you should really specify one yourself.
100  
101 =item -s, --size=SIZE
102  
103 This is the number of processes in the cluster. Its default value is C<1>.
104  
105 =item -m, --modules=PLUGIN
106  
107 This option is used to specify which plugins you want your Squatting app to
108 load before starting. You can use this option multiple times.
109  
110 B<Example>:
111  
112 sudo vw setup ChatterBox -m With::AccessTrace -m With::Log --port 9000
113  
114 =back
115  
116 =cut