On Sat, 2005-10-22 at 13:39 +0100, David Baird wrote:
> On 10/22/05, Peter Speltz <[EMAIL PROTECTED]> wrote:
> > On 10/21/05, David Baird <[EMAIL PROTECTED]> wrote:
> >
> > > How about renaming setup() as setup_model(). The new setup() would
> > > then just call setup_model(). So setup() becomes the official hook for
> > > plugin initialisation, and setup_model() for model initialisation.
> > > Then you can override setup_model() to do things your way.
> > >
> >
> > So you would just override various hooks called in setup and never
> > need to override setup unless you were doing something very out of the
> > norm? I like the sound of that.
> >
>
> Yes. In fact setup() would just be
>
> sub setup
> {
> my $class = shift;
>
> $class->setup_model(@_);
> }
>
> We could maybe break setup_model() into a couple of sub-hooks, but I
> think anyone who needs to override setup_model() should understand the
> framework well enough to know what bits to replicate and what bits to
> modify in their own setup_model().
OK. I tried this and it does mean that I can just override setup_model
in my driver. That's good! But doesn't it leave a couple of issues
unresolved?:
-1- plugin writers define their own version of setup, but within it they
still have to call NEXT::DISTINCT::setup. I'd prefer to see a solution
where they just define a naive setup method that does their own
initialization and then have the framework (specifically, the plugin
loading code) worry about making sure those methods get called. If we
give the new method a new name (setup_plugin?) it should be backwards
compatible.
-2- I still think the code in Maypole::model_setup is really model code,
not controller code. I agree that moving it all to Maypole::Model::Base
is wrong; I suggest Maypole::Model::CDBI or Maypole::Model::MyModel as
well. Something like (untested!):
In Maypole::setup:
Maypole::Model::Base->setup_model(@_);
In Maypole:Model::Base:
sub setup_model {
my $class = shift;
my $calling_class = shift;
$calling_class = ref $calling_class if ref $calling_class;
my $config = $calling_class->config;
my $model = $config->model ||
$config->model("Maypole::Model::CDBI");
$model->require;
die "Couldn't load the model class $model: $@" if $@;
$model->setup_model($calling_class, @_);
}
In Maypole::Model::CDBI:
sub setup_model {
my $class = shift;
my $calling_class = shift;
my $config = $calling_class->config;
... the rest of the existing Maypole::setup code goes here
}
... and in Maypole::Model::MyModel, I just need to define setup_model
differently.
Or am I missing something here?
Cheers, Dave
-------------------------------------------------------
This SF.Net email is sponsored by the JBoss Inc.
Get Certified Today * Register for a JBoss Training Course
Free Certification Exam for All Training Attendees Through End of 2005
Visit http://www.jboss.com/services/certification for more information
_______________________________________________
Maypole-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/maypole-devel