[Dbix-class] question about connect from manual

Eden Cardim edencardim at gmail.com
Sun Feb 20 14:16:43 GMT 2011


>>>>> "Jim" == Jim Green <student.northwestern at gmail.com> writes:

    Jim> Hello!
    Jim> I came from rose::db background so I wonder if there is way

    Jim> to avoid this to in using a
    Jim> my $other_schema = My::Schema->connect( $dsn, $user, $password, $attrs );

    Jim> in rose::db it hides all connection details in DB.pm so I don't need
    Jim> to worry about connection details each time I access a table.
    Jim> I just need to use My::TableName to use the table.

Why don't you keep a pre-connected $schema object within the scope of
your table accesses instead? DBIC will automatically reconnect if the
connection is dropped between table accesses.

In any case, does

--8<---------------cut here---------------start------------->8---
package My::Schema;

[...]

sub autoconnect { shift->connect($dsn, $user, $password, $attrs) }

[...]

my $schema = My::Schema->autoconnect;
--8<---------------cut here---------------end--------------->8---

solve the problem for you? I'd still recommend the former aproach.

-- 
Eden Cardim
Software Engineer
Shadowcat Systems Ltd.
http://www.shadowcat.co.uk
http://blog.edencardim.com



More information about the DBIx-Class mailing list