line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Ado::Command::generate::apache2htaccess; |
2
|
2
|
|
|
2
|
|
2137
|
use Mojo::Base 'Ado::Command::generate'; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
12
|
|
3
|
2
|
|
|
2
|
|
273
|
use Getopt::Long qw(GetOptionsFromArray :config no_auto_abbrev no_ignore_case); |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
17
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
has description => "Generates Apache2 .htaccess file.\n"; |
6
|
|
|
|
|
|
|
has usage => sub { shift->extract_usage }; |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
# The next two are more or less stollen from File::Which. |
9
|
|
|
|
|
|
|
my $IS_DOS = ($^O eq 'MSWin32' or $^O eq 'dos' or $^O eq 'os2'); |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub _which { |
12
|
2
|
|
|
2
|
|
37594
|
my ($self, $basename) = @_; |
13
|
2
|
100
|
|
|
|
19
|
return $self->{$basename} if $self->{$basename}; |
14
|
1
|
|
|
|
|
3
|
my @pathext = (''); |
15
|
1
|
50
|
33
|
|
|
7
|
push @pathext, map {lc} split /;/, $ENV{PATHEXT} if $ENV{PATHEXT} && $IS_DOS; |
|
0
|
|
|
|
|
0
|
|
16
|
1
|
|
|
|
|
24
|
foreach my $path (File::Spec->path($ENV{PATH})) { |
17
|
2
|
|
|
|
|
3
|
foreach my $ext (@pathext) { |
18
|
2
|
50
|
|
|
|
23
|
my $exe = File::Spec->catfile($path, ($ext ? "$basename.$ext" : $basename)); |
19
|
2
|
|
|
|
|
5
|
$exe =~ s|\\|/|g; |
20
|
2
|
100
|
|
|
|
48
|
return $self->{$basename} = $exe if -e $exe; |
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
} |
23
|
0
|
|
|
|
|
0
|
return ''; |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub run { |
27
|
1
|
|
|
1
|
1
|
44
|
my ($self, @args) = @_; |
28
|
1
|
|
|
|
|
6
|
state $app = $self->app; |
29
|
1
|
|
|
|
|
9
|
state $home = $app->home; |
30
|
1
|
|
|
|
|
7
|
state $ado_home = $app->ado_home; |
31
|
1
|
|
|
|
|
10
|
my $args = $self->args; |
32
|
|
|
|
|
|
|
GetOptionsFromArray \@args, |
33
|
|
|
|
|
|
|
'v|verbose' => \$args->{verbose}, |
34
|
|
|
|
|
|
|
'c|config_file=s' => \$args->{config_file}, |
35
|
1
|
|
50
|
|
|
10
|
'M|modules=s@' => \($args->{modules} //= []); |
36
|
|
|
|
|
|
|
|
37
|
1
|
|
|
|
|
317
|
@{$args->{modules}} = split(/\,/, join(',', @{$args->{modules}})); |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
3
|
|
38
|
|
|
|
|
|
|
|
39
|
1
|
50
|
|
|
|
2
|
Carp::croak $self->usage unless scalar @{$args->{modules}}; |
|
1
|
|
|
|
|
3
|
|
40
|
1
|
|
|
|
|
2
|
$args->{DocumentRoot} = $home; |
41
|
1
|
|
|
|
|
3
|
$args->{perl} = $^X; |
42
|
|
|
|
|
|
|
|
43
|
1
|
50
|
|
|
|
3
|
if ($IS_DOS) { |
44
|
0
|
|
|
|
|
0
|
$args->{DocumentRoot} =~ s|\\|/|g; |
45
|
0
|
|
|
|
|
0
|
$args->{perl} =~ s|\\|/|g; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
$args->{plackup} = $self->_which('plackup') |
48
|
1
|
|
|
|
|
575
|
if ( eval { require Plack } |
49
|
1
|
|
|
|
|
582
|
&& eval { require FCGI } |
50
|
1
|
|
|
|
|
1434
|
&& eval { require FCGI::ProcManager } |
51
|
1
|
50
|
33
|
|
|
2
|
&& eval { require Apache::LogFormat::Compiler }); |
|
1
|
|
33
|
|
|
3128
|
|
|
|
|
33
|
|
|
|
|
52
|
|
|
|
|
|
|
|
53
|
1
|
50
|
|
|
|
14
|
say STDERR 'Using arguments:' . $app->dumper($args) if $args->{verbose}; |
54
|
1
|
|
|
|
|
3
|
state $rel_file = 'templates/partials/apache2htaccess.ep'; |
55
|
1
|
50
|
|
|
|
6
|
state $template_file = ( |
56
|
|
|
|
|
|
|
-s $home->rel_file($rel_file) |
57
|
|
|
|
|
|
|
? $home->rel_file($rel_file) |
58
|
|
|
|
|
|
|
: $ado_home->rel_file($rel_file) |
59
|
|
|
|
|
|
|
); |
60
|
1
|
|
|
|
|
54
|
$args->{moniker} = $app->moniker; |
61
|
1
|
|
|
|
|
26
|
my $config = Mojo::Template->new->render_file($template_file, $args); |
62
|
1
|
50
|
|
|
|
37
|
if ($args->{config_file}) { |
63
|
1
|
50
|
|
|
|
5
|
say STDERR 'Writing ' . $args->{config_file} if $args->{verbose}; |
64
|
1
|
|
|
|
|
6
|
Mojo::Util::spurt($config, $args->{config_file}); |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
else { |
67
|
0
|
|
|
|
|
0
|
say $config; |
68
|
|
|
|
|
|
|
} |
69
|
1
|
|
|
|
|
259
|
return $self; |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
1; |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
=pod |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
=encoding utf8 |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
=head1 NAME |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
Ado::Command::generate::apache2htaccess - Generates Apache2 .htaccess file |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
=head1 SYNOPSIS |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
Usage: |
86
|
|
|
|
|
|
|
#on the command-line |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
$ bin/ado generate apache2htaccess --modules cgi,fcgid > .htaccess |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
#programatically |
91
|
|
|
|
|
|
|
use Ado::Command::generate::apache2htaccess; |
92
|
|
|
|
|
|
|
my $v = Ado::Command::generate::apache2htaccess->new; |
93
|
|
|
|
|
|
|
$v->run('--modules' => 'cgi,fcgid'); |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=head1 DESCRIPTION |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
L |
98
|
|
|
|
|
|
|
generates an Apache2 C<.htaccess> configuration file for your L application. |
99
|
|
|
|
|
|
|
You can use this command for a shared hosting account. |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
This is a core command, that means it is always enabled and its code a good |
102
|
|
|
|
|
|
|
example for learning to build new commands, you're welcome to fork it. |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=head1 OPTIONS |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
Below are the options this command accepts, described in L notation. |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=head2 c|config_file=s |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
Full path to the file in which the configuration will be written. |
111
|
|
|
|
|
|
|
If not provided the configuration is printed to the screen. |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
=head3 v|verbose |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
Verbose output. |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
=head2 M|modules=s@ |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
Apache modules to use for running C. Currently supported modules are |
120
|
|
|
|
|
|
|
C and C. You can mention them both to add the corresponding |
121
|
|
|
|
|
|
|
sections and Apache will use C if loaded or C |
122
|
|
|
|
|
|
|
(almost always enabled). |
123
|
|
|
|
|
|
|
The generated configuration for mod_fcgid will use L (C) or |
124
|
|
|
|
|
|
|
L. So make sure you have at least one of them installed. |
125
|
|
|
|
|
|
|
L is recommended. |
126
|
|
|
|
|
|
|
To use L with C you will need to install |
127
|
|
|
|
|
|
|
L, L and L. |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
=head1 ATTRIBUTES |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
L inherits all attributes from |
132
|
|
|
|
|
|
|
L and implements the following new ones. |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
=head2 description |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
my $description = $htaccess->description; |
137
|
|
|
|
|
|
|
$v = $htaccess->description('Foo!'); |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
Short description of this command, used for the command list. |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
=head2 usage |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
my $usage = $htaccess->usage; |
144
|
|
|
|
|
|
|
$v = $htaccess->usage('Foo!'); |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
Usage information for this command, used for the help screen. |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
=head1 METHODS |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
L inherits all methods from |
152
|
|
|
|
|
|
|
L and implements the following new ones. |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
=head2 run |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
my $htaccess = Ado::Command::generate::apache2htaccess->run(@ARGV); |
157
|
|
|
|
|
|
|
my $htaccess = $app->commands->run("generate", "apache2htaccess", |
158
|
|
|
|
|
|
|
'-m' => 'cgi,fcgid', '-c' => $config_file); |
159
|
|
|
|
|
|
|
Run this command. Returns C<$self>. |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
=head1 SEE ALSO |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
L, |
164
|
|
|
|
|
|
|
L, |
165
|
|
|
|
|
|
|
L, |
166
|
|
|
|
|
|
|
L, |
167
|
|
|
|
|
|
|
L, L, |
168
|
|
|
|
|
|
|
L L, |
169
|
|
|
|
|
|
|
L, L, |
170
|
|
|
|
|
|
|
L. |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
=cut |