Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight

Need help untangling inheritance and scope in CGI::App module.

by hesco (Deacon)
on May 02, 2006 at 00:13 UTC ( #546793=perlquestion: print w/replies, xml ) Need Help??

hesco has asked for the wisdom of the Perl Monks concerning the following question:

And another one, if I may . . .

The code below are the relevant excerpts from the module we're building here. But this one is confusing me. This database conection was working for me before I commented it out of cgiapp_init() and tried to offload the work into a new dbh() routine.

The errors read: "Error executing class callback in init stage: Can't call method "config_file" on an undefined value at /home/hesco/anmc/sb/Registration/Registration/lib/Registration/WWW/ line 114." Line 114 is a part of the dbh() routine and reads: $self->config_file('/var/lib/cf/tbd/regform/Registration.ini');

So what here is the undefined value? Isn't $self defined? Why wouldn't it be passed from cgiapp_init? If not $self, then how is it that a hard coded path would be undefined?

I don't get it?

-- Hugh

package Registration::WWW::RegForm; use warnings; use strict; use diagnostics; use base 'CGI::Application'; use CGI::Application::Plugin::Config::Simple; . . . use CGI::FormBuilder; use CGI; . . . sub cgiapp_init { my $self = shift; $self->config_file('/var/lib/cf/tbd/regform/Registration.ini'); my $lib = $self->config_param('library'); push @INC, $lib; # use lib qw{/home/hesco/anmc/sb/Registration/Registration/lib}; require Registration::WWW::htmlgui; require Registration::DB; my $dbh = dbh(); # my $dbh = Registration::DB->connect($self->config_param('db_engine +'),$self->config_param('host_name'),$sel f->config_param('db_name'),$self->config_param('db_user'),$self->confi +g_param('db_pw')); my $result = auth_config($dbh); } sub dbh { my $self = shift; $self->config_file('/var/lib/cf/tbd/regform/Registration.ini'); my $dbh = Registration::DB->connect( $self->config_param('db_engine'), $self->config_param('host_name'), $self->config_param('db_name'), $self->config_param('db_user'), $self->config_param('db_pw') ); return $dbh; }

Replies are listed 'Best First'.
Re: Need help untangling inheritance and scope in CGI::App module.
by gryphon (Abbot) on May 02, 2006 at 00:31 UTC

    Greetings hesco,

    I haven't tested this, but just looking briefly at your code, the first thing I'd try is to change the 8th line of cgiapp_init() to this:

    my $dbh = $self->dbh(); my $result = auth_config($dbh); # ...or instead, simply... my $result = auth_config($self->dbh());

    Inside your sub dbh, you shift off the first element of @_, but calling dbh() directly means you're not passing anything into the sub. Calling $self->dbh() will fix this.

    gryphon Development Manager (WDDC)
    code('Perl') || die;

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://546793]
Approved by GrandFather
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (8)
As of 2021-09-22 08:12 GMT
Find Nodes?
    Voting Booth?

    No recent polls found