On Saturday, August 9, 2014 6:25:05 AM UTC-6, sri wrote:
>
> I'm afraid the nested_helpers proposal didn't get enough votes and had to
> be rejected. :(
>
I'm a late-comer to the party I realize, but I'm not in favor of the
proposed solution either. It feels and looks like a hack, and is barely
better than longer helper names. Lately I've been grouping my helpers into
classes with their own namespaces, then creating an instance of the class
and invoking it like an object. Something like this:
package My::Plugin::Frob;
use Mojo::Base 'Mojolicious::Plugin';
use Frob; ## the helper class
has 'frob'; ## this plugin's attribute
sub register {
my ($self, $app, $cfg) = @_;
$self->frob(Frob->new($cfg)); ## create an instance and assign to the
attribute
$app->helper(frob => sub { $self->frob }); ## make the helper
...
}
then elsewhere, say, in a controller:
$c->frob->some_method(...);
If there's a cleaner way to do this with less boilerplate, I'd be in favor
of that too, but this has worked very well for over a year.
Scott
--
You received this message because you are subscribed to the Google Groups
"Mojolicious" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.