skeleton BUILDALL support
[catagits/Web-Simple.git] / lib / Web / Simple / Application.pm
index 70339fa..c115e6e 100644 (file)
@@ -61,7 +61,25 @@ use warnings FATAL => 'all';
 sub new {
   my ($class, $data) = @_;
   my $config = { $class->_default_config, %{($data||{})->{config}||{}} };
-  bless({ config => $config }, $class);
+  my $new = bless({ config => $config }, $class);
+  $new->BUILDALL($data);
+  $new;
+}
+
+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'; 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;
 }
 
 sub _setup_default_config {
@@ -171,7 +189,7 @@ sub _build_dispatcher_from_spec {
   my $proto = prototype $spec;
   my $parser = $class->_build_dispatch_parser;
   my $matcher = (
-    defined($proto)
+    defined($proto) && length($proto)
       ? $parser->parse_dispatch_specification($proto)
       : undef
   );