Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

CGI::Application Question

by vroom (His Eminence)
on Aug 22, 2001 at 18:32 UTC ( [id://106960]=perlquestion: print w/replies, xml ) Need Help??

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

I started playing with CGI::Application earlier today and am so far impressed with how much it simplifies my life (well that and HTML::Template).

My only problem is that I am trying to implement a error_mode for unspecified run_modes as specified in the docs by adding a handler to AUTOLOAD. However it only runs on &rm=AUTOLOAD and not unspecified runmodes like &rm=blah. I'm probably forgetting something obvious but it looks right. Here's the slimmed down code.

package LocalSite::InquiryQueryApp; use LocalSite::InquiryUtils; use base 'CGI::Application'; use strict; sub setup{ my $self=shift; $self->start_mode('query'); $self->mode_param('rm'); $self->run_modes( 'query'=>\&query_mode, 'display'=>\&display_mode, "AUTOLOAD"=>\&error_mode ); #get our database connection $self->param('dbh'=>getDbConnection); } sub query_mode{ my $self=shift; my $query=$self->query(); my $str="<HTML><BODY>Query Mode</BODY></HTML>"; return $str; } sub error_mode{ my $self=shift; my $rm=shift; my $str="<HTML><BODY>Error: you have chosen an invalid runmode</BODY +></HTML>"; return $str; } sub display_mode{ my $self=shift; my $query=$self->query(); my $str="<HTML><BODY>Display Mode</BODY></HTML>"; return $str; } sub teardown{ my $self=shift; $self->param('dbh')->disconnect(); } 1;


vroom | Tim Vroom | vroom@blockstackers.com

Replies are listed 'Best First'.
Re: CGI::Application Question
by rob_au (Abbot) on Aug 22, 2001 at 18:54 UTC
    This is the way which I have used the AUTOLOAD parameter with no problems (see trimmed code). I would recommend changing the hash key from an interpolated quoted value (") to a non-interpolated quoted value (') (given the success I have had quoting the AUTOLOAD hash key in this manner) - See perlop for details.
     
    my ($application) = self->new( TMPL_PATH => '../templates/signup/', PARAMS => { 'mode_param' => 'stage', } ); sub setup { my ($self) = shift; $self->start_mode('1'); $self->run_modes({ 'AUTOLOAD' => 'form_entry', 'F' => 'form_submission', }); $self->mode_param($self->param('mode_param')); };

     

     
    Ooohhh, Rob no beer function well without!

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (6)
As of 2024-03-28 13:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found