On Wed, 17 Nov 2004 09:20:43 -0600, Jason A. Crome <suppressed> wrote:
> So I am getting a little fancier with my CGI::Applications these days. . .
> I'm using inheritance to cut down the amount of duplicate code and
> maintenance hassles I created for myself. I'm having some issues extending
> the functionality of cgiapp_postrun() however. Allow me to explain my
> intent a bit:
>
<snip - base object's cgiapp_postrun>
>
> So I threw this code in my base object (let's call it My::App) and it works
> great!
>
> I have an instance now where an app derived from My::App wants to process
> the output of one of it's runmodes before the base object processes it. The
> code for this looks like:
>
> sub cgiapp_postrun
> {
> my $self = shift;
> my $html_ref = shift;
>
> # Drop out if we are printing a tax statement
> return if $self->get_current_runmode() eq "print";
>
> # Dereference the output data
> my $html = $$html_ref;
>
> # Draw the tab page
> my $tabs = $self->draw_tabs($html);
>
> # Replace old page with the new one
> $$html_ref = $tabs;
>
> # Invoke our ancestor's functionality
> $self->SUPER::cgiapp_postrun(\$tabs);
> }
>
> And for a reason I can't explain, it seems as if the output in the base
> object is completely ignored. I know it's being called, because if I throw
> a die() in there, the app does in fact die. But the output of the runmode
> isn't displayed. What am I doing wrong? I've been staring at this a while
> and I have the feeling something simple is glaring at me. I just can't see
> it.
The issue is that you're passing a different reference to the base class
than is getting passed to the child class:
# Invoke our ancestor's functionality
$self->SUPER::cgiapp_postrun(\$tabs);
run() passes a reference to cgiapp_postrun(), but doesn't expect
anything returned. After the cgiapp_postrun() method has finished, run()
basically spits out the reference as the page output. So, what I see
happening is that your child class grabs the reference into $html_ref,
which gets modified... but then you pass a reference to $tabs to the
parent class' cgiapp_postrun(). $html_ref never gets changed by the
parent class, in that situation.
Easy fix: pass $html_ref to the parent's cgiapp_postrun().
--
Matthew Weier O'Phinney
suppressed
http://weierophinney.net/matthew/
---------------------------------------------------------------------
Web Archive: http://www.mail-archive.com/suppressed/
http://marc.theaimsgroup.com/?l=cgiapp&r=1&w=2
To unsubscribe, e-mail: suppressed
For additional commands, e-mail: suppressed
Mail converted by mhonarc 2.6.15
This archive provided courtesy of JSW4.NET, Internet Hosting Services for Small Business.