tomred has asked for the wisdom of the Perl Monks concerning the following question:
Scope is not an issue in this context as far as I can tell.sub myaction : Chained('.') PathPart('myaction') POST { my ( $self, $c ) = @_; my $form = MyApp::Form->new; $form->process(params => $c->req->body_params); my $error_sub = sub { $c->response->status(400); $c->stash( results => { form => $form->render, }, ); $c->detach(); }; if ( $form->is_valid ) { try { $form->update_model; } catch($e) { $form->add_form_error($e); $error_sub->(); }; } else { $error_sub->(); } }
Would I be save a CPU cycle or a byte of RAM using lexical subs, or is there any other benefits? Thanks in advance, Dermotmy sub error { $c->response->status(400); $c->stash( results => { form => $form->render, }, ); $c->detach(); }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: lexical sub vs subroutine reference
by dave_the_m (Monsignor) on Jul 26, 2024 at 11:24 UTC | |
by eyepopslikeamosquito (Archbishop) on Jul 26, 2024 at 12:16 UTC | |
by NERDVANA (Priest) on Jul 26, 2024 at 14:21 UTC | |
by haj (Vicar) on Jul 26, 2024 at 19:37 UTC |