| 1 | package Test::Instance::Apache::Config; | ||||||||||||
| 2 | |||||||||||||
| 3 | 4 | ▶ | use Moo; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 4 | 4 | ▶ | use List::Util qw/ pairs /; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 5 | 4 | ▶ | use IO::All; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 6 | 4 | ▶ | use namespace::clean; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 7 | |||||||||||||
| 8 | =head1 NAME | ||||||||||||
| 9 | |||||||||||||
| 10 | Test::Instance::Apache::Config - Create Apache Config File | ||||||||||||
| 11 | |||||||||||||
| 12 | =head1 SYNOPSIS | ||||||||||||
| 13 | |||||||||||||
| 14 | use FindBin qw/ $Bin /; | ||||||||||||
| 15 | use Test::Instance::Apache::Config; | ||||||||||||
| 16 | |||||||||||||
| 17 | my $config_manager = Test::Instance::Apache::Config->new( | ||||||||||||
| 18 | filename => "$Bin/conf/httpd.conf", | ||||||||||||
| 19 | config => [ | ||||||||||||
| 20 | PidFile => "$Bin/httpd.pid", | ||||||||||||
| 21 | Include => "$Bin/mods_enabled/*.load", | ||||||||||||
| 22 | Include => "$Bin/mods_enabled/*.conf", | ||||||||||||
| 23 | ], | ||||||||||||
| 24 | ); | ||||||||||||
| 25 | |||||||||||||
| 26 | $config_manager->write_config; | ||||||||||||
| 27 | |||||||||||||
| 28 | =head1 DESCRIPTION | ||||||||||||
| 29 | |||||||||||||
| 30 | Test::Instance::Apache allows you to spin up a complete Apache instance for | ||||||||||||
| 31 | testing. This is useful when developing various plugins for Apache, or if your | ||||||||||||
| 32 | application is tightly integrated to the webserver. | ||||||||||||
| 33 | |||||||||||||
| 34 | =head2 Attributes | ||||||||||||
| 35 | |||||||||||||
| 36 | These are the attributes available to set on a new object. | ||||||||||||
| 37 | |||||||||||||
| 38 | =head3 filename | ||||||||||||
| 39 | |||||||||||||
| 40 | The target filename to write the new config file to. | ||||||||||||
| 41 | |||||||||||||
| 42 | =cut | ||||||||||||
| 43 | |||||||||||||
| 44 | 4 | has filename => ( is => 'ro', required => 1 ); | |||||||||||
| 45 | |||||||||||||
| 46 | =head3 config | ||||||||||||
| 47 | |||||||||||||
| 48 | The arrayref to use to create the configuration file | ||||||||||||
| 49 | |||||||||||||
| 50 | =cut | ||||||||||||
| 51 | |||||||||||||
| 52 | has config => ( | ||||||||||||
| 53 | is => 'ro', | ||||||||||||
| 54 | 0 | ▶ | default => sub { return [] }, | ||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||
| 55 | 4 | ); | |||||||||||
| 56 | |||||||||||||
| 57 | has _config_string => ( | ||||||||||||
| 58 | is => 'lazy', | ||||||||||||
| 59 | 1 | ▶ | builder => sub { | ||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
Subroutine
_build__config_string: called CC=1 SCAR=0.0
| |||||||||||||
| 60 | 1 | my $self = shift; | |||||||||||
| 61 | 1 | return $self->_gen_string( $self->config ); | |||||||||||
| 62 | }, | ||||||||||||
| 63 | 4 | ); | |||||||||||
| 64 | |||||||||||||
| 65 | 4 | ▶ | sub _gen_string { | ||||||||||
|
Subroutine
_gen_string: called CC=3 SCAR=11.0
| |||||||||||||
| 66 | 4 | my ( $self, $data, $level ) = @_; | |||||||||||
| 67 | |||||||||||||
| 68 | 4 | ▶ | $level ||= 0; | ||||||||||
|
Condition100%2/2
$level ||= 0
MC/DC100%1/1
$level ||= 0
$level
Truth table100%2/2
A
A= $level
| |||||||||||||
| 69 | |||||||||||||
| 70 | return join '', map { | ||||||||||||
| 71 | 4 | my ($key, $value) = @$_; | |||||||||||
| 72 | 14 | ▶ | (ref($value) eq 'ARRAY' | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 73 | ? join('', | ||||||||||||
| 74 | (sprintf "<%s>\n", $key), | ||||||||||||
| 75 | $self->_gen_string($value, $level + 1), | ||||||||||||
| 76 | (sprintf "</%s>\n", split( ' ', $key )) | ||||||||||||
| 77 | ) | ||||||||||||
| 78 | : (' ' x $level).$key.' '.$value."\n" | ||||||||||||
| 79 | ) | ||||||||||||
| 80 | } pairs @$data; | ||||||||||||
| 81 | } | ||||||||||||
| 82 | |||||||||||||
| 83 | =head2 Methods | ||||||||||||
| 84 | |||||||||||||
| 85 | =head3 write_config | ||||||||||||
| 86 | |||||||||||||
| 87 | Write the config to the target filename. | ||||||||||||
| 88 | |||||||||||||
| 89 | =cut | ||||||||||||
| 90 | |||||||||||||
| 91 | 2 | ▶ | sub write_config { | ||||||||||
|
Subroutine
write_config: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 92 | 2 | my $self = shift; | |||||||||||
| 93 | |||||||||||||
| 94 | 2 | io( $self->filename )->print( $self->_config_string ); | |||||||||||
| 95 | } | ||||||||||||
| 96 | |||||||||||||
| 97 | =head1 AUTHOR | ||||||||||||
| 98 | |||||||||||||
| 99 | Tom Bloor E<lt>t.bloor@shadowcat.co.ukE<gt> | ||||||||||||
| 100 | |||||||||||||
| 101 | =head1 COPYRIGHT | ||||||||||||
| 102 | |||||||||||||
| 103 | Copyright 2016 Tom Bloor | ||||||||||||
| 104 | |||||||||||||
| 105 | =head1 LICENCE | ||||||||||||
| 106 | |||||||||||||
| 107 | This library is free software; you can redistribute it and/or modify | ||||||||||||
| 108 | it under the same terms as Perl itself. | ||||||||||||
| 109 | |||||||||||||
| 110 | =head1 SEE ALSO | ||||||||||||
| 111 | |||||||||||||
| 112 | =over | ||||||||||||
| 113 | |||||||||||||
| 114 | =item * L<Test::Instance::Apache> | ||||||||||||
| 115 | |||||||||||||
| 116 | =item * L<Test::Instance::Apache::Modules> | ||||||||||||
| 117 | |||||||||||||
| 118 | =back | ||||||||||||
| 119 | |||||||||||||
| 120 | =cut | ||||||||||||
| 121 | |||||||||||||
| 122 | 4 | 1; | |||||||||||