Hi Alex,

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





"Alex Porras" <[EMAIL PROTECTED]> on 02/14/2002 01:44:20 PM

To:   "mod perl list" <[EMAIL PROTECTED]>
cc:    (bcc: Wesley Sheldahl/Lex/Lexmark)
Subject:  inheritance and Apache::Request


I am slowly learning about OO from Tom's tutorial, and was able to do
inheritance with two dummy classes I wrote, including adding methods to the
subclass and have them work too.  However, when I tried to inherit from
Apache::Request, it doesn't seem to work right.  Maybe this isn't an
Apache::Request issue, so forgive me if that's the case, but here's what I got:

FooBar.pm
---------------------------------------------
package FooBar;

use strict;
use Apache::Request();

@FooBar::ISA = qw(Apache::Request);

sub fooey {
     print "hello world, I'm in FooBar";
}

---------------------------------------------

Handler.pm
---------------------------------------------
sub handler {
     my $r = shift;
     $r->send_http_header('text/html');
     my $form = FooBar->new($r);
     $form->fooey;
     $r->exit(OK);
}


Here's the error I get:

[Thu Feb 14 12:35:14 2002] [error] Can't locate object method "fooey" via
package "Apache::Request" (perhaps you forgot to load "Apache::Request"?) at
/path/modified/Handler.pm line 21.






Reply via email to