in reply to CGI::Application same function code
is one way. Another is to reverse it. The setup stays the same as you have now, but create a new function to do the actual output:$self->run_modes( start => sub { shift->_runmode('start'); }, middle => sub { shift->_runmode('middle'); }, end => sub { shift->_runmode('end'); }, ); # ... sub _runmode { my $self = shift; my $html = shift; my $dbh = $self->param('dbh'); #.... my $tmpl_sub = $self->load_tmpl($html . '.phtml'); #... }
The latter is close to how I do it.sub showStart { my $self = shift; # function specific code ... return $self->display_tmpl( file => 'start.phtml', # other parms ); } sub display_tmpl { my $self = shift; my %opts = shift; my $tmpl = $self->load_tmpl('main.phtml'); my $tmpl_sub = $self->load_tmpl($opts{file}); #... use other parms... $tmpl->param(tmpl_sub => $tmpl_sub->output()); return $tmpl->output(); }
Update:Missed my open-code tag. Fixed.
Update:Oh, and a couple other monks alerted me to the previous update ... just as I was noticing/fixing, but thanks to those who politely smacked me in private. :-)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: CGI::Application same function code
by boboson (Monk) on Feb 13, 2005 at 11:50 UTC | |
by Tanktalus (Canon) on Feb 13, 2005 at 16:05 UTC |