FlatBallFlyer has asked for the wisdom of the Perl Monks concerning the following question:
#============================================================== # FILE: Affiliation.pm # # DESCRIPTION: Class that represents the affiliation # a player with a club # #============================================================= package DataObjects::Affiliation; require MySqlTools::Table; our @ISA = qw(MySqlTools::Table); require DataObjects::Club; require DataObjects::Player; require DataObjects::ClubDGAW; use Log::Log4perl qw(get_logger :levels); use strict; use warnings; my $affObject; #============================================================ # # METHOD: new # #=========================================================== sub new { my $class = shift; if ($affObject) {return affObject;} #-- Singleton . . $self->addColumn({name=>'playerID',..... . . #---------------------------------------------------- # Define foreign keys and indexes #---------------------------------------------------- $self->{FKPLAY} = $self->addFks({ NAME =>'Aff_Player_FK', OWNCOLS =>['playerID'], REFTABLE =>'player', REFCOLS =>['playerID'], ONDELETE =>'CASCADE', }); ===> #################################################### ###### - HERE $self->{FKPLAY} contains a valid FK ###### reference, $self->{FKS}[0] contains a ###### funky reference, the debugger shows it ###### to be a FK object, but the hash is ###### empty! ###################################################
As I stated earlier, I have very similar methods/helpers for working with Indexes, and their is not a problem there. I've reviewed the code side by side, and I'm stumped.#================================================== # # FILE: Table.pm # # DESCRIPTION: Abstract class to define a table # #================================================= package MySqlTools::Table; require MySqlTools::Column; require MySqlTools::ForeignKey; require MySqlTools::Index; require MySqlTools::ResultSet; require MySqlTools::Database; require Utilities::Properties; use Log::Log4perl qw(get_logger :levels); use strict; use warnings; #================================================== # # METHOD: new # #================================================ sub new { my $class = shift; my $parm = shift; . . bless( $self, $class ); return $self; } . . #=================================================== # # METHOD: addFk # #================================================== sub addFks{ my $self = shift; my $parms = shift; my $log = get_logger("MySqlTools::Table"); my $fkName = $parms->{NAME}; $parms->{OWNTABLE} = $self->{NAME}; $parms->{DBH} = $self->{DBH}; my $fk = MySqlTools::ForeignKey->new($parms); if ( !$fk ) { $log->error('FK->new failed!'); } else { ---> push @{$self->{FKS}}, $fk; } ***> return $fk; }
It looks like this was more of a debugger bug than a problem in the code. The attribute $self->{FKS} is an array reference, so the cast of the reference to a real arry @{$arrayRef} is done so that push will work. When the "Table::AddFks" method is called, a valid FK Ref was pushed onto $self->FKS (see ---> in the code above). When a breakpoint in the dugger is set to ***> both $fk, and $self->{FKS}[0] hold a valid reference to an FK object. You can expand and explore the FK object hash. When the code continues to ===> the debugger shows that $self->{FKS}[0] holds a reference to a FK object, however the object can not be "expanded and explored". At this same break-point the $self->{FKPLAY} attribute holds a valid, explorable FK reference. After further testing, later on in the code when I iterate through the array, everything works as expected, and the variable explorer shows the FKS array to contain valid, explorable FK objects. It appears that I was lead down a rabbit hole by a bug in the debugger :) Thank you for a quick response, and I hope this node is able to help others that may be using the Epic deubgger. (I'm still a newbe here at the Monastery!)
I have been requested to show the MySqlTools::ForeignKey->new method, just to make this post complete, here she is.....
Thankssub new { my $class = shift; my $parm = shift; my $log = get_logger("MySqlTools::ForeignKey"); my $self = {}; $self->{DBH} = MySqlTools::Database->new(); $self->{NAME} = $parm->{NAME}; . . $log->info('New ForeignKey object initilized'); bless( $self, $class ); return $self; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Object Reference ^%#)#&* dissapers
by shmem (Chancellor) on Aug 28, 2008 at 21:50 UTC | |
|
Re: Objet Reference ^%#)#&* dissapers
by ikegami (Patriarch) on Aug 28, 2008 at 20:53 UTC |