switch to Moo
Matt S Trout [Sat, 20 Nov 2010 19:56:41 +0000 (19:56 +0000)]
Makefile.PL
lib/Web/Simple.pm
lib/Web/Simple/Application.pm
t/buildall.t [deleted file]

index 5159ab5..0a801e5 100644 (file)
@@ -6,5 +6,6 @@ all_from 'lib/Web/Simple.pm';
 requires 'Syntax::Keyword::Gather';
 requires 'Plack';
 requires 'Moo';
+requires 'warnings::illegalproto';
 
 WriteAll;
index 960fc01..d862373 100644 (file)
@@ -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 {
index a6ada44..91d20a7 100644 (file)
@@ -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 (file)
index 8d676ab..0000000
+++ /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');