Skip to content

Commit

Permalink
add type with coersion for WebGUI::Config
Browse files Browse the repository at this point in the history
  • Loading branch information
haarg committed Jun 17, 2010
1 parent 19c2c5f commit 8bfa022
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 12 deletions.
13 changes: 3 additions & 10 deletions lib/WebGUI.pm
Expand Up @@ -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';
Expand All @@ -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 )
Expand Down
11 changes: 11 additions & 0 deletions lib/WebGUI/Types.pm
Expand Up @@ -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'
;
Expand Down
2 changes: 1 addition & 1 deletion t/Exception/app.t
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion var/site.psgi
Expand Up @@ -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;
Expand Down

0 comments on commit 8bfa022

Please sign in to comment.