[CDBI] Class::DBI Has Many Error

Jay Hargreaves jay at rigadon.com
Wed Nov 16 17:43:13 GMT 2005

Actually I've just realised that the latest version did not fix my 
problem - I now have the following error:

Can't call method "clear_object_index" on an undefined value at 
C:/Perl/site/lib/Class/DBI/Relationship.pm line 24. Compilation failed 
in require at c:\httpd\bowdonrufc\cgi-bin/BowdonRUFC/Admin.pm line 104.

This appears to be in the require statement highlighted below - 
coincidence or inevitability :) The error doesn't occur if I *use* the 
required module in Admin.pm rather than trying to load it on the fly - 
anyone got an idea what I am doing wrong? Apart from turning up in the 
first place :)


William Ross wrote:
> On 16 Nov 2005, at 13:49, Jay Hargreaves wrote:
>> Hi everyone!
>> So I have written a small database application using Class::DBI and  I 
>> have a table of Links and a table of LinkCategories. Each Link  has a 
>> LinkCategory and thus each LinkCategory has many Links. I  have 
>> written an admin interface so I can create new Links and  
>> LinkCategories as I wish. All works as expected on my PC.
>> However, I have now uploaded the code to my laptop and it does not  
>> work on there! My laptop is using the latest Class::DBI version  
>> available on CPAN - my PC is using version 0.95!! If I replace the  
>> DBI.pm file on my laptop with the one on my PC everything works fine!
>> So that's the background - here is the error message:
>> Can't use an undefined value as a HASH reference at C:/Perl/site/ 
>> lib/Class/DBI/Relationship/HasMany.pm line 51. Compilation failed  in 
>> require at c:\httpd\bowdonrufc\cgi-bin/BowdonRUFC/Admin.pm line  104.
> I'm not sure you have got the latest cdbi there: the Relationship/ 
> HasMany.pm in v3.0.12 has no line 51. Or have you changed that file?
> You're getting that particular error because at some point you're  
> passing a third argument to has_many that isn't a hashref. I can't  
> begin to see why that is, but from looking over the code I suspect  it's 
> to do with calling class methods as normal functions at some point.
> will
> ps. I have to say, your code is full of ingenuity, but it scares the  
> hell out of me.
>   require File::Spec->catfile(split /::/, "$module.pm")
> is particularly startling, and
>   my $columns = eval ( '$' . $module . '::columns' );
> suggests that more OOP study is needed. If you were thinking in terms  
> of classes and methods it would just be:
>   my @columns = $module->all_columns;
> and ${$variable} is always a big red flag. there's a lovely MJD rant  
> about this somewhere. hold on. ah. not really the same thing, but:  
> http://perl.plover.com/varvarname.html

bingo, bango, bosh...

More information about the ClassDBI mailing list