blib/lib/Catalyst/Helper/InitScript/FreeBSD.pm

filter: Statementstmt 35.3% 23 / 65 Branchbran 0.0% 0 / 12 Conditioncond 0.0% 0 / 12 MC/DCmcdc 0.0% 0 / 7 Subroutinesub 63.6% 7 / 11 Podpod 100% 1 / 1 totaltotal 28.7% 31 / 108 CC 13 SCAR 40.3
CC
13
Cov
26%
mk_stuff
112.9
_render_file
12.0
_usage
2.0
CRAP 56.1
↑ Summary
1 package Catalyst::Helper::InitScript::FreeBSD;
2  
3 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 2 ▶use English;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use File::Spec::Functions;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶use Term::Prompt;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶use Getopt::Long;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 2 our $VERSION = '0.01';
12  
13 =head1 NAME
14  
15 Catalyst::Helper::InitScript::FreeBSD - /usr/local/etc/rc.d/yourapp.sh generator.
16  
17 =head1 SYNOPSIS
18  
19 % ./script/yourapp_create.pl InitScript::FreeBSD -- --help
20 usage: ./script/yourapp_create.pl
21 -? -help display this help and exits.
22 -user The real uid of fastcgi process. [default is USERNAME]
23 -group The real gid of fastcgi process. [default is GROUP]
24 -p -pidfile specify filename for pid file.
25 [default is /var/run/yourapp.pid]
26 -l -listen Socket path to listen on can be HOST:PORT, :PORT or a filesystem path.
27 [default is /var/run/yourapp.sockets]
28 -n -nproc specify number of processes to keep to serve requests.
29 [default is 4]
30 -mysql run after init mysql. [default is no]
31 -postgresql run after init postgresql. [default is no]
32  
33 % ./script/yourapp_create.pl InitScript::FreeBSD -- -nproc 2 -mysql
34 /usr/home/bokutin/svk/YourApp/trunk/script/../yourapp.sh.sample is exist.
35 overwrite? (y or n) [default n] y
36 /usr/home/bokutin/svk/YourApp/trunk/script/../yourapp.sh.sample was created.
37  
38 The following commands were needed to complete setting up.
39 % sudo cp /usr/home/bokutin/svk/YourApp/trunk/script/../yourapp.sh.sample /usr/local/etc/rc.d/yourapp.sh
40 % sudo chmod 755 /usr/local/etc/rc.d/yourapp.sh
41 % sudo touch /var/run/yourapp.pid
42 % sudo touch /var/run/yourapp.sockets
43  
44 =cut
45  
46 =head2 mk_stuff
47  
48 =cut
49  
50 0 ▶sub mk_stuff {
Subroutine mk_stuff: not called CC=11 SCAR=47.3
Pod documented
51 0 my ( $class, $helper, @args ) = @_;
52  
53 # vars
54 my $vars = {
55 app => lc($helper->{app}) || die,
56 base => $helper->{base},
57 0 ▶ user => getpwuid($UID) || "",
Condition0%0/6
lc $helper->{'app'} || die()
l!l
00
getpwuid $Catalyst::Helper::InitScript::FreeBSD::UID || ''
l!l
00
getgrgid $Catalyst::Helper::InitScript::FreeBSD::GID || ''
l!l
00
MC/DC0%0/1
lc $helper->{'app'} || die()
lc $helper->{'app'}
MC/DC0%0/1
getpwuid $Catalyst::Helper::InitScript::FreeBSD::UID || ''
getpwuid $Catalyst::Helper::InitScript::FreeBSD::UID
MC/DC0%0/1
getgrgid $Catalyst::Helper::InitScript::FreeBSD::GID || ''
getgrgid $Catalyst::Helper::InitScript::FreeBSD::GID
Truth table0%0/2
A
A= lc $helper->{'app'}
Aresult
11
00
Truth table0%0/2
A
A= getpwuid $Catalyst::Helper::InitScript::FreeBSD::UID
Aresult
11
00
Truth table0%0/2
A
A= getgrgid $Catalyst::Helper::InitScript::FreeBSD::GID
Aresult
11
00
58 group => getgrgid($GID) || "",
59 nproc => 4,
60 use_socket => 1,
61 };
62 0 $vars->{pidfile} = "/var/run/$vars->{app}.pid";
63 0 $vars->{listen} = "/var/run/$vars->{app}.sockets";
64 0 my $output = canonpath(catfile($vars->{base}, "$vars->{app}.sh.sample"));
65  
66 # parse args
67 {
68 0 ▶ no warnings 'uninitialized';
Subroutine BEGIN: called CC=1 SCAR=0.2
69 0 my $opts = {};
70 0 local @ARGV = @args;
71 my $ret = GetOptions(
72 'help|?' => \$opts->{help},
73 'user=s' => \$opts->{user},
74 'group=s' => \$opts->{group},
75 'pidfile|p=s' => \$opts->{pidfile},
76 'listen|l=s' => \$opts->{listen},
77 'nproc|n=i' => \$opts->{nproc},
78 'mysql' => \$opts->{mysql},
79 'postgresql' => \$opts->{postgresql},
80 0 );
81 0 ▶ if (!$ret or $opts->{help}) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $ret or $opts->{"help"}) 0 0 0
Condition0%0/3
not $ret or $opts->{"help"}
l!l&&r!l&&!r
000
MC/DC0%0/2
not $ret or $opts->{"help"}
not $ret $opts->{"help"}
Truth table0%0/3
not(A) or B
A= not $retB= $opts->{"help"}
ABresult
1X1
011
000
82 0 $class->_usage($vars);
83 0 return 0;
84 }
85 0 ▶ if ($opts->{listen} =~ m/:\d+$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->{"listen"} =~ /:\d+$/) 0 0 0
86 0 $opts->{use_socket} = 0;
87 }
88 0 delete $opts->{$_} for (grep { ! length $opts->{$_} } keys %$opts);
89 0 $vars = { %$vars, %$opts };
90 }
91
92 # processing
93 0 ▶ if (-f $output and !$class->_ask_overwite($vars, $output)) {
Branch: 1 branch
BranchTrueFalseTotal
if (-f $output and not $class->_ask_overwite($vars, $output)) { } 0 0 0
Condition0%0/3
-f $output and not $class->_ask_overwite($vars, $output)
!ll&&!rl&&r
000
MC/DC0%0/2
-f $output and not $class->_ask_overwite($vars, $output)
-f $output not $class->_ask_overwite($vars, $output)
Truth table0%0/3
A and not(B)
A= -f $outputB= not $class->_ask_overwite($vars, $output)
ABresult
0X0
100
111
94 0 print "cancelled.\n";
95 0 return 0;
96 }
97 else {
98 0 $class->_render_file($helper, $vars, $output);
99  
100 0 my @msgs;
101 0 push @msgs, "$output was created.";
102 0 push @msgs, "";
103 0 push @msgs, "The following commands were needed to complete setting up.";
104 0 push @msgs, "% sudo cp $output /usr/local/etc/rc.d/$vars->{app}.sh";
105 0 push @msgs, "% sudo chmod 755 /usr/local/etc/rc.d/$vars->{app}.sh";
106 0 push @msgs, "% sudo touch $vars->{pidfile}";
107 0 ▶ push @msgs, "% sudo touch $vars->{listen}" if $vars->{use_socket};
Branch: 1 branch
BranchTrueFalseTotal
if $vars->{"use_socket"} 0 0 0
108  
109 0 print join("\n", @msgs), "\n";
110 }
111  
112 0 return 1;
113 }
114  
115 0 ▶sub _usage {
Subroutine _usage: not called CC=1 SCAR=6.9
116 0 my ($class, $vars) = @_;
117  
118 0 print <<USAGE;
119 usage: $0
120 -? -help display this help and exits.
121 -user The real uid of fastcgi process. [default is $vars->{user}]
122 -group The real gid of fastcgi process. [default is $vars->{group}]
123 -p -pidfile specify filename for pid file.
124 [default is $vars->{pidfile}]
125 -l -listen Socket path to listen on can be HOST:PORT, :PORT or a filesystem path.
126 [default is $vars->{listen}]
127 -n -nproc specify number of processes to keep to serve requests.
128 [default is $vars->{nproc}]
129 -mysql run after init mysql. [default is no]
130 -postgresql run after init postgresql. [default is no]
131 USAGE
132 }
133  
134 0 ▶sub _ask_overwite {
Subroutine _ask_overwite: not called CC=1 SCAR=6.9
135 0 my ($class, $vars, $output) = @_;
136  
137 0 prompt('y', "$output is exist. overwrite?", "", "");
138 }
139  
140 0 ▶sub _render_file {
Subroutine _render_file: not called CC=3 SCAR=24.8
141 0 my ($class, $helper, $vars, $output) = @_;
142  
143 0 my $file = 'init_script';
144  
145 0 my $t = Template->new;
146 0 my $template = $helper->get_file( __PACKAGE__, $file );
147 0 ▶ return 0 unless $template;
Branch: 1 branch
BranchTrueFalseTotal
unless $template 0 0 0
148 0 ▶ $t->process( \$template, $vars, $output )
Branch: 1 branch
BranchTrueFalseTotal
$t->process(\$template, $vars, $output) or "Catalyst::Exception"->throw("message", qq[Couldn't process "$file", ] . $t->error) 0 0 0
149 || Catalyst::Exception->throw(
150 message => qq/Couldn't process "$file", / . $t->error() );
151  
152 0 return 1;
153 }
154  
155 =head1 AUTHOR
156  
157 Tomohiro Hosaka, C<< <bokutin at cpan.org> >>
158  
159 =head1 COPYRIGHT & LICENSE
160  
161 Copyright 2008 Tomohiro Hosaka, all rights reserved.
162  
163 This program is free software; you can redistribute it and/or modify it
164 under the same terms as Perl itself.
165  
166 =cut
167  
168 2 1; # End of Catalyst::Helper::InitScript::FreeBSD
169  
170 __DATA__
↑ Summary