Re: Casting around for ideas...

[prev] [thread] [next] [Date index for 2005/05/23]

From: Nic Gibson
Subject: Re: Casting around for ideas...
Date: 09:16 on 23 May 2005
On May 22, 2005, at 20:02, Matt S Trout wrote:

> On Sun, May 22, 2005 at 07:40:45PM +0100, Nic Gibson wrote:
>
>> OK. I read my own email again this morning (don't write email at 1am)
>> and it really
>> doesn't make a lot of sense.
>>
>> An example, I have a package Foo. I need to use this in several
>> places, all slightly
>> modified. Therefore, I create Foo::Bar. This will maybe have a new
>> column.
>>
>> However, I seem to be having a problem using Foo::Bar - I get errors
>> that appear
>> to show that the __grouper attribute of Foo::Bar is empty - not
>> getting the columns.
>> from Foo. That may be caused by something else I do, not sure what.
>>
>
> I think it's down to the way Class::Data::Inheritable works. Maybe try
>
> __PACKAGE__->__grouper(__PACKAGE__->__grouper)
>
> first or something.
>
I think you are right. However, I suspect I"m doing something to  
exacerbate this. Investigation beckons. Time to reread the source for  
Class::Data::Inheritable I think.

>
>> The other part comes down to:
>>
>>     Imagine that I have the above working.
>>     The conventional way to set the DBI connection is via a shared
>> base.
>>
>>     I have the following packages.
>>
>>         Foo::Bar
>>         MyApp::One
>>         MyApp::Two
>>
>> Now, Foo::Bar is derived from Foo. MyApp::One and MyApp::Two are
>> derived from
>> MyApp::Base. Foo is a generic package and doesn't have a base class
>> that defines
>> a connection in the same way.
>>
>
> Well, my way of doing it would be to get something suitable onto  
> the head
> of the packages' @INC somehow - say
>
> package Foo::Bar;
>
> use base qw/Foo CurrentConnection/;
>
> but have CurrentConnection *not* do ->connection. Then in your user  
> code you
> can do
>
> use CurrentConnection;
>
> CurrentConnection->connection(...);
>
> use Foo::Bar;

This has potential although I can see it causing issues in, say  
mod_perl  environments. Our applications tend to work in both web and  
cron job environments - the front end in the web and cron jobs doing  
things that modify the file system/send mail/etc. The approach I've  
been mulling over  has similarities to this but needs to instantiate  
something rather than use a class method - otherwise two web  
applications running in the same apache child will get the same  
database connection. Must get this worked out :)

>
> <continue as normal>
>
> Other similar tricks will work - you could even find all your table  
> packages
> and do an unshift('Connection::Class', @{"${package}::INC"});

Never liked that approach. it feels 'wrong' somehow.
However, Maypole does it, iirc.

cheers

nic
>
> -- 
>      Matt S Trout           Website: http://www.shadowcatsystems.co.uk
>   Technical Director        E-mail:  mst (at) shadowcatsystems.co.uk
> Shadowcat Systems Ltd.
>
>

(message missing)

Casting around for ideas...
Nic Gibson 00:08 on 22 May 2005

Re: Casting around for ideas...
Jay Strauss 14:30 on 22 May 2005

Re: Casting around for ideas...
Nic Gibson 18:40 on 22 May 2005

Re: Casting around for ideas...
Matt S Trout 19:02 on 22 May 2005

Re: Casting around for ideas...
Nic Gibson 09:16 on 23 May 2005

Re: Casting around for ideas...
Tony Bowden 09:24 on 23 May 2005

Re: Casting around for ideas...
Matt S Trout 17:04 on 23 May 2005

Re: Casting around for ideas...
Nic Gibson 09:29 on 23 May 2005

Generated at 15:51 on 25 May 2005 by mariachi v0.52