Hello all,
I'm having trouble saving objects of my Registration class between pages on my web site. I'm saving the objects in an array using CGI::Session, like this:
# Add new registration object to the regArray my $ptrRegistrationArray = $session->param("registrationArray"); push(@$ptrRegistrationArray, $ptrCurrentRegistration); $session->param("registrationArray", $ptrRegistrationArray); $session->flush();
I call the sequence above on two different pages (representing two paths available for the user: create new registration or renew an existing registration). The following page is a review screen where the paths converge; it pulls all registration info out of the registrationArray for display, like this:
my $ptrRegistrationArray = $session->param("registrationArray"); foreach my $reg (@$ptrRegistrationArray) { print STDERR "reg is a " . ref($reg) . "\n"; print STDERR "reg = " . Dumper($reg) . "\n"; print STDERR "reg->can('testMethod') results: " . $reg->can("testMethod") . "\n"; # testMethod() is basically a "hello world" for the # Registration class. $reg->testMethod(); # Other work here }
The puzzling/perplexing/frustrating as hell bit: the review page works for the 'renew' path, but fails for the 'new' path (for clarity: 'new' here is referring to a new user registration, not Registration::new()). Here's the output for the renew path (working example):
reg is a Registration reg = $VAR1 = bless( { 'name1' => 'value1', 'name2' => 'value2', 'name3' => 'value3', }, 'Registration' ); reg->can('testMethod') results: CODE(0x83406b8) hello world
And here's the output for the new path (failing example):
reg is a Registration reg = $VAR1 = bless( { 'name1' => 'value1', 'name2' => 'value2', 'name3' => 'value3', }, 'Registration' ); reg->can('testMethod') results: <conspicuously blank!> Can't locate object method "testMethod" via package "Registration"
As you can see, although the instance's data makes it out of the extraction process on the 'bad' path just fine, the class seems to have forgotten it's methods; almost like it's reverted to a simple hash. However, calling ref($object) - not to mention the Data::Dumper output - indicate this object is recognized as a Registration class instance. It's "bless"ed & everything! Although clearly not by the right gods...
I'm about out of hair to pull (didn't have much to start with). Anyone have any idea what could be happening to my objects here?
In reply to "Can't locate object method"...? Why not??? by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |