Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
I'm working on a CGI::App that is growing like topsy. The list of runmodes has past a dozen and is veering crazily toward two.

I remembered dragonchilds comment "every major subsystem... (would) have their own C::A". He posted some code to show how that might be done

I hit some snags implementing it, here is what I finaly came up with.

Main.pm

package App::Main; use strict; use warnings; use base qw{CGI::Application}; use App::One; use App::Two; sub setup { my ($self) = @_; $self->start_mode('one'); $self->mode_param(path_info => 1); $self->run_modes([qw{ one two }] ); } sub one { my ($self) = @_; my $one = App::One->new; $one->run; exit; #$self->header_type('none'); } sub two { my ($self) = @_; my $two = App::Two->new; $two->run; exit; #$self->header_type('none'); } 1;
One.pm
package App::One; use strict; use warnings; use base qw{CGI::Application}; sub cgiapp_init { my $self = shift; $self->tmpl_path(q{tmpl}); } sub setup { my ($self) = @_; $self->mode_param(path_info => 2); $self->start_mode('one_a'); $self->run_modes([qw( one_a one_b )]); } sub one_a{ my ($self) = @_; my $tmpl = $self->load_tmpl; return $tmpl->output; } sub one_b{ my ($self) = @_; my $tmpl = $self->load_tmpl; return $tmpl->output; } 1;
Two.pm would be along similar lines. The instance script would be something like
#!C:/Perl/bin/perl.exe use strict; use warnings; use lib qw{ /www/local/sw/admin/lib }; use App::Main; my $top = App::Main->new; $top->run;
The Main.pm runmodes create new C::A objects. I've used the $self->mode_param(path_info => n); (where n tells C::A which part of path_info to use) to establish which runmode to use. So

index.cgi/one/one_a
will get us to 'main' runmode 'one', 'sub runmode' 'one_a'.

I'll now be able to develope/test each 'main runmode' separately and things should go more smoothly (I said 'should'!).

One point though, in Main.pm I've had to include exit; at the end of each method. Because of the way C::A works the header will have already been added/sent. Just having a return would mean another header would be added. Interestingly, $self->header('none') did what it says on the tin but tacked on the word 'none' to the end of the ouput (after, in this case, the closing html tag).

What do the monks think about the general approach? Worth pursuing or are there pitfalls and traps ahead?


In reply to CGI::Application with 'main' runmodes and 'sub' runmodes by wfsp

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (4)
As of 2022-05-17 18:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you prefer to work remotely?



    Results (68 votes). Check out past polls.

    Notices?