]> git.decadent.org.uk Git - maypole.git/blobdiff - lib/Apache/MVC.pm
General restructuring, and a delete method which doesn't quite work yet.
[maypole.git] / lib / Apache / MVC.pm
index 95e3dd3f131b4a3791348cd636e8ba88b2f0ffac..8ed51bf1c9108a353b0bb2f05750951ab22d5188 100644 (file)
@@ -7,13 +7,21 @@ use Apache::Constants ":common";
 use strict;
 use warnings;
 our $VERSION = "1.0";
-
 __PACKAGE__->mk_classdata($_) for qw( _config init_done view_object );
 __PACKAGE__->mk_accessors ( qw( config ar params objects model_class
 args action template ));
 __PACKAGE__->config({});
 __PACKAGE__->init_done(0);
 
+
+sub import {
+    my $real = shift;
+    if ($real ne "Apache::MVC") {
+        no strict 'refs';
+        *{$real."::handler"} = sub { Apache::MVC::handler($real, @_) };
+    }
+}
+
 # This is really dirty.
 sub config {
     my $self = shift;
@@ -42,7 +50,9 @@ sub init {
     $config->{display_tables} ||= [ $class->config->{loader}->tables ];
     for my $subclass (@{$config->{classes}}) {
         no strict 'refs';
-        push @{$subclass."::ISA"}, $class->config->{model};
+        unshift @{$subclass."::ISA"}, $class->config->{model};
+        $config->{model}->adopt($subclass)
+           if $config->{model}->can("adopt");
     }
     $class->view_object($class->config->{view}->new);
     $class->init_done(1);
@@ -56,18 +66,19 @@ sub class_of {
 
 sub handler {
     # See Apache::MVC::Workflow before trying to understand this.
-    # XXX This needs to work with Apache without method handlers
     my $class = shift;
     $class->init unless $class->init_done;
     my $r = bless { config => $class->config }, $class;
     $r->get_request();
     $r->parse_location();
+
     $r->model_class($r->class_of($r->{table}));
     my $status = $r->is_applicable;
     return $status unless $status == OK;
     $status = $r->call_authenticate;
     return $status unless $status == OK;
     $r->additional_data();
+    
     $r->model_class->process($r);
     $r->view_object->process($r);
     return $r; # For debugging.
@@ -81,29 +92,35 @@ sub get_request {
 
 sub parse_location {
     my $self = shift;
-    my @pi = split /\//, $self->{ar}->uri();
+    my $uri = $self->{ar}->path_info();
+    my @pi = split /\//, $uri;
     shift @pi while @pi and !$pi[0];
     $self->{table} = shift @pi;
     $self->{action} = shift @pi;
     $self->{args} = \@pi;
 
-    $self->{params} = $self->{ar}->content;
+    $self->{params} = { $self->{ar}->content };
 }
 
 sub is_applicable {
     my $self = shift;
     my $config = $self->config;
     my %ok = map {$_ => 1} @{$config->{display_tables}};
+    warn "We don't have that table ($self->{table})"
+        unless $ok{$self->{table}};
     return DECLINED() unless exists $ok{$self->{table}};
 
     # Does the action method exist?
+    # XXX We should set the method class to the class for the table
     my $cv = $self->model_class->can($self->{action});
+    warn "We don't have that action ($self->{action})" unless $cv;
     return DECLINED() unless $cv;
 
     # Is it exported?
     $self->{method_attribs} = join " ", attributes::get($cv);
+    do { warn "$self->{action} not exported";
     return DECLINED() 
-     unless $self->{method_attribs} =~ /\bExported\b/i;
+     unless $self->{method_attribs} =~ /\bExported\b/i;
     return OK();
 }