On Wed, Mar 28, 2018 at 2:39 PM, sri <
kra...@gmail.com> wrote:
>> That being said, I would ask to the collective wisdom of the group:
>>
>> 1. would proxy defined as explained in the cookboock work in templates?
>
>
> Technically, you can always do "<%= $c->my_helper_prefix->foo('bar') %>".
>
When I read this I started banging my head on the desk: I had
*completely missed* the paragraph in the rendering guide about the
controller being accessible
in the template scripts. Now that the headache has subsided, I can reply :)
Since the main reason I wanted 'structured' helpers was that I had two
helpers that logically should have had the same name but
where actually quite different. So I thought to introduce two helpers:
foo.foobar, to be used in the context of controller Foo to do foobnar,
and bar.foobar meant to do a different foobar in the context of
controller Bar.
What I did, was to define methods Foo::_foobar and Bar::_foobar and
then, in my app setup, define a single foobar helper with
$app->helper(foobar => sub {
my $c = shift;
return $c->_foobar(@_) if $c->$_can('_foobar');
# do something (e.g. croak) to handle the case were the
controller has no _foobar
});
I tried to define directly Foo::foobar and Bar::foobar, but I get something like
Undefined subroutine
&Mojo::Template::Sandbox::6bd05336357ba117d6ac9a329ea3a6ec::foobar
meaning there is something (well, more than some thing) that I do not
understand in how the functions are injected into the template object.
However, the solution above works for me, and I'm content :).
Obviously, I'm open to suggestion for better ways to do this.
cheers