> cannot see the anwser from Stefan Adams, has it been deleted ? (I got 
criticized for it ;-) )

Nope, Stefan Adams edited the code inline.

Henry Foolman, thanks for your detailed reply about authoring plugins -- 
appreciate it.  Unless I misunderstood your post completely, my question is 
really how to figure out the name of the helper function from within the 
helper, perhaps via some nested ref inside $self!?  I tried dumping it but 
quickly got lost, so wanted to see if the community is aware of a trick.  
Is that even possible?

On Wednesday, July 5, 2017 at 6:20:08 AM UTC-4, Henry Foolman wrote:
>
> Hi,
> i cannot see the anwser from Stefan Adams,
> has it been deleted ? (I got criticized for it ;-) )
> Anyhow, the best way is to create a plugin which you can use from 
> everywhere in your app.
>
> mojo generate plugin Test::Utils (gives you)
>   [mkdir] 
> /root/Plugins/Mojolicious-Plugin-Test-Utils/lib/Mojolicious/Plugin/Test
>   [write] 
> /root/Plugins/Mojolicious-Plugin-Test-Utils/lib/Mojolicious/Plugin/Test/Utils.pm
>   [mkdir] /root/Plugins/Mojolicious-Plugin-Test-Utils/t
>   [write] /root/Plugins/Mojolicious-Plugin-Test-Utils/t/basic.t
>   [exist] /root/Plugins/Mojolicious-Plugin-Test-Utils
>   [write] /root/Plugins/Mojolicious-Plugin-Test-Utils/Makefile.PL
>
> Than edit your Plugin:
> vi Mojolicious-Plugin-Test-Utils/lib/Mojolicious/Plugin/Test/Utils.pm
>
> E.g: Debug Logger:
>
> package Mojolicious::Plugin::Test::Utils;
> use Mojo::Base 'Mojolicious::Plugin';
>
> our $VERSION = '0.01';
>
> sub register {
>   my ($self, $app) = @_;
>
>
>   $app->helper(debug_logger => sub {
>       my $c = shift;
>
>       #debugging in hypnotoad
>       return Mojo::Log->new(path => '/var/log/debug.log', level => 'debug'
> );
>
>   });
>
> }
>
> 1;
>
>
> Then build it:
> cd Mojolicious-Plugin-Test-Utils
> perl Makefile.PL
> make
> make install
>
>
> Enable it in your app by loading it in yout startup routine:
> #init Utilities plugin
> $self->plugin( 'Test::Utils );
>
> Use it in your app or another helper:
>
> my $logger = $app->debug_logger;
> $logger->debug(sprintf("test\n" ));
>
> There's also a very good documentation on the website:
> You totally should read:
> http://mojolicious.org/perldoc/Mojolicious/Guides/Growing
> And:
> http://mojolicious.org/perldoc/Mojolicious/Guides/Cookbook
>
> Best regards
>
> Hans
>
>
>
> Am Dienstag, 4. Juli 2017 00:17:38 UTC+2 schrieb Beginner:
>>
>> Thanks.  That's certainly one way ... I am more curious if I can access 
>> the helper name from within the helper as my application has hundreds of 
>> helpers and I am trying to see if I can lookup the name from within the 
>> helper itself.  If there is no other way, I will fall back to your 
>> suggestion.
>>
>> On Monday, July 3, 2017 at 4:52:25 PM UTC-4, Stefan Adams wrote:
>>>
>>>
>>> On Mon, Jul 3, 2017 at 7:01 AM, Beginner <[email protected]> wrote:
>>>>
>>>> *my $helper = 'dummy';*
>>>
>>> helper *$helper* => sub { 
>>>>     my $self = shift;
>>>>     my $log = shift;
>>>>     *#**my $helper = "";* # XXX - how to determine the name 
>>>> dynamically?
>>>>
>>>>     my $time_start = $self->get_start_time();
>>>>
>>>>     $log->info({msg => "started helper $helper"});
>>>>     # .. Do something ..
>>>>     $elapsed = $self->get_elapsed_time($get_start_time);
>>>>     $log->info({msg => "completed helper $helper", took => $elapsed});
>>>> };
>>>
>>>
>>>
>>>

-- 
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 https://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.

Reply via email to