Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Seeking help with CGI::Application, please.

by hesco (Deacon)
on Feb 11, 2006 at 00:54 UTC ( [id://529509]=perlquestion: print w/replies, xml ) Need Help??

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

I'm getting these errors thrown by the CGI::Application::run() method:

No such run mode 'start' at /var/wwwssl/auth-test/dprnew.cgi line 6 (i +n cleanup) Can't access `DESTROY' field in object of class D +istroPr +sRls. at /var/wwwssl/auth-test/dprnew.cgi line 0
dprnew.cgi reads:

#!/usr/bin/perl -wT use lib(qw{/home/hesco/sandbox/DistroPrsRls/lib}); use DistroPrsRls; BEGIN { print STDERR "\@INC includes: \n", join("\n", @INC), "\n"; } my $dpr = DistroPrsRls->new(); $dpr->run(); exit; 1;
My DistroPrsRls.pm calls DistroPrsRlsAuth.pm which includes a use base CGI::Application; line. It starts out:

package DistroPrsRls; use Carp; use lib(qw{/home/hesco/sandbox/DistroPrsRls/lib}); use base 'DistroPrsRlsAuth'; sub setup { my $self = shift; $self->start_mode('mode1'); $self->mode_param('rm'); $self->run_modes( 'mode1' => 'Login', 'mode2' => 'DPR_Dashboard', 'mode3' => 'EnterPrsRls', 'mode4' => 'ApprovePrsRls', 'mode5' => 'ChooseLists', 'mode6' => 'ScheduleDistro', 'mode7' => 'AuthorizeDistro', 'mode8' => 'ReviewJobs' ); return 1; } sub Login { my $self = shift; my $q = $self->query(); $output .= $q->start_html(-title => 'DistroPrsRls Login Form'); $output .= h3('Login Page'),br(); $output .= "$error \n" if defined($error); $output .= $q->startform(); $output .= $q->textfield(-name => 'testfield'); $output .= $q->password(-name => 'testpassword'); $output .= qq{UserID: <input type="text" name="username" size=15><b +r>}; $output .= qq{Password: <input type="password" name="password" size= +15><br>}; # $output .= qq{<input type="hidden" name="function" value="Login">} +; $output .= $q->hidden(-name => 'rm', -value => 'DPR-Dashboard'); # $output .= qq{<input type="submit" value="Login">}; $output .= $q->submit(-value => 'Login'); $output .= $q->end_form(); $output .= $q->end_html; return($output); } etc., etc.
Do I need to name one of the keys or values from the run_modes hash, 'start' to make this module work for me?

Thanks for your help.

-- Hugh

Replies are listed 'Best First'.
Re: Seeking help with CGI::Application, please.
by cees (Curate) on Feb 11, 2006 at 03:47 UTC

    What you have there should basically work, although there are a few problems with your code. However, I suspect the real problem is somewhere in the rest of the code that you haven't included.

    Here are a couple of things that you should consider changing:

    • add 'use strict;' to the top: Since you don't have a 'my $output' in your Login sub, I assume that you are not using strict. And while you are at it, you should probably add 'use warnings;' as well, and 'use diagnostics;' if you don't understand the errors or warnings that are spit out.
    • is 'h3' a method that you wrote? Or is it part of the CGI.pm library, and it should have been $q->h3?
    • Are you using something different than CGI.pm, because 'password' is not a valid method of CGI.pm (see the call to $q->password). It should probably be password_field instead.

    I doubt that fixing those problems will remove the error though. Also, the error message is kind of an odd one. CGI::Application doesn't use a DESTROY method, so where is that coming from? I am wondering if maybe your are loading a module that imports a lot of functions, and it happens to override some of the functionality in CGI::Application (a common mistake is to add something like 'use CGI qw(:standard)' to your app, which unexpectedly overrides some important methods in CGI::Application).

    Without more code, it is all just guesswork though...

Re: Seeking help with CGI::Application, please.
by johnnywang (Priest) on Feb 11, 2006 at 01:54 UTC
    How are you calling the cgi script? from a web page, I assume? you are probably setting the parameter "rm" as "start" in that page? that runmode is not defined.
      Thanks, but no. I'm invoking this application from a browser pointed at a file reading:

      #!/usr/bin/perl -wT use lib(qw{/home/hesco/sandbox/DistroPrsRls/lib}); use DistroPrsRls; BEGIN { print STDERR "\@INC includes: \n", join("\n", @INC), "\n"; } my $dpr = DistroPrsRls->new(); $dpr->run(); exit; 1;
      I'm not sure where this 'start' value is coming from.

      -- Hugh

        I'm not sure where this 'start' value is coming from.

        'start' is the default runmode (or 'start mode') that is used if no runmode parameter is provided in the request object. However, in your setup method, you have set the start_mode to 'mode1', so in the absense of a runmode parameter, it should load the 'mode1' runmode as the default.

        So somehow your 'setup' method is not being executed correctly.

        Wouldn't the mode value come from CGI then? Make sure you set a default run mode or the 'rm' parameter is present in the request. There should be detailed instructions in the CGI::Application perldoc. Wish you luck!

        Here's link to a tutorial that might help. Although, from a quick glance at your code, you seem to have done things right. Still, may be worth checking over. One immediate suggestion might be to try setting run mode parameter and default value after the code which defines all run modes:
        sub setup { 
          my $self = shift; 
          $self->run_modes( 
            'mode1' => 'Login', 
            'mode2' => 'DPR_Dashboard', 
            'mode3' => 'EnterPrsRls', 
            'mode4' => 'ApprovePrsRls', 
            'mode5' => 'ChooseLists', 
            'mode6' => 'ScheduleDistro', 
            'mode7' => 'AuthorizeDistro', 
            'mode8' => 'ReviewJobs' ); 
        
            $self->start_mode('mode1'); 
            $self->mode_param('rm'); 
        
          return 1; 
        }
        


        _____________________
        "We've all heard that a million monkeys banging on a million typewriters will eventually reproduce
        the entire works of Shakespeare. Now, thanks to the Internet, we know this is not true."

        Robert Wilensky, University of California

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (4)
As of 2024-12-12 17:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Which IDE have you been most impressed by?













    Results (65 votes). Check out past polls.