X-Git-Url: https://git.decadent.org.uk/gitweb/?a=blobdiff_plain;f=lib%2FApache%2FMVC.pm;h=467f0f97b83ffb5f01c2d55b59a3bb191c3513f8;hb=d635ca733a7199c4f9893e8d5a50e96a1295f092;hp=25a8adb0c6dc9d47259624b433d5c4a3fa20e43a;hpb=fd44a844f551caa56dfaaacb4ba2c6e69d9a4157;p=maypole.git diff --git a/lib/Apache/MVC.pm b/lib/Apache/MVC.pm index 25a8adb..467f0f9 100644 --- a/lib/Apache/MVC.pm +++ b/lib/Apache/MVC.pm @@ -32,28 +32,29 @@ sub config { sub set_database { my ($calling_class, $dsn) = @_; $calling_class = ref $calling_class if ref $calling_class; - $calling_class->config->{dsn} = $dsn; - $calling_class->config->{loader} = Class::DBI::Loader->new( + my $config = $calling_class->config; + $config->{model} ||= "Apache::MVC::Model::CDBI"; + $config->{model}->require; + $config->{dsn} = $dsn; + $config->{loader} = Class::DBI::Loader->new( namespace => $calling_class, dsn => $dsn ); + $config->{classes} = [ $config->{loader}->classes ]; + for my $subclass (@{$config->{classes}}) { + no strict 'refs'; + unshift @{$subclass."::ISA"}, $config->{model}; + $config->{model}->adopt($subclass) + if $config->{model}->can("adopt"); + } } sub init { my $class = shift; my $config = $class->config; - $config->{model} ||= "Apache::MVC::Model::CDBI"; $config->{view} ||= "Apache::MVC::View::TT"; - $config->{model}->require; $config->{view}->require; - $config->{classes} = [ $class->config->{loader}->classes ]; $config->{display_tables} ||= [ $class->config->{loader}->tables ]; - for my $subclass (@{$config->{classes}}) { - no strict 'refs'; - push @{$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); @@ -105,17 +106,22 @@ sub parse_location { sub is_applicable { my $self = shift; my $config = $self->config; - my %ok = map {$_ => 1} @{$config->{display_tables}}; - return DECLINED() unless exists $ok{$self->{table}}; + $config->{ok_tables} = {map {$_ => 1} @{$config->{display_tables}}}; + warn "We don't have that table ($self->{table})" + unless $config->{ok_tables}{$self->{table}}; + return DECLINED() unless exists $config->{ok_tables}{$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(); }