Using class::dbi::factory with multiple table classes in a single file
[prev]
[thread]
[next]
[Date index for 2005/04/05]
This is a multi-part message in MIME format.
------=_NextPart_000_0022_01C539E8.8038A900
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
Hi--
Is there a way to have the class::dbi subclass definitions all in =
the same file and use class::dbi::factory?
If I place each subclass in its own file, factory works fine. If I =
collect them all into a single pm file, I get an error when I try to get =
the colums
my @columns =3D $WebCams->columns ('assay');
and the message is:
failed to load class 'Assay': Can't locate Assay.pm in @INC
The same aggregate pm file works fine without the factory. If I =
create a separate file for Assay and reference it (use Assay;) in my =
code, Factory works fine. If I delete the reference to Assay, it still =
works (at least it can get the column definitions)?!
Sample code is shown below.
Thanks,
Barry
ps The following also does not work:
$WebCams->use_classes (qw/WebCamsDb::Assay WebCamsDb::Results =
WebCamsDb::Experiment/);
my @columns =3D $WebCams->columns (lc('WebCamsDb::assay'));
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
(File WebCamsDb.pm)
#!c:/perl/bin/perl
package WebCamsDb;
use strict; use warnings;
#------------------------------------------------------------------------=
-----
{package WebCams_Server;
use strict; use warnings;
use lib 'C:/Development/Perl/database';
use base qw(Class::DBI);
sub MODULE_NAME { __PACKAGE__ }
sub class_title {shift->table}
sub class_plural {shift->table}
sub class_description {shift->table}
1;}# end Package WebCams_Server
#------------------------------------------------------------------------=
-------------------------------------------------------------------------=
------{package Assay;
use strict;
use warnings;
use base 'WebCams_Server';
__PACKAGE__->table (__PACKAGE__);
__PACKAGE__->columns(All =3D> qw/ name description executable comments =
timestamp /);
1;}
#------------------------------------------------------------------------=
-------------------------------------------------------------------------=
------{package Results;
use strict; use warnings;
use base 'WebCams_Server';
__PACKAGE__->table (__PACKAGE__);
__PACKAGE__->columns(All =3D> qw/ id seq_id exp_run value timestamp /);
1;}
#=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D
(File try_factory.pl)
use strict; use warnings;
use lib "c:/development/perl/lib/";
use WebCamsDb;
use Class::DBI::Factory;
my $WebCams =3D Class::DBI::Factory->new;
$WebCams->set_db ({db_type =3D> 'mysql',
db_name =3D> 'WebCams',
db_username =3D> $name,
db_password =3D> $pw,
});
$WebCams->use_classes (qw/Assay Results Experiment/);
my $table =3D 'Assay';
my @columns =3D $WebCams->columns (lc($table));
#=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D
(File Assay.pm)
package Assay;
use strict; use warnings;
use lib "c:/development/perl/lib/";
use base 'WebCams_Server';
__PACKAGE__->table (__PACKAGE__);
__PACKAGE__->columns(All =3D> qw/ name description executable comments =
timestamp /);
1;
------=_NextPart_000_0022_01C539E8.8038A900
Content-Type: text/html;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-1">
<META content=3D"MSHTML 6.00.2900.2604" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>Hi--</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2> Is there a way to =
have the=20
class::dbi subclass definitions all in the same file and use=20
class::dbi::factory?</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>If I place each subclass in its own =
file, factory=20
works fine. If I collect them all into a single pm file, I get an error =
when I=20
try to get the colums</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2> my @columns =3D=20
$WebCams->columns ('assay');<BR></FONT></DIV>
<DIV><FONT face=3DArial size=3D2>and the message is:</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2> failed to load class =
'Assay':=20
Can't locate Assay.pm in @INC</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2> The same aggregate =
pm file=20
works fine without the factory. If I create a separate file for Assay =
and=20
reference it (use Assay;) in my code, Factory works fine. If I =
delete the=20
reference to Assay, it still works (at least it can get the column=20
definitions)?!</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2> Sample code is shown =
below.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>Thanks,</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>Barry</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>ps The following also does not =
work:</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>
<DIV><FONT face=3DArial size=3D2> $WebCams->use_classes=20
(qw/WebCamsDb::Assay WebCamsDb::Results =
WebCamsDb::Experiment/);</FONT></DIV>
<DIV><FONT face=3DArial size=3D2> my @columns =3D=20
$WebCams->columns=20
(lc('WebCamsDb::assay'));<BR>=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D</FONT></DIV>
<DIV>(File WebCamsDb.pm)</DIV></FONT><FONT face=3DArial=20
size=3D2>#!c:/perl/bin/perl<BR>package WebCamsDb;</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>use strict; use=20
warnings;<BR>#-----------------------------------------------------------=
------------------<BR>{package=20
WebCams_Server;<BR>use strict; use warnings;<BR>use lib=20
'C:/Development/Perl/database';<BR>use base qw(Class::DBI);<BR>sub =
MODULE_NAME {=20
__PACKAGE__ }<BR>sub class_title {shift->table}<BR>sub class_plural=20
{shift->table}<BR>sub class_description =
{shift->table}</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>1;}# end Package=20
WebCams_Server<BR>#------------------------------------------------------=
-------------------------------------------------------------------------=
------------------------{package=20
Assay;<BR>use strict;<BR>use warnings;<BR>use base=20
'WebCams_Server';</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>__PACKAGE__->table=20
(__PACKAGE__);<BR>__PACKAGE__->columns(All =3D> qw/ name =
description=20
executable comments timestamp /);<BR></FONT><FONT face=3DArial=20
size=3D2>1;}<BR></FONT><FONT face=3DArial=20
size=3D2>#---------------------------------------------------------------=
-------------------------------------------------------------------------=
---------------{package=20
Results;<BR>use strict; use warnings;<BR>use base=20
'WebCams_Server';<BR></FONT><FONT face=3DArial =
size=3D2>__PACKAGE__->table=20
(__PACKAGE__);<BR>__PACKAGE__->columns(All =3D> qw/ id seq_id =
exp_run value=20
timestamp /);<BR>1;}<BR></FONT><FONT face=3DArial=20
size=3D2>#=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D<BR>
<DIV>(File try_factory.pl)</DIV>
<DIV>use strict; use warnings;<BR>use lib =
"c:/development/perl/lib/";</DIV>
<DIV>use WebCamsDb;<BR>use Class::DBI::Factory;</DIV>
<DIV> </DIV>
<DIV>my $WebCams =3D Class::DBI::Factory->new;<BR>$WebCams->set_db =
({db_type=20
=3D>=20
'mysql',<BR> &=
nbsp; =20
db_name =3D>=20
'WebCams',<BR>  =
; =20
db_username =3D>=20
$name,<BR> &nb=
sp; =20
db_password =3D>=20
$pw,<BR>  =
; =20
});<BR>$WebCams->use_classes (qw/Assay Results Experiment/);</DIV>
<DIV>my $table =3D 'Assay';</DIV>
<DIV>my @columns =3D $WebCams->columns=20
(lc($table));<BR>#=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D<BR>
<DIV>(File Assay.pm)</DIV></DIV>
<DIV>package Assay;<BR>use strict; use warnings;<BR>use lib=20
"c:/development/perl/lib/";</DIV>
<DIV>use base 'WebCams_Server';</DIV>
<DIV><FONT face=3DArial size=3D2>__PACKAGE__->table=20
(__PACKAGE__);<BR>__PACKAGE__->columns(All =3D> qw/ name =
description=20
executable comments timestamp /);<BR></FONT><FONT face=3DArial=20
size=3D2>1;</FONT></DIV></FONT></DIV></BODY></HTML>
------=_NextPart_000_0022_01C539E8.8038A900--
|
Using class::dbi::factory with multiple table classes in a single file
Barry Dancis 18:05 on 05 Apr 2005
|