File Coverage

lib/Apache/SiteConfig/Template.pm
Criterion Covered Total %
statement 7 9 77.7
branch n/a
condition n/a
subroutine 3 3 100.0
pod n/a
total 10 12 83.3


line stmt bran cond sub pod time code
1             package Apache::SiteConfig::Template;
2 1     1   5 use warnings;
  1         2  
  1         24  
3 1     1   4 use strict;
  1         1  
  1         21  
4 1     1   394 use Moose;
  0            
  0            
5             use Apache::SiteConfig;
6             use Apache::SiteConfig::Root;
7              
8              
9             sub new_context {
10             return Apache::SiteConfig::Root->new;
11             }
12              
13             sub build {
14             my ($self,%args) = @_;
15              
16             my $args = \%args;
17             my $root = $self->new_context;
18             my $vir = $root->add_section( 'VirtualHost' , '*:80' );
19              
20             for( grep { $args->{$_} } qw(ServerName ServerAlias DocumentRoot)) {
21             $vir->add_directive( $_ , $args{$_} );
22             }
23              
24             my $root_dir = $vir->add_section('Directory' , '/');
25             $root_dir->add_directive( 'Options' , 'FollowSymLinks' );
26             $root_dir->add_directive( 'AllowOverride' , 'None' );
27              
28             my $doc_root = $vir->add_section('Directory', $args{DocumentRoot} );
29             $doc_root->add_directive( 'Options' , 'Indexes FollowSymLinks MultiViews' );
30             $doc_root->add_directive( 'AllowOverride' , 'None' );
31             $doc_root->add_directive( 'Order' , 'allow,deny' );
32             $doc_root->add_directive( 'Allow' , 'from all' );
33              
34             $vir->add_directive( 'LogLevel' , 'info' );
35             $vir->add_directive( 'CustomLog' , [ $args{CustomLog} , 'combine' ] ) if $args{CustomLog};
36             $vir->add_directive( 'ErrorLog' , $args{ErrorLog} ) if $args{ErrorLog};
37             return $root;
38             }
39              
40             1;
41             __END__
42              
43              
44             $ git clone git@foo.com:projectA.git /var/sites/projectA
45              
46             and will build site config args for template class:
47              
48             ServerName => 'foo.com',
49             ServerAlias => 'bar.com',
50             DocumentRoot => '/var/sites/projectA/webroot/'
51             AccessLog => '/var/sites/projectA/apache2/logs/access.log',
52             ErrorLog => '/var/sites/projectA/apache2/logs/error.log',
53