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. :-)
In reply to Re: CGI::Application same function code
by Tanktalus
in thread CGI::Application same function code
by boboson
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |