n and save
it to the database.
=head2 $Config
The ASP4 C<$Config> object is stored in a simple JSON format on disk, and accessible
everywhere within your entire ASP4 application as the global C<$Co
ample project to get things going.
In the C<data_connections.main> section of C<conf/asp4-config.json> you should have
something like this:
...
"main": {
"dsn": "DBI:mysql:d
__PACKAGE__->VARS;
use LWP::UserAgent;
use HTTP::Request::Common;
use HTTP::Date 'time2iso';
use JSON::XS;
use Data::Dumper;
require ASP4;
our $ua;
sub run
{
my ($s, $context) = @_;
my $erro
ndler::Remote - Send your errors someplace else via http.
=head1 SYNOPSIS
In your C<asp4-config.json>:
...
"errors": {
"error_handler": "ASP4::ErrorHandler::Remote",
"post_erro
package ASP4::Error;
use strict;
use warnings 'all';
use ASP4::HTTPContext;
use JSON::XS;
sub new
{
my $class = shift;
my ($err_str, %args);
if( @_ )
{
if( @_ == 1 )
{
$err_s
{stacktrace},
code => $code,
form_data => encode_json($Form) || "{}",
session_data => eval { encode_json(\%session_data) } || "{}",
http_referer => $ENV{HTTP_REFERER},
acktrace
A string - defaults to the value of C<$@>.
=head2 form_data
JSON-encoded C<$Form> object.
=head2 session_data
JSON-encoded C<$Session> object.
=head2 http_referer
Default value is C<$E
d1 NAME
ASP4::ErrorHandler - Default fatal error handler
=head1 SYNOPSIS
In your C<asp4-config.json>:
...
"errors": {
"error_handler": "ASP4::ErrorHandler",
"mail_errors_to":
ixtures.json' )
{
eval { require Data::Properties::JSON };
$test_data = Data::Properties::JSON->new(
properties_file => $config->web->application_root . '/etc/test_fixtures.json'
)
rict;
use warnings 'all';
use Carp 'confess';
use ASP4::ConfigFinder;
use ASP4::ConfigParser;
use JSON::XS;
our $Configs = { };
#====================================================================
$ifh, '<', $path
or die "Cannot open '$path' for reading: $!";
local $/;
my $doc = decode_json( scalar(<$ifh>) );
close($ifh);
(my $where = $path) =~ s/\/conf\/[^\/]+$//;
$Configs->{$
hed on a per-path basis. Paths are full - i.e. C</usr/local/projects/mysite.com/conf/asp4-config.json> -
so there should never be a clash between two different configurations on the
same web server,
g',
png => 'image/png',
bmp => 'image/bmp',
gif => 'image/gif',
json => 'application/x-json',
css => 'text/css',
pdf => 'application/x-pdf',
js => 'text/javas
onse->Redirect("/login/");
}# end if()
}
1;# return true:
Then, in your C<asp4-config.json>:
{
...
"web": {
...
"request_filters": [
{
"uri_match":
use strict;
use warnings 'all';
use base 'ASP4::SessionStateManager';
use Cache::Memcached;
use JSON::XS;
my $memd;
sub new
{
my ($class, $r) = @_;
my $s = bless { }, $class;
my $conn = ASP4
ion_id
{
my ($s, $id) = @_;
my $ref = $memd->get( $id )
or return;
$s = bless decode_json($ref), ref($s) ? ref($s) : $s;
}# end verify_session_id()
*retrieve = \&verify_session_id;
sub
$s->{__lastMod} = time();
$s->sign;
my %clone = %$s;
my $json = encode_json(\%clone);
$memd->set( $s->{SessionID}, $json, $s->{__ttl} );
}# end save()
sub reset
{
my $s = shift;
gNode::Web;
use strict;
use warnings 'all';
use base 'ASP4::ConfigNode';
use Carp 'confess';
use JSON::XS;
sub new
{
my $class = shift;
my $s = $class->SUPER::new( @_ );
$s->{handler_resol
ding: $!";
local $/;
my $json = eval { decode_json( scalar(<$ifh>) ) }
or confess "Error parsing '$item->{include_routes}': $@";
ref($json) eq 'ARRAY'
or confess "Fil
e '$item->{include_routes}' should be an arrayref but it's a '@{[ ref($json) ]}' instead.";
@$json;
} : $_
} @original;
my $router = Router::Generic->new();
map { $router->add_route
to whatever you set your config->data_connections->session->cookie_domain to
in your asp4-config.json. Otherwise defaults to C<$ENV{HTTP_HOST}>.
You can override the defaults by passing in a domain
$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": {
"po
ConfigFinder;
use strict;
use warnings 'all';
use Cwd 'fastcwd';
our $CONFIGFILE = 'asp4-config.json';
sub config_path
{
my $path = $CONFIGFILE;
my $root = do { ($ENV{REMOTE_ADDR} || '') eq