Apache/Modules.pm

filter: Statementstmt 67.3% 31 / 46 Branchbran 25.0% 1 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 81.8% 9 / 11 Podpod 100% 2 / 2 totaltotal 68.2% 43 / 63 CC 7 SCAR 14.5
CC
7
Cov
64%
load_modules
12.8
__ANON__
2.5
_build_include_modules
2.5
CRAP 4.3
« Apache.pm ↑ Summary Apache/Config.pm »
1 package Test::Instance::Apache::Modules;
2  
3 5 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 5 ▶use IO::All;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 =head1 NAME
7  
8 Test::Instance::Apache::Modules - Apache module management for T::I::A
9  
10 =head1 SYNOPSIS
11  
12 use FindBin qw/ $Bin /;
13 use Test::Instance::Apache::Modules;
14  
15 my $modules = Test::Instance::Apache::Modules->new(
16 server_root => "$Bin/conf",
17 modules => [ qw/ mpm_prefork authz_core mome / ],
18 );
19  
20 # get include paths for config
21 my $paths = $modules->include_modules;
22  
23 =head1 DESCRIPTION
24  
25 Test::Instance::Apache::Modules sets up the required modules for Apache
26 according to an array of module names. This functions similarly to C<a2enmod>
27 which comes as part of the Apache distribution, however is much more simplified
28 to only do what is necessary for T::I::A.
29  
30 The module creates a C<mods-available> and C<mods-enabled> folder inside the
31 L</server_root> directory, and then copies the contents of
32 C</etc/apache2/mods-available> into the new C<mods-available> folder. Then,
33 symlinks are created across to the C<mods-enabled> folder, ready for Apache to
34 include from the L</include_modules> list.
35  
36 =head2 Attributes
37  
38 These are the available attributes on Test::Instance::Apache::Modules
39  
40 =head3 modules
41  
42 The arrayref of modules to symlink into C<mods-enabled> folder. This is
43 required. Note that any modules specified here will need to be installed on
44 your local machine, and you will have to specify ALL modules required - there
45 are no assumptions made for modules to include.
46  
47 =cut
48  
49 has modules => (
50 is => 'ro',
51 required => 1,
52 3 ▶ isa => sub { die "modules must be an array!\n" unless ref $_[0] eq 'ARRAY' },
Subroutine __ANON__: called CC=2 SCAR=7.6
Branch: 1 branch
BranchTrueFalseTotal
unless ref $_[0] eq "ARRAY" 0 3 3
53 5 );
54  
55 =head3 server_root
56  
57 The root directory of the server config. This directory is where
58 C<mods-available> and C<mods-enabled> directories will be created. This
59 attribute is required.
60  
61 =cut
62  
63 5 has server_root => (
64 is => 'ro',
65 required => 1,
66 );
67  
68 has _available_mods_folder => (
69 is => 'lazy',
70 1 ▶ builder => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine _build__available_mods_folder: called CC=1 SCAR=0.0
71 1 my $self = shift;
72 1 return $self->make_server_dir( 'mods-available' );
73 },
74 5 );
75  
76 has _enabled_mods_folder => (
77 is => 'lazy',
78 0 ▶ builder => sub {
Subroutine _build__enabled_mods_folder: not called CC=1 SCAR=1.2
Subroutine __ANON__: called CC=1 SCAR=1.2
79 0 my $self = shift;
80 0 return $self->make_server_dir( 'mods-enabled' );
81 },
82 5 );
83  
84 =head3 include_modules
85  
86 This creates the include paths for the C<conf> and C<load> files as required by
87 Apache.
88  
89 =cut
90  
91 has include_modules => (
92 is => 'lazy',
93 0 ▶ builder => sub {
Subroutine __ANON__: not called CC=2 SCAR=9.2
Subroutine _build_include_modules: called CC=2 SCAR=9.2
94 0 my $self = shift;
95 0 my @include;
96 0 foreach ( qw/ load conf / ) {
97 0 push @include, 'Include';
98 0 push @include, sprintf( '%s/*.%s', $self->_enabled_mods_folder, $_ );
99 }
100 0 return \@include;
101 },
102 5 );
103  
104 =head2 Methods
105  
106 These are the methods available on Test::Instance::Apache::Modules.
107  
108 =head3 load_modules
109  
110 This function performs the main part of this module. This copies all the
111 current mods from C</etc/apache2/mods-available> to the C<mods-available>
112 directory, and then symlinks all the required modules across to the
113 C<mods-enabled> folder.
114  
115 =cut
116  
117 3 ▶sub load_modules {
Subroutine load_modules: called CC=4 SCAR=25.5
Pod documented
118 3 my $self = shift;
119  
120 3 io->dir( '/etc/apache2/mods-available' )->copy( $self->_available_mods_folder );
121  
122 0 for my $module ( @{ $self->modules } ) {
123 0 for my $suffix ( qw/ conf load / ) {
124 0 my $source_filename = File::Spec->catfile(
125 $self->_available_mods_folder,
126 sprintf( '%s.%s', $module, $suffix )
127 );
128 0 my $target_filename = File::Spec->catfile(
129 $self->_enabled_mods_folder,
130 sprintf( '%s.%s', $module, $suffix )
131 );
132 0 ▶ if ( -f $source_filename ) {
Branch: 1 branch
BranchTrueFalseTotal
if (-f $source_filename) 0 0 0
133 # if the file does not exist, just ignore it as not all mods have config files
134 0 symlink( $source_filename, $target_filename );
135 }
136 }
137 }
138 }
139  
140 =head3 make_server_dir
141  
142 Utility function to create a new directory in the L</server_root>.
143  
144 =cut
145  
146 5 ▶sub make_server_dir {
Subroutine make_server_dir: called CC=1 SCAR=0.0
Pod documented
147 5 my ( $self, @dirnames ) = @_;
148 5 my $dir = File::Spec->catdir( $self->server_root, @dirnames );
149 5 mkdir $dir;
150 5 return $dir;
151 }
152  
153 =head1 AUTHOR
154  
155 Tom Bloor E<lt>t.bloor@shadowcat.co.ukE<gt>
156  
157 =head1 COPYRIGHT
158  
159 Copyright 2016 Tom Bloor
160  
161 =head1 LICENCE
162  
163 This library is free software; you can redistribute it and/or modify
164 it under the same terms as Perl itself.
165  
166 =head1 SEE ALSO
167  
168 =over
169  
170 =item * L<Test::Instance::Apache>
171  
172 =back
173  
174 =cut
175  
176 5 1;
« Apache.pm ↑ Summary Apache/Config.pm »