You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by "Eric J. Hansen" <eh...@worldmachine.com> on 2003/12/19 01:52:24 UTC
using pnotes to store/retrieve Class::DBI objects?
I'm trying to use $r->pnotes to store a Class::DBI object in an early
stage handler so it may be retrieved by a later stage handler. Specifically:
in my PerlTransHandler:
my $dbrecord = ClassDBI_Table1->retrieve ( 1 ); # ClassDBI_Table1 is of base Class::DBI::mysql
$r->pnotes('INFO_FOR_LATER', \$dbrecord );
Note that ClassDBI_Table1 represents a MySQL table that has a field
called "Name".
Then, in my PerlResponseHandler:
my $existing_dbrecord = $r->pnotes('INFO_FOR_LATER');
$r->log_error ( "INFO_FOR_LATER = " . $existing_dbrecord->Name );
Unfortunately, when I do this, I get a "Can't use an undefined value as a
HASH reference ..." error. I've tried various iterations of the code,
such as not deferencing the stored object in PerlTransHandler, as
well as referencing the Name property as $existing_dbrecord->{Name} (with
braces), but no luck. Have also tried assigning the pnotes value
as ('INFO_FOR_LATER' => \$dbrecord), but again not working.
Any help? Am guessing this is a syntax issue, but I'm not getting it.
FYI, am running Apache/2.0.48 (Unix) mod_perl/1.99_11 Perl/v5.8.2,
and I'm also using Apache::DBI.
thank you,
Eric
--
Reporting bugs: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
Re: using pnotes to store/retrieve Class::DBI objects?
Posted by Stas Bekman <st...@stason.org>.
Eric J. Hansen wrote:
> Hurrah! Its working now. Thank you!
Cool. Thanks for the report.
I'll commit it after releasing 1.99_12 on Monday, so it'll be available in
1.99_13 hopefully somewhere next month. I can't add it to 1.99_12 since it
wasn't tested.
>>>When I try to retrieve this Class::DBI object from the Cleanup
>>>Handler, the pnotes values are totally gone. However,
>>
>>regular scalers
>>
>>>that I've put in 'notes' are still there. Perhaps pnotes has (by
>>>design) already been cleaned up prior to the
>>
>>PerlCleanupHandler stage?
>>
>>Right, here is the fix:
__________________________________________________________________
Stas Bekman JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/ mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org http://ticketmaster.com
--
Reporting bugs: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
RE: using pnotes to store/retrieve Class::DBI objects?
Posted by "Eric J. Hansen" <eh...@worldmachine.com>.
Hurrah! Its working now. Thank you!
Eric
> > When I try to retrieve this Class::DBI object from the Cleanup
> > Handler, the pnotes values are totally gone. However,
> regular scalers
> > that I've put in 'notes' are still there. Perhaps pnotes has (by
> > design) already been cleaned up prior to the
> PerlCleanupHandler stage?
>
> Right, here is the fix:
>
> Index: src/modules/perl/modperl_config.c
> ===================================================================
> RCS file: /home/cvs/modperl-2.0/src/modules/perl/modperl_config.c,v
> retrieving revision 1.71
> diff -u -r1.71 modperl_config.c
> --- src/modules/perl/modperl_config.c 23 Oct 2003 18:34:51
> -0000 1.71
> +++ src/modules/perl/modperl_config.c 20 Dec 2003 02:46:41 -0000
> @@ -288,12 +288,12 @@
> apr_status_t retval;
> MP_dRCFG;
>
> + retval = modperl_callback_per_dir(MP_CLEANUP_HANDLER, r,
> + MP_HOOK_RUN_ALL);
> +
> if (rcfg->pnotes) {
> SvREFCNT_dec(rcfg->pnotes);
> rcfg->pnotes = Nullhv;
> }
> -
> - retval = modperl_callback_per_dir(MP_CLEANUP_HANDLER, r,
> MP_HOOK_RUN_ALL);
>
> /* undo changes to %ENV caused by +SetupEnv, perl-script, or
> * $r->subprocess_env, so the values won't persist */
--
Reporting bugs: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
Re: using pnotes to store/retrieve Class::DBI objects?
Posted by Stas Bekman <st...@stason.org>.
Eric J. Hansen wrote:
> After looking at this further, it turns out that Perrin's suggested
> code *does* work, but only in the PerlResponseHandler or earlier
> stages. And unfortunately, I mis-stated the original problem... which is
> that I am trying to retrieve that pnotes object (Class::DBI instance)
> in _PerlCleanupHandler_ (not PerlResponseHandler as originally stated).
>
> When I try to retrieve this Class::DBI object from the Cleanup Handler,
> the pnotes values are totally gone. However, regular scalers that I've
> put in 'notes' are still there. Perhaps pnotes has (by design) already
> been cleaned up prior to the PerlCleanupHandler stage?
Right, here is the fix:
Index: src/modules/perl/modperl_config.c
===================================================================
RCS file: /home/cvs/modperl-2.0/src/modules/perl/modperl_config.c,v
retrieving revision 1.71
diff -u -r1.71 modperl_config.c
--- src/modules/perl/modperl_config.c 23 Oct 2003 18:34:51 -0000 1.71
+++ src/modules/perl/modperl_config.c 20 Dec 2003 02:46:41 -0000
@@ -288,12 +288,12 @@
apr_status_t retval;
MP_dRCFG;
+ retval = modperl_callback_per_dir(MP_CLEANUP_HANDLER, r, MP_HOOK_RUN_ALL);
+
if (rcfg->pnotes) {
SvREFCNT_dec(rcfg->pnotes);
rcfg->pnotes = Nullhv;
}
-
- retval = modperl_callback_per_dir(MP_CLEANUP_HANDLER, r, MP_HOOK_RUN_ALL);
/* undo changes to %ENV caused by +SetupEnv, perl-script, or
* $r->subprocess_env, so the values won't persist */
__________________________________________________________________
Stas Bekman JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/ mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org http://ticketmaster.com
--
Reporting bugs: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
RE: using pnotes to store/retrieve Class::DBI objects?
Posted by "Eric J. Hansen" <eh...@worldmachine.com>.
After looking at this further, it turns out that Perrin's suggested
code *does* work, but only in the PerlResponseHandler or earlier
stages. And unfortunately, I mis-stated the original problem... which is
that I am trying to retrieve that pnotes object (Class::DBI instance)
in _PerlCleanupHandler_ (not PerlResponseHandler as originally stated).
When I try to retrieve this Class::DBI object from the Cleanup Handler,
the pnotes values are totally gone. However, regular scalers that I've
put in 'notes' are still there. Perhaps pnotes has (by design) already
been cleaned up prior to the PerlCleanupHandler stage?
FYI, this happens whether or not I define PerlCleanupHandler in the
server conf file or dynamically via $r->push_handlers.
thanks
Eric
Perrin last wrote:
> > On further investigation, the problem seems to be that the
> object is
> > losing its namespace.
>
> That's not it. Many people have successfully stored objects
> in pnotes
> before.
>
> > In the first handler (where I define
> > the object and store it in pnotes) I'm logging the value of "ref
> > $dbrecord" and getting the correct Class::Object value. In
> the second
> > handler (where I retrieve the object from pnotes and try to
> access a
> > method), I'm logging the "ref $dbrecord" and getting a blank ("").
>
> Are you certain that you have the same request object in both
> cases? If
> your first handler is handling an index request, the second
> one might be
> a totally different request object. Check $r->is_initial_req().
--
Reporting bugs: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
Re: using pnotes to store/retrieve Class::DBI objects?
Posted by Perrin Harkins <pe...@elem.com>.
Eric J. Hansen wrote:
> On further investigation, the problem seems to be that the object
> is losing its namespace.
That's not it. Many people have successfully stored objects in pnotes
before.
> In the first handler (where I define
> the object and store it in pnotes) I'm logging the value of
> "ref $dbrecord" and getting the correct Class::Object value. In
> the second handler (where I retrieve the object from pnotes
> and try to access a method), I'm logging the "ref $dbrecord" and
> getting a blank ("").
Are you certain that you have the same request object in both cases? If
your first handler is handling an index request, the second one might be
a totally different request object. Check $r->is_initial_req().
- Perrin
--
Reporting bugs: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
RE: using pnotes to store/retrieve Class::DBI objects?
Posted by "Eric J. Hansen" <eh...@worldmachine.com>.
I tried Perrin's suggestion, but got the same error message
(Can't call method "Name" on an undefined value at....)
On further investigation, the problem seems to be that the object
is losing its namespace. In the first handler (where I define
the object and store it in pnotes) I'm logging the value of
"ref $dbrecord" and getting the correct Class::Object value. In
the second handler (where I retrieve the object from pnotes
and try to access a method), I'm logging the "ref $dbrecord" and
getting a blank (""). Seems that this must be the problem...
any other ideas?
thanks
Eric
> -----Original Message-----
> From: Perrin Harkins [mailto:perrin@elem.com]
> Sent: Thursday, December 18, 2003 9:22 PM
> To: Eric J. Hansen
> Cc: modperl@perl.apache.org
> Subject: Re: using pnotes to store/retrieve Class::DBI objects?
>
>
> Eric J. Hansen wrote:
> > my $dbrecord = ClassDBI_Table1->retrieve ( 1 );
> # ClassDBI_Table1 is of base Class::DBI::mysql
> > $r->pnotes('INFO_FOR_LATER', \$dbrecord );
>
> Should be
>
> $r->pnotes('INFO_FOR_LATER', $dbrecord );
>
> > my $existing_dbrecord = $r->pnotes('INFO_FOR_LATER');
> > $r->log_error ( "INFO_FOR_LATER = " .
> $existing_dbrecord->Name );
>
> Should be
>
> $r->log_error ( "INFO_FOR_LATER = " . $existing_dbrecord->Name() );
>
> > I've tried various iterations of the code
>
> I'm guessing you just didn't try the right combination.
>
> - Perrin
--
Reporting bugs: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
Re: using pnotes to store/retrieve Class::DBI objects?
Posted by Perrin Harkins <pe...@elem.com>.
Eric J. Hansen wrote:
> my $dbrecord = ClassDBI_Table1->retrieve ( 1 ); # ClassDBI_Table1 is of base Class::DBI::mysql
> $r->pnotes('INFO_FOR_LATER', \$dbrecord );
Should be
$r->pnotes('INFO_FOR_LATER', $dbrecord );
> my $existing_dbrecord = $r->pnotes('INFO_FOR_LATER');
> $r->log_error ( "INFO_FOR_LATER = " . $existing_dbrecord->Name );
Should be
$r->log_error ( "INFO_FOR_LATER = " . $existing_dbrecord->Name() );
> I've tried various iterations of the code
I'm guessing you just didn't try the right combination.
- Perrin
--
Reporting bugs: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html