ASP4
view release on metacpan or search on metacpan
lib/ASP4/Config.pm view on Meta::CPAN
# Just in case we're dealing with a file-based db like SQLite:
foreach my $key (qw/ session main /)
{
$s->{data_connections}->{$key}->{dsn} =~ s/\@ServerRoot\@/$root/;
$s->{data_connections}->{$key}->{dsn} =~ s/\@ProjectRoot\@/$project_root/;
$s->{data_connections}->{$key}->{dsn} =~ s{\\\\}{\\}g;
}# end foreach()
# Make sure that $s->page_cache_root exists:
unless( $s->{web}{page_cache_root} )
{
if( $^O =~ m{win32}i )
{
my $temp_root = $ENV{TMP} || $ENV{TEMP};
$s->{web}{page_cache_root} = "$temp_root\\PAGE_CACHE";
}
else
{
$s->{web}{page_cache_root} = "/tmp/PAGE_CACHE";
}# end if()
}# end unless()
unless( -d $s->{web}{page_cache_root} )
{
my @parts = split /[\/\\]/, $s->{web}{page_cache_root};
my $root = $^O =~ m{win32}i ? '' : "/";
while( my $next = shift(@parts) )
{
$root .= "$next/";
mkdir($root) unless -d $root;
die "Cannot create path to '@{[ $s->web->page_cache_root ]}' - stopped at '$root': $!"
unless -d $root;
chmod(0777, $root);
}# end while()
}# end unless()
(my $compiled_root = $s->{web}->{page_cache_root} . '/' . $s->{web}->{application_name}) =~ s/::/\//g;
my $folder = $^O =~ m{win32}i ? '' : "/";
foreach my $part ( grep { $_ } split /[\/\\]/, $compiled_root )
{
$folder .= "$part/";
unless( -d $folder )
{
mkdir($folder);
chmod(0777, $folder)
}# end unless()
confess "Folder '$folder' does not exist and cannot be created"
unless -d $folder;
}# end foreach()
confess "Folder '$folder' exists but cannot be written to"
unless -w $folder;
}# end init_server_root()
sub load_class
{
my ($s, $class) = @_;
(my $file = "$class.pm") =~ s/::/\//g;
eval { require $file; }
or confess "Cannot load $class: $@";
}# end load_class()
sub DESTROY
{
my $s = shift;
undef(%$s);
}
1;# return true:
=pod
=head1 NAME
ASP4::Config - Central configuration for ASP4
=head1 SYNOPSIS
# Settings:
$Config->system->settings->some_setting;
$Config->system->settings->another_setting;
# Error-handling:
$Config->errors->error_handler;
$Config->errors->mail_errors_to;
$Config->errors->mail_errors_from;
$Config->errors->smtp_server;
# Web:
$Config->web->application_name;
$Config->web->application_root;
$Config->web->project_root;
$Config->web->www_root;
$Config->web->handler_root;
$Config->web->media_manager_upload_root;
$Config->web->page_cache_root;
# Data Connections:
foreach my $conn ( map { $Config->data_connections->$_ } qw/ session application main / )
{
my $dbh = DBI->connect(
$conn->dsn,
$conn->username,
$conn->password
);
}# end foreach()
=head1 JSON Config File
ASP4::ASP keeps all of its configuration inside of C</conf/asp4-config.json>
Here is an example:
{
"system": {
"post_processors": [
( run in 0.516 second using v1.01-cache-2.11-cpan-5a3173703d6 )