From: Matt S Trout Date: Sat, 20 Nov 2010 19:56:41 +0000 (+0000) Subject: switch to Moo X-Git-Tag: v0.005~30 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=8bd060f4f069c0aafac9d705540d4033b7c5cd19;hp=4ed4fb42c2a30a541a4eae477c7ad35a81b39c30;p=catagits%2FWeb-Simple.git switch to Moo --- diff --git a/Makefile.PL b/Makefile.PL index 5159ab5..0a801e5 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -6,5 +6,6 @@ all_from 'lib/Web/Simple.pm'; requires 'Syntax::Keyword::Gather'; requires 'Plack'; requires 'Moo'; +requires 'warnings::illegalproto'; WriteAll; diff --git a/lib/Web/Simple.pm b/lib/Web/Simple.pm index 960fc01..d862373 100644 --- a/lib/Web/Simple.pm +++ b/lib/Web/Simple.pm @@ -1,29 +1,16 @@ package Web::Simple; -use strict; -use warnings FATAL => 'all'; +use strictures 1; use 5.008; +use warnings::illegalproto (); our $VERSION = '0.004'; -sub setup_all_strictures { - strict->import; - warnings->import(FATAL => 'all'); -} - -sub setup_dispatch_strictures { - setup_all_strictures(); - warnings->unimport('syntax'); - warnings->import(FATAL => qw( - ambiguous bareword digit parenthesis precedence printf - prototype qw reserved semicolon - )); -} - sub import { - setup_dispatch_strictures(); my ($class, $app_package) = @_; $class->_export_into($app_package||caller); + eval "package $class; use Moo;"; + warnings::illegalproto->unimport; } sub _export_into { diff --git a/lib/Web/Simple/Application.pm b/lib/Web/Simple/Application.pm index a6ada44..91d20a7 100644 --- a/lib/Web/Simple/Application.pm +++ b/lib/Web/Simple/Application.pm @@ -1,34 +1,13 @@ package Web::Simple::Application; -use strict; -use warnings FATAL => 'all'; - -sub new { - my ($class, $data) = @_; - my $config = { $class->_default_config, %{($data||{})->{config}||{}} }; - my $new = bless({ config => $config }, $class); - $new->BUILDALL($data); - $new; -} +use Moo; -sub BUILDALL { - my ($self, $data) = @_; - my $targ = ref($self); - my @targ; - while ($targ->isa(__PACKAGE__) and $targ ne __PACKAGE__) { - push(@targ, "${targ}::BUILD") - if do { - no strict 'refs'; no warnings 'once'; - defined *{"${targ}::BUILD"}{CODE} - }; - my @targ_isa = do { no strict 'refs'; @{"${targ}::ISA"} }; - die "${targ} uses Multiple Inheritance: ISA is: ".join ', ', @targ_isa - if @targ_isa > 1; - $targ = $targ_isa[0]; - } - $self->$_($data) for reverse @targ; - return; -} +has 'config' => (is => 'ro', trigger => sub { + my ($self, $value) = @_; + my %default = $self->_default_config; + my @not = grep !exists $value->{$_}, keys %default; + @{$value}{@not} = @default{@not}; +}); sub _setup_default_config { my $class = shift; @@ -47,10 +26,6 @@ sub _setup_default_config { sub _default_config { () } -sub config { - shift->{config}; -} - sub _construct_response_filter { my ($class, $code) = @_; my $self = do { no strict 'refs'; ${"${class}::self"} }; diff --git a/t/buildall.t b/t/buildall.t deleted file mode 100644 index 8d676ab..0000000 --- a/t/buildall.t +++ /dev/null @@ -1,23 +0,0 @@ -use Test::More 'no_plan'; - -use Web::Simple 'Fork'; - -my @run; - -sub Fork::BUILD { push @run, [ FORK => $_[1] ] } - -@Knife::ISA = 'Fork'; - -@Spoon::ISA = 'Knife'; - -sub Spoon::BUILD { push @run, [ SPOON => $_[1] ] } - -bless({}, 'Fork')->BUILDALL('data'); - -is_deeply(\@run, [ [ FORK => 'data' ] ], 'Single class ok'); - -@run = (); - -bless({}, 'Spoon')->BUILDALL('data'); - -is_deeply(\@run, [ [ FORK => 'data' ], [ SPOON => 'data' ] ], 'Subclass ok');