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::Pluggable;
|
||||
use WebGUI::Paths;
|
||||
use WebGUI::Types;
|
||||
use Try::Tiny;
|
||||
|
||||
extends 'Plack::Component';
|
||||
|
|
@ -48,18 +49,10 @@ These subroutines are available from this package:
|
|||
=cut
|
||||
|
||||
has config => (
|
||||
is => 'rw',
|
||||
isa => 'WebGUI::Config',
|
||||
);
|
||||
has site => (
|
||||
is => 'ro',
|
||||
isa => 'Str',
|
||||
required => 1,
|
||||
trigger => sub {
|
||||
my ($self, $site) = @_;
|
||||
my $config = WebGUI::Config->new( $site );
|
||||
$self->config($config);
|
||||
},
|
||||
isa => 'WebGUI::Type::Config',
|
||||
coerce => 1,
|
||||
);
|
||||
|
||||
=head2 call( $env )
|
||||
|
|
|
|||
|
|
@ -45,6 +45,17 @@ Similarly, if an undef value is applied, it is coerced into an empty arrayref.
|
|||
|
||||
=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'
|
||||
=> as 'ArrayRef'
|
||||
;
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ use HTTP::Request::Common;
|
|||
use Test::More tests => 9;
|
||||
use HTTP::Exception;
|
||||
|
||||
my $wg = WebGUI->new(site => WebGUI::Test->file);
|
||||
my $wg = WebGUI->new(config => WebGUI::Test->config);
|
||||
|
||||
my $regular_app = builder {
|
||||
enable '+WebGUI::Middleware::Session', config => $wg->config;
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ use Plack::App::File;
|
|||
use WebGUI;
|
||||
|
||||
builder {
|
||||
my $wg = WebGUI->new( site => $ENV{WEBGUI_CONFIG} );
|
||||
my $wg = WebGUI->new( config => $ENV{WEBGUI_CONFIG} );
|
||||
my $config = $wg->config;
|
||||
|
||||
enable 'Log4perl', category => $config->getFilename, conf => WebGUI::Paths->logConfig;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue