Jamie Krasnoo wrote:
> Ok I have a quick question on setup when you're sub classing CGI::App.
>
> If I want to be able to specify standard run modes, and mode_params
> without having to overload the setup function each time I use it. How
> does that work?
This is just typically done by calling SUPER::setup() in your overloaded setup()
function.
> In the super class:
>
> sub setup {
> my $self = shift;
>
> # get the runmode from the path info.
> $self->mode_param(
> 'path_info' => -1
> );
That probably should be in cgiapp_init, not setup.
> # Define the default starting runmode (usualy home)
> $self->start_mode('home');
>
> # Define the runmodes. This maps all the runmodes to functions
> $self->run_modes(
> 'home' => 'home',
> 'user' => 'user',
> )
> }
>
> In the application
>
> sub setup {
> my $self = shift;
>
This is where you'd typically put something like:
$self->SUPER::setup();
> # Adding this runmode to the standard ones.
> my $self->run_modes(
> 'signup' => 'signup'
> );
> }
>
> Or should I not even bother to define setup in the super class and
> just define it in the sub class each time? What would be the best way
> to do this?
One of the reasons that run_modes is cummulative is that lot's of people do what
you're describing. Sometimes though I like to use the new callback hooks to do
the same thing at the setup stage without having to have my child classes worry
about calling the base classes setup method.
in your base class:
__PACKAGE__->add_callback('setup' => \&my_setup_method);
--
Michael Peters
Developer
Plus Three, LP
---------------------------------------------------------------------
Web Archive: http://www.mail-archive.com/[email protected]/
http://marc.theaimsgroup.com/?l=cgiapp&r=1&w=2
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]