suppressed wrote:
Hi!This may not be strictly a CGI::Application question, but I thought I'd ask here... this is my first attempt at using this (and it appears *very* useful!). I may not be grokking something about perl OOP.I wanted to add an auth object to my application, so I created something like this:package myApp::Auth; use warnings; use strict; use Exporter (); our @ISA = qw( Exporter ); our @EXPORT = qw( new login ); our @EXPORT_OK = qw( new login );
Here's your problem: you're exporting "new" by default, so you're _replacing_ the "new" in your CgiApp derived package. That's _not_ what you want at all, of course. Note that _replacing_ is something completely different from _overriding_.
Remove everything to do with Exporter. Typical OO code does not have to export anything, since your object will wrap all you need from it.
You should be using your own object like this:
use myApp::Auth;
my $auth = myApp::Auth->new( <arguments> ); # perl knows where to look for new() !
$auth->perform_some_method();
You could instantiate your object in CgiApp's setup() method, save it as a param(), and access it from there:
# in myApp::test (your CgiApp derived class)
sub setup {
my $self = shift;
# store auth object
$self->param( auth => myApp::Auth->new( <args> ) );
# more setup here
}
# use it in a run mode
sub foo {
my $self = shift;
my $auth = $self->param('auth');
$auth->make_some_check();
}
When I use this from a simple script, everything is fine. When I use it from within the CGI::App derived class (test)via an instance script, I get: Can't local object method "_module" via package "myApp::test"
See? You exported new, but not _module. the call to new lives in myApp::test now, so it's looking for methods in the current package.
So, some kind of namespace issue due to the fact that the caller is an object (an instance of CGI::Application), it seems... Any ideas about what lame-brain mistake I've made will be greatly appreciated!!
Don't use Exporter unless you're exporting real functions or procedures. Read up on OO in perl (perldoc perlboot etc).
HTH,
Rhesa
---------------------------------------------------------------------
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.