Re: stupid beginner question
[prev]
[thread]
[next]
[Date index for 2005/06/27]
On 27 Jun 2005, at 08:11, Hartmaier Alexander wrote:
> So one file per package is 'normal' usage...ok!
> Maybe the problem is that I set the perl library path manually in my
> startup.pl with 'use lib "/home/nac/lib";'.
>
> Looks like the base class or something like this isn't found...
>
> /home/nac/lib/NAC/
> DBI.pm (base class)
> Constraints.pm (uses base class)
>
> I get the following error in all of my embperl pages:
> [9960]ERR: 24: Error in Perl code: Can't call method "param" on an =20
> undefined
> value at /home/nac/lib/NAC/Constraints.pm line 5
>
> Constraints.pm:
>
> package NAC::Constraints;
> use strict;
> use warnings;
> use base 'NAC::DBI';
> __PACKAGE__->table($NAC::DBI::g_config->param('schemaname') .
> '.constraints');
Read the error message. The class is in the right place and it's =20
loading fine, or you would see a message like 'Can't locate NAC/=20
DBI.pm in @INC'.
The problem is that you're trying to access a configuration object =20
held in $NAC::DBI::g_config before that object exists. As the message =20=
says, you're calling method "param" on an undefined object, =20
presumably because some code that you rely on hasn't run yet. =20
Something about the order of packages in your old single file will =20
have obscured the bug until now.
The first thing I'd do is stop accessing that variable directly. Add =20
a method to NAC::DBI that returns the $g_config object, and in that =20
method you can make sure that the object exists and load it if =20
necessary. That method will be inherited by NAC::Constraints. You =20
will probably still run into difficulties to do with these methods =20
being called very early during loading, but they will be easier to =20
identify and fix if your encapsulation is good (ie, you stick to the =20
method interface and leave the class variables alone).
best
will
> __PACKAGE__->columns(Primary =3D> qw/fromtable fromfield/);
> __PACKAGE__->columns(Essential =3D> qw/totable tofield toname =
desctable
> descfield/);
> __PACKAGE__->columns(Others =3D> qw//);
>
> 1;
>
> Is there any example about where the files should be saved?
>
> -Alex
>
>
>
>> -----Urspr=FCngliche Nachricht-----
>> Von: Matt S Trout [mailto:cdbi-talk@xxxxx.xx.xx]
>> Gesendet: Freitag, 24. Juni 2005 20:26
>> An: Hartmaier Alexander
>> Cc: class dbi list
>> Betreff: Re: stupid beginner question
>>
>> On Fri, Jun 24, 2005 at 03:47:11PM +0200, Hartmaier Alexander wrote:
>>
>>> After starting to use CDBI I defined all my packages in one file.
>>>
>>> Now I thought it would be memory conservative and 'better' to split
>>>
>> them
>>
>>> up into one file per package definition.
>>>
>>> Before I used 'use nac_objects_dbi;' and now only the packages i =20
>>> need
>>> e.g. 'use NAC::Interface;'
>>>
>>> But it doesn't work and also is a bit complicated to debug under
>>>
>> Embperl
>>
>>> too.
>>>
>>
>> In what way doesn't it work? I've done Class::DBI one-package-per-=20
>> file
>> since
>> I first started working with it 2 or 3 years ago and never had any
>> problems
>> with it.
>>
>> If you could provide an example of the problem you're having, maybe
>> people
>> would better be able to help.
>>
>> --
>> Matt S Trout Website: http://=20
>> www.shadowcatsystems.co.uk
>> Technical Director E-mail: mst (at) shadowcatsystems.co.uk
>> Shadowcat Systems Ltd.
>