add type with coersion for WebGUI::Config
This commit is contained in:
parent
19c2c5fa1c
commit
8bfa022441
4 changed files with 16 additions and 12 deletions
|
|
@ -25,6 +25,7 @@ use MooseX::NonMoose;
|
||||||
use WebGUI::Config;
|
use WebGUI::Config;
|
||||||
use WebGUI::Pluggable;
|
use WebGUI::Pluggable;
|
||||||
use WebGUI::Paths;
|
use WebGUI::Paths;
|
||||||
|
use WebGUI::Types;
|
||||||
use Try::Tiny;
|
use Try::Tiny;
|
||||||
|
|
||||||
extends 'Plack::Component';
|
extends 'Plack::Component';
|
||||||
|
|
@ -48,18 +49,10 @@ These subroutines are available from this package:
|
||||||
=cut
|
=cut
|
||||||
|
|
||||||
has config => (
|
has config => (
|
||||||
is => 'rw',
|
|
||||||
isa => 'WebGUI::Config',
|
|
||||||
);
|
|
||||||
has site => (
|
|
||||||
is => 'ro',
|
is => 'ro',
|
||||||
isa => 'Str',
|
|
||||||
required => 1,
|
required => 1,
|
||||||
trigger => sub {
|
isa => 'WebGUI::Type::Config',
|
||||||
my ($self, $site) = @_;
|
coerce => 1,
|
||||||
my $config = WebGUI::Config->new( $site );
|
|
||||||
$self->config($config);
|
|
||||||
},
|
|
||||||
);
|
);
|
||||||
|
|
||||||
=head2 call( $env )
|
=head2 call( $env )
|
||||||
|
|
|
||||||
|
|
@ -45,6 +45,17 @@ Similarly, if an undef value is applied, it is coerced into an empty arrayref.
|
||||||
|
|
||||||
=cut
|
=cut
|
||||||
|
|
||||||
|
subtype 'WebGUI::Type::Config'
|
||||||
|
=> as class_type('WebGUI::Config');
|
||||||
|
|
||||||
|
coerce 'WebGUI::Type::Config'
|
||||||
|
=> from Str
|
||||||
|
=> via {
|
||||||
|
require WebGUI::Config;
|
||||||
|
WebGUI::Config->new($_)
|
||||||
|
}
|
||||||
|
;
|
||||||
|
|
||||||
subtype 'WebGUI::Type::JSONArray'
|
subtype 'WebGUI::Type::JSONArray'
|
||||||
=> as 'ArrayRef'
|
=> as 'ArrayRef'
|
||||||
;
|
;
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ use HTTP::Request::Common;
|
||||||
use Test::More tests => 9;
|
use Test::More tests => 9;
|
||||||
use HTTP::Exception;
|
use HTTP::Exception;
|
||||||
|
|
||||||
my $wg = WebGUI->new(site => WebGUI::Test->file);
|
my $wg = WebGUI->new(config => WebGUI::Test->config);
|
||||||
|
|
||||||
my $regular_app = builder {
|
my $regular_app = builder {
|
||||||
enable '+WebGUI::Middleware::Session', config => $wg->config;
|
enable '+WebGUI::Middleware::Session', config => $wg->config;
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ use Plack::App::File;
|
||||||
use WebGUI;
|
use WebGUI;
|
||||||
|
|
||||||
builder {
|
builder {
|
||||||
my $wg = WebGUI->new( site => $ENV{WEBGUI_CONFIG} );
|
my $wg = WebGUI->new( config => $ENV{WEBGUI_CONFIG} );
|
||||||
my $config = $wg->config;
|
my $config = $wg->config;
|
||||||
|
|
||||||
enable 'Log4perl', category => $config->getFilename, conf => WebGUI::Paths->logConfig;
|
enable 'Log4perl', category => $config->getFilename, conf => WebGUI::Paths->logConfig;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue