ASP4
view release on metacpan or search on metacpan
lib/ASP4/Config.pm view on Meta::CPAN
{
$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": [
],
"libs": [
"@ServerRoot@/lib",
"@ProjectRoot@/lib"
],
"load_modules": [
"DBI",
"DBD::SQLite"
],
"env_vars": {
"myvar": "Some-Value",
"another_var": "Another Value"
},
"settings": {
"foo": "bar",
"baz": "bux"
}
},
"errors": {
"error_handler": "ASP4::ErrorHandler",
"mail_errors_to": "you@yours.com",
"mail_errors_from": "root@localhost",
"smtp_server": "localhost"
},
"web": {
"application_name": "DefaultApp",
"application_root": "@ServerRoot@",
"www_root": "@ServerRoot@/htdocs",
"handler_root": "@ServerRoot@/handlers",
"page_cache_root": "/tmp/PAGE_CACHE",
"handler_resolver": "ASP4::HandlerResolver",
"handler_runner": "ASP4::HandlerRunner",
"filter_resolver": "ASP4::FilterResolver",
"request_filters": [
{
"uri_match": "^/.*",
"class": "My::Filter"
}
],
"disable_persistence": [
{
"uri_match": "^/handlers/dev\\.speed",
"disable_session": true
},
{
"uri_match": "^/index\\.asp",
"disable_session": true
}
]
},
"data_connections": {
"session": {
"manager": "ASP4::SessionStateManager",
"cookie_name": "session-id",
"cookie_domain": ".mysite.com",
"session_timeout": 30,
"dsn": "DBI:SQLite:dbname=/tmp/db_asp4",
"username": "",
"password": ""
},
"main": {
"dsn": "DBI:SQLite:dbname=/tmp/db_asp4",
"username": "",
"password": ""
}
}
}
=head1 BUGS
It's possible that some bugs have found their way into this release.
Use RT L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=ASP4> to submit bug reports.
=head1 HOMEPAGE
Please visit the ASP4 homepage at L<http://0x31337.org/code/> to see examples
of ASP4 in action.
=head1 AUTHOR
John Drago <jdrago_999@yahoo.com>
( run in 0.676 second using v1.01-cache-2.11-cpan-39bf76dae61 )