Bigtop
view release on metacpan or search on metacpan
lib/Bigtop/Backend/HttpdConf/Gantry.pm view on Meta::CPAN
label => 'Alternate Template',
descr => 'A custom TT template.',
type => 'text' },
];
}
sub gen_HttpdConf {
my $class = shift;
my $base_dir = shift;
my $tree = shift;
# write main file
my $configs = $tree->get_app_configs();
my $controller_configs = $tree->get_controller_configs();
my $conf_content = $class->output_httpd_conf( $tree, $configs, 'base' );
my $docs_dir = File::Spec->catdir( $base_dir, 'docs' );
mkdir $docs_dir;
my $conf_file = File::Spec->catfile( $docs_dir, 'httpd.conf' );
Bigtop::write_file( $conf_file, $conf_content );
# write other files
ALT_CONF:
foreach my $alt_conf ( keys %{ $configs } ) {
next ALT_CONF if $alt_conf eq 'base';
next ALT_CONF if $alt_conf =~ /CGI/i;
$conf_content = $class->output_httpd_conf(
$tree, $configs, $alt_conf, $controller_configs
);
$conf_file = File::Spec->catfile( $docs_dir, "httpd.$alt_conf.conf" );
Bigtop::write_file( $conf_file, $conf_content );
}
}
sub output_httpd_conf {
my $class = shift;
my $tree = shift;
my $configs = shift;
my $config_type = shift; # the name of the config we want
my $controller_configs = shift;
my $config = $tree->get_config->{HttpdConf};
my $skip_config = $config->{skip_config} || 0;
my $gconf = $config->{gantry_conf} || 0;
my $instance;
my $conffile;
if ( $gconf ) {
$skip_config = 1;
my $gantry_config = $tree->get_config->{Conf};
$instance = $gantry_config->{instance};
$conffile = $gantry_config->{conffile};
}
# let old timers go as before
$instance ||= $config->{instance } || 0;
$conffile ||= $config->{conffile } || 0;
if ( $instance and defined $config_type and $config_type ne 'base' ) {
$instance .= "_$config_type";
}
# first find the base location
my $location_output = $tree->walk_postorder( 'output_location' );
my $location = $location_output->[0] || ''; # default to host root
$location =~ s{/+$}{};
# then find out if we have a base controller
my $base_handler = $tree->walk_postorder( 'base_handler_anyone' );
$base_handler = ( $base_handler->[0] ) ? $tree->get_appname : 0;
# now build the <Perl> and <Location> blocks
my $perl_block_lines = $tree->walk_postorder(
'output_perl_block',
$tree->get_config()
);
my $httpd_walk_output = $tree->walk_postorder(
'output_httpd_conf_locations',
{
location => $location,
skip_config => $skip_config,
instance => $instance,
conffile => $conffile,
base_handler => $base_handler,
configs => $configs,
config_type => $config_type,
controller_configs => $controller_configs,
}
);
my %divided_output;
foreach my $output_el ( @{ $httpd_walk_output } ) {
my ( $type, $value ) = %{ $output_el };
push @{ $divided_output{ $type } }, $value;
}
my $conf_file = Bigtop::Backend::HttpdConf::Gantry::conf_file(
{
perl_block_lines => $perl_block_lines,
locations => $divided_output{ locations },
}
);
my %config_pairs;
CONFIG_PAIR:
foreach my $config_wrapper ( @{ $divided_output{ configs } } ) {
if ( ref( $config_wrapper ) eq 'ARRAY' ) {
foreach my $config_set ( @{ $config_wrapper } ) {
foreach my $config_item ( split /\n/, $config_set ) {
my ( undef, undef, $name, $value ) =
split /\s+/, $config_item;
$config_pairs{ $name } = $value;
}
}
}
( run in 0.763 second using v1.01-cache-2.11-cpan-39bf76dae61 )