requires 'Syntax::Keyword::Gather';
requires 'Plack';
requires 'Moo';
+requires 'warnings::illegalproto';
WriteAll;
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 {
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;
sub _default_config { () }
-sub config {
- shift->{config};
-}
-
sub _construct_response_filter {
my ($class, $code) = @_;
my $self = do { no strict 'refs'; ${"${class}::self"} };
+++ /dev/null
-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');