Re: [Maypole-dev] Re: [Maypole] multiple Maypole applications

From: David R. Baird (dave at riverside-cms.co.uk)
Date: Tue Aug 17 2004 - 22:09:38 BST


On 17 Aug 2004 at 17:11, Simon Flack wrote:

> On Tue, 17 Aug 2004 15:42:21 +0100, David R. Baird wrote
> > On 17 Aug 2004 at 13:46, Simon Flack wrote:
> [snip]
> > > Are you trying to use a single controller for multiple apps?
> >
> > My Maypole drivers inherit from a generic driver, which passes on the
> > application-specific class name in the call to setup:
> >
> > package ISellIt;
> > use base 'Generic::MaypoleDriver';
> > __PACKAGE__->setup_driver;
> > 1;
> >
> > package Generic::MaypoleDriver;
> > use base 'MasonX::Maypole'; # inherits from Maypole
> >
> > sub setup_driver {
> > my ($class) = @_;
> >
> > # application config object
> > my $cfg = get_cfg();
> >
> > my $dsn = $cfg->dsn;
> >
> > $class->setup( $dsn, $user, $pass );
> >
> > $class->config->{ application_name } = $cfg->AppName;
> > $class->config->{ uri_base } = $cfg->UriBase;
> > $class->config->{ rows_per_page } = $cfg->RowsPerPage;
> > $class->config->{ view } = 'Maypole::View::Base';
> > }
> >
> > Is this what you mean by a single controller? Do you see any
> > problems with this setup? Specifically, the $calling_class in
> > Maypole::setup will be the application namespace (ISellIt) which
> > should work as advertised with Class::Data::Inheritable.
>
> I see. Each new application is modifying the base class's config(). I think
> you just need to call '$class->config({})' in
> Generic::MaypoleDriver->driver_setup() before modifying the config, to make
> sure that it is not inheriting the 'config' from Maypole.pm.
>
> Of course, I might be missing somethign more fundamental.
>
> SF

Without the patch, you are correct, each new application modifies the
base class's config, despite being called through different class
names. I think that's a bug, and short-circuits
Class::Data::Inheritable, but I've only played with Maypole a little
bit so far so my use cases may not be representative.

You're right, the config can be isolated to the correct package by
sending an empty hashref in the driver, this is what I have now and
it works fine:

package BeerDB;
__PACKAGE__->config( {} );
# get $dsn etc
__PACKAGE__->setup( $dsn, $user, $pass );
# add config stuff, set up relationships etc.
1;

package ISellIt;
__PACKAGE__->config( {} );
# get $dsn etc
__PACKAGE__->setup( $dsn, $user, $pass );
# add config stuff, set up relationships etc.
1;

I think this is the right way to address the problem, rather than by
patching Maypole::setup. Any calls to __PACKAGE__->config before
calling setup will be accessing/modifying the base config. The patch
would mean that any calls _after_ setup would access the derived
config. That's not intuitive. Better just to highlight the issue in
the docs.

d.

-- 
Dr. David R. Baird
Riverside Content Management Systems
dave at riverside-cms.co.uk
http://www.riverside-cms.co.uk

_______________________________________________ maypole-dev mailing list maypole-dev at lists.netthink.co.uk http://lists.netthink.co.uk/listinfo/maypole-dev



This archive was generated by hypermail 2.1.3 : Thu Feb 24 2005 - 22:25:56 GMT