On Thu, Feb 14, 2002 at 01:55:34PM -0600, Alex Porras wrote:

> Ok, that makes sense.  But the reason I didn't include a "new"
>method for FooBar was because I don't know what A::R's "new" method
>does, so I didn't want to override it.  What if it does some init
>stuff to the object? I'm assuming that's what's happening because,
>after adding a "new" method to FooBar, when I try to call
>$foobar->param (which I have not overridden), the child process
>segfaults.  Oh well, I guess at this point I need to go back to
>reading more on perl OO since it's not sinking.

I believe that Apache::Request doesn't really do inheritence properly.
If you look you'll see that the new() method is written in C.  It
should be blessing itself into the passed in class, not using
Apache::Request.  My XS is a little foggy, but it appears that these
lines should be modified to use the passed in class:

    CLEANUP:
    apreq_add_magic(ST(0), robj, RETVAL);

which ends up as:

        ST(0) = sv_newmortal();
        sv_setref_pv(ST(0), "Apache::Request", (void*)RETVAL);


In any case all you need to do to get around this is define your own
new method and call the Apache::Request object directly and store it
as the value 'r'..  Here's an example:

sub new {
 my ($class, $r) = @_;

 return bless { r  => Apache::Request->new($r),
               }, $class;
}





> Thanks for your help!
> 
> --Alex
> 
> > -----Original Message-----
> > From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]
> > 
> > The problem is that package FooBar doesn't have a "new" 
> > method. Here's what happened as a result.
> > 
> > When you called 'FooBar->new($r), perl looked for a sub 
> > called "new" in package
> > FooBar. Since it didn't find one, it looked at FooBar's @ISA, 
> > and looked in
> > Apache::Request for a "new" method. There it presumably found 
> > one, so that
> > statement didn't return an error. But, the new() in 
> > Apache::Request probably
> > returned an Apache::Request object instead of a FooBar 
> > object, so when you
> > called "$form->fooey", it only looked in Apache::Request and 
> > any modules in it's
> > @ISA.
> > 
> > You might want to look at using the universal "isa" and "can" 
> > methods while
> > you're debugging and trying stuff out. Good luck!
> > 
> > Wes Sheldahl

-- 
Paul Lindner    [EMAIL PROTECTED]   ||||| | | | |  |  |  |   |   |

    mod_perl Developer's Cookbook   http://www.modperlcookbook.org/
         Human Rights Declaration   http://www.unhchr.ch/udhr/index.htm

Reply via email to