You can call helpers right from the app.

#Lite
app->helper_name

#Full
$self->app->helper_name

You can also call them from controllers

#Lite
$c->helper_name

#Full
$self->helper_name

You can call them either way in controllers as well. If you need session 
data in the helper then it is best to use it from the controller. You will 
lose session data if you call from app but there are ways around it.


On Saturday, January 28, 2017 at 4:32:26 AM UTC-5, Pavel Serikov wrote:
>
> It's better to explain the problem on example. I'm writing bot for 
> Telegram and want to implement getting updates via WebHook and polling (via 
> Mojo::IOLoop) both.
>
> helper answer => sub {
>  my ($c, $update) = shift;
>  ...
>  if ($update->{message}{text} eq "something") {
>    $api->sendMessage ({ chat_id => $chat_id, text => '/shot - Get online 
> camera shot' });
>  }
> };
>
> ...
>
> post '/'.$config->{telegram_api_token} => sub {
>   my $c = shift;
>   my $update = $c->req->json;
>   $c->answer($update);
>   $c->render(json => "ok");
> };
>
> if ($config->{polling}) {
>  $api->deleteWebhook();
>
>  Mojo::IOLoop->recurring($config->{polling_timeout} => sub {
>    my $updates = $api->getUpdates;
>    my @updates = @{$updates->{result}};
>     
>    for my $u (@updates) {
>      app->controller_class->helpers->answer($u); ##### How to call helper 
> answer here ?
>    }
>  });
>
> }
>
> Is there any way to execute helper 'answer' outside the routes or I need 
> to move project from Mojolicious::Lite to Mojolicious ?
>

-- 
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