X-Git-Url: https://git.decadent.org.uk/gitweb/?a=blobdiff_plain;f=lib%2FMaypole.pm;h=29c8917d81022b5ed699c76c8f0b196677fd6d3f;hb=5f530b5f17106319faa2f437a567332c86bf6a2c;hp=4a5201127794ab8c8936cd322eeeb62de83395b1;hpb=5ba93a09518403ae28e8a71b5299e2458a6dfa0b;p=maypole.git diff --git a/lib/Maypole.pm b/lib/Maypole.pm index 4a52011..29c8917 100644 --- a/lib/Maypole.pm +++ b/lib/Maypole.pm @@ -4,13 +4,14 @@ use attributes (); use UNIVERSAL::require; use strict; use warnings; +use Maypole::Config; our $VERSION = "1.8"; __PACKAGE__->mk_classdata($_) for qw( config init_done view_object ); __PACKAGE__->mk_accessors( qw( ar params query objects model_class args action template ) ); -__PACKAGE__->config( {} ); +__PACKAGE__->config( Maypole::Config->new() ); __PACKAGE__->init_done(0); use Maypole::Constants; @@ -27,26 +28,26 @@ sub setup { sub { Maypole::handler( $calling_class, @_ ) }; } my $config = $calling_class->config; - $config->{model} ||= "Maypole::Model::CDBI"; - $config->{model}->require; - die "Couldn't load the model class $config->{model}: $@" if $@; - $config->{model}->setup_database( $config, $calling_class, @_ ); - for my $subclass ( @{ $config->{classes} } ) { + $config->model || $config->model("Maypole::Model::CDBI"); + $config->model->require; + die "Couldn't load the model class $config->model: $@" if $@; + $config->model->setup_database( $config, $calling_class, @_ ); + for my $subclass ( @{ $config->classes } ) { no strict 'refs'; - unshift @{ $subclass . "::ISA" }, $config->{model}; - $config->{model}->adopt($subclass) - if $config->{model}->can("adopt"); + unshift @{ $subclass . "::ISA" }, $config->model; + $config->model->adopt($subclass) + if $config->model->can("adopt"); } } sub init { my $class = shift; my $config = $class->config; - $config->{view} ||= "Maypole::View::TT"; - $config->{view}->require; - die "Couldn't load the view class $config->{view}: $@" if $@; - $config->{display_tables} ||= [ @{ $class->config->{tables} } ]; - $class->view_object( $class->config->{view}->new ); + $config->view || $config->view("Maypole::View::TT"); + $config->view->require; + die "Couldn't load the view class ".$config->view.": $@" if $@; + $config->display_tables || $config->display_tables([ $class->config->tables ]); + $class->view_object( $class->config->view->new ); $class->init_done(1); } @@ -67,7 +68,7 @@ sub handler { sub handler_guts { my $r = shift; - $r->model_class( $r->config->{model}->class_of( $r, $r->{table} ) ); + $r->model_class( $r->config->model->class_of( $r, $r->{table} ) ); my $applicable = $r->is_applicable; unless ( $applicable == OK ) { @@ -122,13 +123,13 @@ sub handler_guts { sub is_applicable { my $self = shift; my $config = $self->config; - $config->{ok_tables} ||= $config->{display_tables}; - $config->{ok_tables} = { map { $_ => 1 } @{ $config->{ok_tables} } } - if ref $config->{ok_tables} eq "ARRAY"; + $config->ok_tables || $config->ok_tables($config->display_tables); + $config->ok_tables ({ map { $_ => 1 } @{ $config->ok_tables } }) + if ref $config->ok_tables eq "ARRAY"; warn "We don't have that table ($self->{table})" if $self->debug - and not $config->{ok_tables}{ $self->{table} }; - return DECLINED() unless exists $config->{ok_tables}{ $self->{table} }; + and not $config->ok_tables->{ $self->{table} }; + return DECLINED() unless exists $config->ok_tables->{ $self->{table} }; # Does the action method exist? my $cv = $self->model_class->can( $self->{action} ); @@ -220,7 +221,7 @@ this: package ProductDatabase; use base 'Apache::MVC'; __PACKAGE__->set_database("dbi:mysql:products"); - ProductDatabase->config->{uri_base} = "http://your.site/catalogue/"; + ProductDatabase->config->uri_base = "http://your.site/catalogue/"; ProductDatabase::Product->has_a("category" => ProductDatabase::Category); # ... @@ -278,7 +279,7 @@ subclass the model class, and configure your class slightly differently: Then your top-level application package should change the model class: (Before calling C) - ProductDatabase->config->{model} = "ProductDatabase::Model"; + ProductDatabase->config->model("ProductDatabase::Model"); (The C<:Exported> attribute means that the method can be called via the URL C/supersearch/...>.)