[Catalyst] Access to DBIx schema from outside Catalyst

J. Shirley jshirley at gmail.com
Tue Dec 8 00:37:33 GMT 2009


On Mon, Dec 7, 2009 at 4:21 PM, Greg Matheson <drbean at freeshell.org> wrote:

> On Mon, 07 Dec 2009, J. Shirley wrote:
>
> > On Mon, Dec 7, 2009 at 8:50 AM, Eden Cardim <edencardim at gmail.com>
> wrote:
>
> > > >>>>> "Dermot" =3D=3D Dermot  <paikkos at googlemail.com> writes:
>
> > >    Dermot> If I have a Class outside my Cat App, I can have access to
> > >    Dermot> that via C::Model::Adapator. Is there a method for giving
> > >    Dermot> that external Class access to Catalyst features,
> > >    Dermot> particularly the DBix schema and perhaps the debug and log
> > >    Dermot> methods?
>
> > > Both DBIx::Class::Schema and Catalyst::Log are regular perl classes
> > > and you can use them anywhere in a perl program just like you'd use a=
ny
> > > other class.
>
>
>
> > Or, more verbosely:
>
> > package MyApp::External::Class;
>
> > use Moose;
>
> > has 'schema' =3D>  ( is =3D> 'ro', isa =3D> 'DBIx::Class::Schema', hand=
les =3D> {
> > 'resultset' =3D> 'resultset' } );
> > has 'log'         =3D> ( is =3D> 'ro', isa =3D> 'Catalyst::Log', defaul=
t =3D> sub
> {
> > Catalyst::Log->new } );
> > has 'debug'    =3D> ( is =3D> 'ro', isa =3D> 'Bool' );
> > 1;
>
> > I do things like this (though not with Catalyst::Log) quite frequently,
> and
> > just create a custom type for the schema[1], add a coercion and can pass
> in
> > a array ref to call ->connect:
>
> > my $schema =3D MyApp::External::Class->new( schema =3D> [ $dsn, $user, =
$pass
> ],
> > debug =3D> 1 );
> > $schema->resultset('Foo"); # handles does this.
>
> I've seen Catalyst::Component::InstancePerContext recommended on
> IRC to get the $c context object, but this is more than needed?
>
>
>
>
That would only work if he is using Catalyst, and a Catalyst component.
This is somewhat the other direction.

He wants to access the DBIx::Class schema outside of Catalyst and simply
have access to ->log and ->debug methods.

-J
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/catalyst/attachments/20091207/611aa=
2b6/attachment.htm


More information about the Catalyst mailing list