Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: CGI::Application with 'main' runmodes and 'sub' runmodes

by Arunbear (Prior)
on Apr 28, 2007 at 15:46 UTC ( [id://612565]=note: print w/replies, xml ) Need Help??


in reply to CGI::Application with 'main' runmodes and 'sub' runmodes

CGI::Application::Dispatch was created to help you with problems like this so e.g. instead of your App::Main you'd have an invocation script like:
#!/usr/bin/perl use strict; use CGI::Application::Dispatch; CGI::Application::Dispatch->dispatch( prefix => 'App', default => 'one', );
This should do what you want (including the path info dispatch), but CGI::Application::Dispatch has lots more configuration options should you need more power.

Having said this, I now prefer CGI::Prototype over CGI::App, beacuse with CGI::Prototype, run modes are handled by classes so each of your two dozen (and growing) run modes would live in its own small module. I find this makes the application a lot more manageable as it increases in size.

Replies are listed 'Best First'.
Re^2: CGI::Application with 'main' runmodes and 'sub' runmodes
by Rhandom (Curate) on Apr 28, 2007 at 20:17 UTC
    I second the vote for CGI::Prototype. I'd also suggest looking at CGI::Ex::App. It lets you choose if you want some run modes handled by other classes, or handled by locally.

    #!/usr/bin/perl package Foo; use strict; use warnings; use base qw(CGI::Ex::App); Foo->new->navigate; exit; sub base_dir_abs { '/var/www/templates' } ### tell the application to ### look for a module to handle each run mode (step) sub allow_morph { 1 } { # This could be in its own file - or # embedded in here is fine # you can get here by going to # /cgi-bin/my_cgi # or /cgi-bin/my_cgi/main # or /cgi-bin/my_cgi?step=main package Foo::Main; sub file_print { return \ <<'HERE'; <h1>Step Main</h1> This is the default run mode. You said [% hello %]. HERE sub hash_swap { return {hello => "I'm main!"}; } } # end of Foo::Main # you get to step2 by calling # /cgi-bin/my_cgi?step=step2 # or # /cgi-bin/my_cgi/step2 # these methods are just sitting the the Foo class sub step2_file_print { return \ <<'HERE'; <h1>I'm in step 2</h1> You said [% hello %]. HERE sub step2_hash_swap { return {hello => 'Hello Step2'}; } # uncomment for a trace of which methods were looked for # sub post_navigate { # use CGI::Ex::Dump qw(debug); # debug shift->dump_history; #}


    my @a=qw(random brilliant braindead); print $a[rand(@a)];

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (5)
As of 2024-04-19 03:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found