[CDBI] print Class::DBI object to Data::Dumper

Birgit Kellner birgit.kellner at univie.ac.at
Wed Jan 18 15:26:37 GMT 2006


I'm trying to print a Class::DBI object to a file handle, using 
Data::Dumper, with a little subroutine that I've written to dump my 
variables for testing purposes. However, not all of the data gets 
dumped, and I'd like to find out why.

This is the routine:

sub dump {
my $variable = shift;# can be scalar, array ref or hash ref
my @loop;
push (@loop, $variable);# clumsy, but doesn't seem to work without it
my $caller = (caller(1))[3];
my $call_file = (caller(1))[1];
my $call_line = (caller(1))[2];
my $d = Data::Dumper->new(\@loop);
print TEST "$caller, $call_file, $call_line\n";
print TEST $d->Dump;


The object is retrieved in this routine:

sub show_single_term {
my @term = ILKB::Term->search(t_id => "$in->{t_id}");# t_id passed 
through the form
$vars->{terms} = \@term;


And this is the output to the filehandle:

main::show_single_term, /srv/www/cgi-bin/ilkb_edit/ilkb.cgi, 168
$VAR1 = [
bless( {
't_id' => '75',
'lan_id' => bless( {
'lan_id' => '123'
}, 'ILKB::Language' ),
't_owner' => 'Kellner',
'public' => undef,
'c_id' => bless( {
'c_id' => '36'
}, 'ILKB::Concept' ),
'tgrp_id' => '37',
'term' => 'svārthānumāna'
}, 'ILKB::Term' )

My question is this: there is more data in the object than is actually 
Here's the class definition:

package ILKB::Term;
use base 'ILKB::DBI';
my %columns = &main::get_class_columns("term");
ILKB::Term->columns(Primary => "$columns{Primary}" );
ILKB::Term->columns(Essential => @{$columns{Essential}});
ILKB::Term->has_a('c_id' => 'ILKB::Concept');
ILKB::Term->has_a('lan_id' => 'ILKB::Language');
ILKB::Term->has_many('descriptive_item' =>'ILKB::DescriptiveItem');
ILKB::Term->has_many('term_translation' =>'ILKB::TermTranslation');

I know that the items related through ILKB::DescriptiveItem are 
retrieved because they are printed to an HTML template that's called 
later in the process. But for some reason they don't get dumped. Does 
anyone know why? Or know of any alternative (and better) approaches to 
dumping complete Class::DBI objects?


Birgit Kellner

More information about the ClassDBI mailing list