Re: [Mojolicious] Async/await in Mojolicious Full App

2020-06-18 Thread Jeyaraj Durairaj
Hi,

Just to share that I have successfully deployed Mojolicious (Full App) 
based BI application in production with Hynotoad along with Async/Await 
feature, DBIx:Class model layer, Mojo::Pg Model layer, API calls with 
Mojo::UserAgent (with Async/Await).

Mojo::Test feature is also amazing.


Special thanks to Luc Didry
for the following link which has helped me in deployment.

https://mojolicious.io/blog/2018/12/22/use-carton-for-your-mojolicious-app-deployment/


-- Jeyaraj

On Saturday, 6 June 2020 19:17:05 UTC+5:30, Jeyaraj Durairaj wrote:
>
> Honored to receive answers and responses from experts in the first place.
> Your tips and ideas are indeed essential to me.
>
> Happy to be in Mojolicious discussions and sharing ideas!
>
> -- Jeyaraj
>
> On Saturday, 6 June 2020 19:11:47 UTC+5:30, Stefan Adams wrote:
>>
>> *form *and *json *are examples of "content generators 
>> ".  
>> You can think of them as request macros.  *form 
>> *, for 
>> example, "generates query string, application/x-www-form-urlencoded or 
>> multipart/form-data content" while *json*, for example, "generates 
>> application/json content with Mojo::JSON."
>>
>> So, true, changing the content generator as I recommended changes how the 
>> request is sent to the server.  But you can also create your own custom 
>> generators if you need to, such as an application/x-www-form-urlencoded 
>> content expecting a JSON value for a form parameter as yours seems to 
>> expect.
>>
>> Indeed, without knowing anything about your API, I recommended a change 
>> for how you send your request, completely blindly and contrary to what the 
>> API endpoint may be expecting.  I assumed the API endpoint would handle a 
>> JSON request, but instead it seems to want a JSON string as the value to 
>> the *periods* parameter of the form.
>>
>> On Sat, Jun 6, 2020 at 5:50 AM Jeyaraj Durairaj  
>> wrote:
>>
>>> Hi Stefan,
>>>
>>> Thanks for the appreciation and the ideas.
>>>
>>> I will surely do the following change in my code.
>>>
>>> changing to return *$tx->result->json*; from  return 
>>> from_json($tx->result->body); 
>>>
>>> However, following change has been tricky to me.
>>>
>>> changing to  *json* => { periods => *$c->session('cx_current_quarter')*
>>>  },  from  form => { periods => encode_json([ 
>>> $c->session('cx_current_quarter') 
>>> ]) },
>>>
>>>  I, per se, tried *json* => { periods => 
>>> *$c->session('cx_current_quarter')* } at the outset. It did not work.
>>>
>>> The reason I found is the following:
>>>
>>> "json =>" works for the API call without "Authorization Header"
>>> my $tx = await $ua->post_p('http://' . $c->config->{API_IP} . 
>>> '/api/token/refresh/' => json => { refresh => $refresh_token });
>>>
>>> only "form =>" works for the API call with Authorization Header" 
>>> $tx = await $ua->post_p(
>>> 'http://' . $c->config->{API_IP} . 
>>> '/api-app/analytics/summary/',
>>> { Authorization => 'Bearer ' . $access_token },
>>> *form *=> { periods => *$c->session('cx_current_quarter')*
>>>  }, 
>>> );
>>>
>>> The difference between json and form in this context was intentional or 
>>> accidental. More comments on this will be appreciated!
>>>
>>> Thanks.
>>> -- Jeyaraj
>>>
>>>
>>>
>>> On Saturday, 6 June 2020 02:55:04 UTC+5:30, Stefan Adams wrote:

 Great job pushing your application forward with Async/Await!  Looking 
 at your snippet, here's one small change you can probably make using the 
 json() 
 method from Mojo::Message 
 :

 $app->helper(summary_data => async sub ($c, $access_token) {
 my $ua = Mojo::UserAgent->new;

 my $tx = await $ua->post_p(
 'http://' . $c->config->{API_IP} . 
 '/api-app/analytics/summary/',
 { Authorization => 'Bearer ' . $access_token },
 *json* => { periods => *$c->session('cx_current_quarter')* 
 }, 
 );
 if ($tx->result->is_success) {
 return *$tx->result->json*;
 }
 $c->flash(message_type => 'warning');
 $c->flash(message => 'Could not get summary data');
 return $c->redirect_to('cx-summary', status => 403);
 });



 On Thu, Jun 4, 2020 at 2:31 AM Jeyaraj Durairaj  
 wrote:

> Hi,
>
> It works for *helpers* as well with the following declaration.
>
> $app->helper(summary_data => async sub ($c, $access_token) {
> my $ua = Mojo::UserAgent->new;
>
> my $tx = await $ua->post_p(
> 'http://' . $c->config->{API_IP} . 
> '/api-app/analytics/summary/',
> { Authorization => 'Bearer ' . $access_token },
> form => { periods => encode_json([ 
>

Re: [Mojolicious] Async/await in Mojolicious Full App

2020-06-06 Thread Jeyaraj Durairaj
Honored to receive answers and responses from experts in the first place.
Your tips and ideas are indeed essential to me.

Happy to be in Mojolicious discussions and sharing ideas!

-- Jeyaraj

On Saturday, 6 June 2020 19:11:47 UTC+5:30, Stefan Adams wrote:
>
> *form *and *json *are examples of "content generators 
> ".  
> You can think of them as request macros.  *form 
> *, for 
> example, "generates query string, application/x-www-form-urlencoded or 
> multipart/form-data content" while *json*, for example, "generates 
> application/json content with Mojo::JSON."
>
> So, true, changing the content generator as I recommended changes how the 
> request is sent to the server.  But you can also create your own custom 
> generators if you need to, such as an application/x-www-form-urlencoded 
> content expecting a JSON value for a form parameter as yours seems to 
> expect.
>
> Indeed, without knowing anything about your API, I recommended a change 
> for how you send your request, completely blindly and contrary to what the 
> API endpoint may be expecting.  I assumed the API endpoint would handle a 
> JSON request, but instead it seems to want a JSON string as the value to 
> the *periods* parameter of the form.
>
> On Sat, Jun 6, 2020 at 5:50 AM Jeyaraj Durairaj  > wrote:
>
>> Hi Stefan,
>>
>> Thanks for the appreciation and the ideas.
>>
>> I will surely do the following change in my code.
>>
>> changing to return *$tx->result->json*; from  return 
>> from_json($tx->result->body); 
>>
>> However, following change has been tricky to me.
>>
>> changing to  *json* => { periods => *$c->session('cx_current_quarter')*
>>  },  from  form => { periods => encode_json([ 
>> $c->session('cx_current_quarter') 
>> ]) },
>>
>>  I, per se, tried *json* => { periods => 
>> *$c->session('cx_current_quarter')* } at the outset. It did not work.
>>
>> The reason I found is the following:
>>
>> "json =>" works for the API call without "Authorization Header"
>> my $tx = await $ua->post_p('http://' . $c->config->{API_IP} . 
>> '/api/token/refresh/' => json => { refresh => $refresh_token });
>>
>> only "form =>" works for the API call with Authorization Header" 
>> $tx = await $ua->post_p(
>> 'http://' . $c->config->{API_IP} . 
>> '/api-app/analytics/summary/',
>> { Authorization => 'Bearer ' . $access_token },
>> *form *=> { periods => *$c->session('cx_current_quarter')*
>>  }, 
>> );
>>
>> The difference between json and form in this context was intentional or 
>> accidental. More comments on this will be appreciated!
>>
>> Thanks.
>> -- Jeyaraj
>>
>>
>>
>> On Saturday, 6 June 2020 02:55:04 UTC+5:30, Stefan Adams wrote:
>>>
>>> Great job pushing your application forward with Async/Await!  Looking at 
>>> your snippet, here's one small change you can probably make using the 
>>> json() 
>>> method from Mojo::Message 
>>> :
>>>
>>> $app->helper(summary_data => async sub ($c, $access_token) {
>>> my $ua = Mojo::UserAgent->new;
>>>
>>> my $tx = await $ua->post_p(
>>> 'http://' . $c->config->{API_IP} . 
>>> '/api-app/analytics/summary/',
>>> { Authorization => 'Bearer ' . $access_token },
>>> *json* => { periods => *$c->session('cx_current_quarter')* 
>>> }, 
>>> );
>>> if ($tx->result->is_success) {
>>> return *$tx->result->json*;
>>> }
>>> $c->flash(message_type => 'warning');
>>> $c->flash(message => 'Could not get summary data');
>>> return $c->redirect_to('cx-summary', status => 403);
>>> });
>>>
>>>
>>>
>>> On Thu, Jun 4, 2020 at 2:31 AM Jeyaraj Durairaj  
>>> wrote:
>>>
 Hi,

 It works for *helpers* as well with the following declaration.

 $app->helper(summary_data => async sub ($c, $access_token) {
 my $ua = Mojo::UserAgent->new;

 my $tx = await $ua->post_p(
 'http://' . $c->config->{API_IP} . 
 '/api-app/analytics/summary/',
 { Authorization => 'Bearer ' . $access_token },
 form => { periods => encode_json([ 
 $c->session('cx_current_quarter') ]) }, 
 );
 if ($tx->result->is_success) {
 return from_json($tx->result->body);
 }
 $c->flash(message_type => 'warning');
 $c->flash(message => 'Could not get summary data');
 return $c->redirect_to('cx-summary', status => 403);
 });




 -- Jeyaraj

 On Thursday, 4 June 2020 12:06:01 UTC+5:30, Jeyaraj Durairaj wrote:
>
> Hi,
>
> Eureka! Eureka! It works!.
>
> The solution I found (because of my error) is that I uninstalled 
> Mojo::AsyncAwait and installed Future::AsyncAwait.

Re: [Mojolicious] Async/await in Mojolicious Full App

2020-06-06 Thread Stefan Adams
*form *and *json *are examples of "content generators
".
You can think of them as request macros.  *form
*, for
example, "generates query string, application/x-www-form-urlencoded or
multipart/form-data content" while *json*, for example, "generates
application/json content with Mojo::JSON."

So, true, changing the content generator as I recommended changes how the
request is sent to the server.  But you can also create your own custom
generators if you need to, such as an application/x-www-form-urlencoded
content expecting a JSON value for a form parameter as yours seems to
expect.

Indeed, without knowing anything about your API, I recommended a change for
how you send your request, completely blindly and contrary to what the API
endpoint may be expecting.  I assumed the API endpoint would handle a JSON
request, but instead it seems to want a JSON string as the value to the
*periods* parameter of the form.

On Sat, Jun 6, 2020 at 5:50 AM Jeyaraj Durairaj 
wrote:

> Hi Stefan,
>
> Thanks for the appreciation and the ideas.
>
> I will surely do the following change in my code.
>
> changing to return *$tx->result->json*; from  return
> from_json($tx->result->body);
>
> However, following change has been tricky to me.
>
> changing to  *json* => { periods => *$c->session('cx_current_quarter')*
>  },  from  form => { periods => encode_json([ 
> $c->session('cx_current_quarter')
> ]) },
>
>  I, per se, tried *json* => { periods =>
> *$c->session('cx_current_quarter')* } at the outset. It did not work.
>
> The reason I found is the following:
>
> "json =>" works for the API call without "Authorization Header"
> my $tx = await $ua->post_p('http://' . $c->config->{API_IP} .
> '/api/token/refresh/' => json => { refresh => $refresh_token });
>
> only "form =>" works for the API call with Authorization Header"
> $tx = await $ua->post_p(
> 'http://' . $c->config->{API_IP} .
> '/api-app/analytics/summary/',
> { Authorization => 'Bearer ' . $access_token },
> *form *=> { periods => *$c->session('cx_current_quarter')* },
> );
>
> The difference between json and form in this context was intentional or
> accidental. More comments on this will be appreciated!
>
> Thanks.
> -- Jeyaraj
>
>
>
> On Saturday, 6 June 2020 02:55:04 UTC+5:30, Stefan Adams wrote:
>>
>> Great job pushing your application forward with Async/Await!  Looking at
>> your snippet, here's one small change you can probably make using the json()
>> method from Mojo::Message
>> :
>>
>> $app->helper(summary_data => async sub ($c, $access_token) {
>> my $ua = Mojo::UserAgent->new;
>>
>> my $tx = await $ua->post_p(
>> 'http://' . $c->config->{API_IP} .
>> '/api-app/analytics/summary/',
>> { Authorization => 'Bearer ' . $access_token },
>> *json* => { periods => *$c->session('cx_current_quarter')*
>> },
>> );
>> if ($tx->result->is_success) {
>> return *$tx->result->json*;
>> }
>> $c->flash(message_type => 'warning');
>> $c->flash(message => 'Could not get summary data');
>> return $c->redirect_to('cx-summary', status => 403);
>> });
>>
>>
>>
>> On Thu, Jun 4, 2020 at 2:31 AM Jeyaraj Durairaj 
>> wrote:
>>
>>> Hi,
>>>
>>> It works for *helpers* as well with the following declaration.
>>>
>>> $app->helper(summary_data => async sub ($c, $access_token) {
>>> my $ua = Mojo::UserAgent->new;
>>>
>>> my $tx = await $ua->post_p(
>>> 'http://' . $c->config->{API_IP} .
>>> '/api-app/analytics/summary/',
>>> { Authorization => 'Bearer ' . $access_token },
>>> form => { periods => encode_json([
>>> $c->session('cx_current_quarter') ]) },
>>> );
>>> if ($tx->result->is_success) {
>>> return from_json($tx->result->body);
>>> }
>>> $c->flash(message_type => 'warning');
>>> $c->flash(message => 'Could not get summary data');
>>> return $c->redirect_to('cx-summary', status => 403);
>>> });
>>>
>>>
>>>
>>>
>>> -- Jeyaraj
>>>
>>> On Thursday, 4 June 2020 12:06:01 UTC+5:30, Jeyaraj Durairaj wrote:

 Hi,

 Eureka! Eureka! It works!.

 The solution I found (because of my error) is that I uninstalled
 Mojo::AsyncAwait and installed Future::AsyncAwait.
 It just works!

 By June end, my business intelligence application will be live to serve
 100+ users with insights and analytics.

 (To apply icing on the cake, I have plugged in Moose also in to model
 layer for my application)

 As Glen Hinkle said, it is really really a fun to work in Mojolicious.
 I love Hypnotoad.

 BTW, I am doing a private project as well to help a home designer to
 launch a w

Re: [Mojolicious] Async/await in Mojolicious Full App

2020-06-06 Thread Jeyaraj Durairaj
Hi Stefan,

Thanks for the appreciation and the ideas.

I will surely do the following change in my code.

changing to return *$tx->result->json*; from  return 
from_json($tx->result->body); 

However, following change has been tricky to me.

changing to  *json* => { periods => *$c->session('cx_current_quarter')* }, 
 from  form => { periods => encode_json([ $c->session('cx_current_quarter') 
]) },

 I, per se, tried *json* => { periods => *$c->session('cx_current_quarter')*
 } at the outset. It did not work.

The reason I found is the following:

"json =>" works for the API call without "Authorization Header"
my $tx = await $ua->post_p('http://' . $c->config->{API_IP} . 
'/api/token/refresh/' => json => { refresh => $refresh_token });

only "form =>" works for the API call with Authorization Header" 
$tx = await $ua->post_p(
'http://' . $c->config->{API_IP} . 
'/api-app/analytics/summary/',
{ Authorization => 'Bearer ' . $access_token },
*form *=> { periods => *$c->session('cx_current_quarter')* }, 
);

The difference between json and form in this context was intentional or 
accidental. More comments on this will be appreciated!

Thanks.
-- Jeyaraj



On Saturday, 6 June 2020 02:55:04 UTC+5:30, Stefan Adams wrote:
>
> Great job pushing your application forward with Async/Await!  Looking at 
> your snippet, here's one small change you can probably make using the json() 
> method from Mojo::Message 
> :
>
> $app->helper(summary_data => async sub ($c, $access_token) {
> my $ua = Mojo::UserAgent->new;
>
> my $tx = await $ua->post_p(
> 'http://' . $c->config->{API_IP} . 
> '/api-app/analytics/summary/',
> { Authorization => 'Bearer ' . $access_token },
> *json* => { periods => *$c->session('cx_current_quarter')* }, 
> );
> if ($tx->result->is_success) {
> return *$tx->result->json*;
> }
> $c->flash(message_type => 'warning');
> $c->flash(message => 'Could not get summary data');
> return $c->redirect_to('cx-summary', status => 403);
> });
>
>
>
> On Thu, Jun 4, 2020 at 2:31 AM Jeyaraj Durairaj  > wrote:
>
>> Hi,
>>
>> It works for *helpers* as well with the following declaration.
>>
>> $app->helper(summary_data => async sub ($c, $access_token) {
>> my $ua = Mojo::UserAgent->new;
>>
>> my $tx = await $ua->post_p(
>> 'http://' . $c->config->{API_IP} . 
>> '/api-app/analytics/summary/',
>> { Authorization => 'Bearer ' . $access_token },
>> form => { periods => encode_json([ 
>> $c->session('cx_current_quarter') ]) }, 
>> );
>> if ($tx->result->is_success) {
>> return from_json($tx->result->body);
>> }
>> $c->flash(message_type => 'warning');
>> $c->flash(message => 'Could not get summary data');
>> return $c->redirect_to('cx-summary', status => 403);
>> });
>>
>>
>>
>>
>> -- Jeyaraj
>>
>> On Thursday, 4 June 2020 12:06:01 UTC+5:30, Jeyaraj Durairaj wrote:
>>>
>>> Hi,
>>>
>>> Eureka! Eureka! It works!.
>>>
>>> The solution I found (because of my error) is that I uninstalled 
>>> Mojo::AsyncAwait and installed Future::AsyncAwait.
>>> It just works!
>>>
>>> By June end, my business intelligence application will be live to serve 
>>> 100+ users with insights and analytics.
>>>
>>> (To apply icing on the cake, I have plugged in Moose also in to model 
>>> layer for my application)
>>>
>>> As Glen Hinkle said, it is really really a fun to work in Mojolicious. I 
>>> love Hypnotoad.
>>>
>>> BTW, I am doing a private project as well to help a home designer to 
>>> launch a web site for their small firm. Guess! what framework I am gonna 
>>> use.. *Mojolicious.*
>>>
>>> Thanks to Mojo group and special thanks to SRI as well.
>>>
>>> -- Jeyaraj
>>>
>>>
>>>
>>> On Thursday, 28 May 2020 14:15:04 UTC+5:30, Jeyaraj Durairaj wrote:

 any luck on the solutions?

 -- Jeyaraj

 On Thursday, 28 May 2020 00:10:48 UTC+5:30, Jeyaraj Durairaj wrote:
>
> However, the below code perfectly work for me outside Mojolicious App.
>
>
> use Modern::Perl;
> use Mojo::Base -strict, -signatures;
> use Mojo::UserAgent;
> use Mojo::Promise;
> use Mojo::IOLoop;
> use Mojo::Util 'trim';
> use Mojo::AsyncAwait;
> use LWP::UserAgent;
> use JSON;
>
>
> my $ua = Mojo::UserAgent->new;
> my $result = $ua->post('http://localhost:8000/api/token/' => json => 
> { username => 'username', password => 'mypassword' })
> ->result
> ->json;
> my $access_token = $result->{access};
> my $refresh_token = $result->{refresh};
> print "Access Token: " . $result->{access}, "\n";
> print "Refresh Token: " . $result->{refresh}, "\n\n";
>
>
> $ua = Mojo::UserAgent->new;
> $result =

Re: [Mojolicious] Async/await in Mojolicious Full App

2020-06-05 Thread Stefan Adams
Great job pushing your application forward with Async/Await!  Looking at
your snippet, here's one small change you can probably make using the json()
method from Mojo::Message
:

$app->helper(summary_data => async sub ($c, $access_token) {
my $ua = Mojo::UserAgent->new;

my $tx = await $ua->post_p(
'http://' . $c->config->{API_IP} .
'/api-app/analytics/summary/',
{ Authorization => 'Bearer ' . $access_token },
*json* => { periods => *$c->session('cx_current_quarter')* },
);
if ($tx->result->is_success) {
return *$tx->result->json*;
}
$c->flash(message_type => 'warning');
$c->flash(message => 'Could not get summary data');
return $c->redirect_to('cx-summary', status => 403);
});



On Thu, Jun 4, 2020 at 2:31 AM Jeyaraj Durairaj 
wrote:

> Hi,
>
> It works for *helpers* as well with the following declaration.
>
> $app->helper(summary_data => async sub ($c, $access_token) {
> my $ua = Mojo::UserAgent->new;
>
> my $tx = await $ua->post_p(
> 'http://' . $c->config->{API_IP} .
> '/api-app/analytics/summary/',
> { Authorization => 'Bearer ' . $access_token },
> form => { periods => encode_json([
> $c->session('cx_current_quarter') ]) },
> );
> if ($tx->result->is_success) {
> return from_json($tx->result->body);
> }
> $c->flash(message_type => 'warning');
> $c->flash(message => 'Could not get summary data');
> return $c->redirect_to('cx-summary', status => 403);
> });
>
>
>
>
> -- Jeyaraj
>
> On Thursday, 4 June 2020 12:06:01 UTC+5:30, Jeyaraj Durairaj wrote:
>>
>> Hi,
>>
>> Eureka! Eureka! It works!.
>>
>> The solution I found (because of my error) is that I uninstalled
>> Mojo::AsyncAwait and installed Future::AsyncAwait.
>> It just works!
>>
>> By June end, my business intelligence application will be live to serve
>> 100+ users with insights and analytics.
>>
>> (To apply icing on the cake, I have plugged in Moose also in to model
>> layer for my application)
>>
>> As Glen Hinkle said, it is really really a fun to work in Mojolicious. I
>> love Hypnotoad.
>>
>> BTW, I am doing a private project as well to help a home designer to
>> launch a web site for their small firm. Guess! what framework I am gonna
>> use.. *Mojolicious.*
>>
>> Thanks to Mojo group and special thanks to SRI as well.
>>
>> -- Jeyaraj
>>
>>
>>
>> On Thursday, 28 May 2020 14:15:04 UTC+5:30, Jeyaraj Durairaj wrote:
>>>
>>> any luck on the solutions?
>>>
>>> -- Jeyaraj
>>>
>>> On Thursday, 28 May 2020 00:10:48 UTC+5:30, Jeyaraj Durairaj wrote:

 However, the below code perfectly work for me outside Mojolicious App.


 use Modern::Perl;
 use Mojo::Base -strict, -signatures;
 use Mojo::UserAgent;
 use Mojo::Promise;
 use Mojo::IOLoop;
 use Mojo::Util 'trim';
 use Mojo::AsyncAwait;
 use LWP::UserAgent;
 use JSON;


 my $ua = Mojo::UserAgent->new;
 my $result = $ua->post('http://localhost:8000/api/token/' => json => {
 username => 'username', password => 'mypassword' })
 ->result
 ->json;
 my $access_token = $result->{access};
 my $refresh_token = $result->{refresh};
 print "Access Token: " . $result->{access}, "\n";
 print "Refresh Token: " . $result->{refresh}, "\n\n";


 $ua = Mojo::UserAgent->new;
 $result = $ua->post('http://' . 'localhost:8000' .
 '/api/token/refresh/' => json => { refresh => $refresh_token })
 ->result
 ->json;


 my $agent = Mojo::UserAgent->new;
 async post_user_p => sub ($url) {
 say "\n\n", $url;
 my $tx = await $agent->post_p(
 $url,
 {
 Authorization => 'Bearer ' . $result->{access},
 },
 form => {"username" => "username"},

 );
 return trim from_json($tx->result->body)->{first_name};
 };

 async main => sub (@urls) {
 my @promises = map { post_user_p($_) } @urls;
 my @names = await Mojo::Promise->all(@promises);
 say for map { $_->[0] } @names;
 };

 my @urls = (qw(
 http://localhost:8000/api-converge/auth/user/
 ));

 main(@urls)->wait;




 On Wednesday, 27 May 2020 23:41:27 UTC+5:30, Jeyaraj Durairaj wrote:
>
> I tried generating an example app and copied pasted the code segment
> you posted here and then tried.
>
> "Action not found!" error is shown.
>
> Should I reinstall Perl again and then try?
> Will it work under morbo or works only on Hypnotoad?
> I am using Windows for my development, wherein morbo is the only
> server I can test.
> Or can I test it on daemon mode and try>
> Please sugge

Re: [Mojolicious] Async/await in Mojolicious Full App

2020-06-04 Thread Jeyaraj Durairaj
Hi,

It works for *helpers* as well with the following declaration.

$app->helper(summary_data => async sub ($c, $access_token) {
my $ua = Mojo::UserAgent->new;

my $tx = await $ua->post_p(
'http://' . $c->config->{API_IP} . 
'/api-app/analytics/summary/',
{ Authorization => 'Bearer ' . $access_token },
form => { periods => encode_json([ 
$c->session('cx_current_quarter') ]) }, 
);
if ($tx->result->is_success) {
return from_json($tx->result->body);
}
$c->flash(message_type => 'warning');
$c->flash(message => 'Could not get summary data');
return $c->redirect_to('cx-summary', status => 403);
});




-- Jeyaraj

On Thursday, 4 June 2020 12:06:01 UTC+5:30, Jeyaraj Durairaj wrote:
>
> Hi,
>
> Eureka! Eureka! It works!.
>
> The solution I found (because of my error) is that I uninstalled 
> Mojo::AsyncAwait and installed Future::AsyncAwait.
> It just works!
>
> By June end, my business intelligence application will be live to serve 
> 100+ users with insights and analytics.
>
> (To apply icing on the cake, I have plugged in Moose also in to model 
> layer for my application)
>
> As Glen Hinkle said, it is really really a fun to work in Mojolicious. I 
> love Hypnotoad.
>
> BTW, I am doing a private project as well to help a home designer to 
> launch a web site for their small firm. Guess! what framework I am gonna 
> use.. *Mojolicious.*
>
> Thanks to Mojo group and special thanks to SRI as well.
>
> -- Jeyaraj
>
>
>
> On Thursday, 28 May 2020 14:15:04 UTC+5:30, Jeyaraj Durairaj wrote:
>>
>> any luck on the solutions?
>>
>> -- Jeyaraj
>>
>> On Thursday, 28 May 2020 00:10:48 UTC+5:30, Jeyaraj Durairaj wrote:
>>>
>>> However, the below code perfectly work for me outside Mojolicious App.
>>>
>>>
>>> use Modern::Perl;
>>> use Mojo::Base -strict, -signatures;
>>> use Mojo::UserAgent;
>>> use Mojo::Promise;
>>> use Mojo::IOLoop;
>>> use Mojo::Util 'trim';
>>> use Mojo::AsyncAwait;
>>> use LWP::UserAgent;
>>> use JSON;
>>>
>>>
>>> my $ua = Mojo::UserAgent->new;
>>> my $result = $ua->post('http://localhost:8000/api/token/' => json => { 
>>> username => 'username', password => 'mypassword' })
>>> ->result
>>> ->json;
>>> my $access_token = $result->{access};
>>> my $refresh_token = $result->{refresh};
>>> print "Access Token: " . $result->{access}, "\n";
>>> print "Refresh Token: " . $result->{refresh}, "\n\n";
>>>
>>>
>>> $ua = Mojo::UserAgent->new;
>>> $result = $ua->post('http://' . 'localhost:8000' . '/api/token/refresh/' 
>>> => json => { refresh => $refresh_token })
>>> ->result
>>> ->json;
>>>
>>>
>>> my $agent = Mojo::UserAgent->new;
>>> async post_user_p => sub ($url) {
>>> say "\n\n", $url;
>>> my $tx = await $agent->post_p(
>>> $url,
>>> {
>>> Authorization => 'Bearer ' . $result->{access},
>>> },
>>> form => {"username" => "username"}, 
>>>
>>> );
>>> return trim from_json($tx->result->body)->{first_name};
>>> };
>>>
>>> async main => sub (@urls) {
>>> my @promises = map { post_user_p($_) } @urls;
>>> my @names = await Mojo::Promise->all(@promises);
>>> say for map { $_->[0] } @names;
>>> };
>>>
>>> my @urls = (qw(
>>> http://localhost:8000/api-converge/auth/user/
>>> ));
>>>
>>> main(@urls)->wait;
>>>
>>>
>>>
>>>
>>> On Wednesday, 27 May 2020 23:41:27 UTC+5:30, Jeyaraj Durairaj wrote:

 I tried generating an example app and copied pasted the code segment 
 you posted here and then tried.

 "Action not found!" error is shown.

 Should I reinstall Perl again and then try?
 Will it work under morbo or works only on Hypnotoad?
 I am using Windows for my development, wherein morbo is the only server 
 I can test.
 Or can I test it on daemon mode and try>
 Please suggest as to how I should diagnose it.
 I would need this Async/await to be working in my system.
 I have tried without Async, all other functionalities rock both in 
 development and production (hypnotoad). Mojo::UserAgent is amazing to 
 fetch 
 API call data from Django server (running under Apache).

 I am completely counting on Mojolicious as my primary framework for my 
 new projects. Please help.


 Regards/Jeyaraj

 On Wednesday, 27 May 2020 17:46:49 UTC+5:30, Sebastian Riedel wrote:
>
> I'll assume it was you who asked the same question on IRC earlier. Had 
> you been sticking around for a bit longer you would have seen my 
> instructions for getting a working application that i tested locally.
>
> 14:08  to be sure i did a "mojo generate app" and then 
> replaced the controller with http://paste.scsys.co.uk/589044
>
> That's the important part, if that doesn't work your Perl or some 
> module you installed is broken.
>
> --
> sebastia

Re: [Mojolicious] Async/await in Mojolicious Full App

2020-06-03 Thread Jeyaraj Durairaj
Hi,

Eureka! Eureka! It works!.

The solution I found (because of my error) is that I uninstalled 
Mojo::AsyncAwait and installed Future::AsyncAwait.
It just works!

By June end, my business intelligence application will be live to serve 
100+ users with insights and analytics.

(To apply icing on the cake, I have plugged in Moose also in to model layer 
for my application)

As Glen Hinkle said, it is really really a fun to work in Mojolicious. I 
love Hypnotoad.

BTW, I am doing a private project as well to help a home designer to launch 
a web site for their small firm. Guess! what framework I am gonna use.. 
*Mojolicious.*

Thanks to Mojo group and special thanks to SRI as well.

-- Jeyaraj



On Thursday, 28 May 2020 14:15:04 UTC+5:30, Jeyaraj Durairaj wrote:
>
> any luck on the solutions?
>
> -- Jeyaraj
>
> On Thursday, 28 May 2020 00:10:48 UTC+5:30, Jeyaraj Durairaj wrote:
>>
>> However, the below code perfectly work for me outside Mojolicious App.
>>
>>
>> use Modern::Perl;
>> use Mojo::Base -strict, -signatures;
>> use Mojo::UserAgent;
>> use Mojo::Promise;
>> use Mojo::IOLoop;
>> use Mojo::Util 'trim';
>> use Mojo::AsyncAwait;
>> use LWP::UserAgent;
>> use JSON;
>>
>>
>> my $ua = Mojo::UserAgent->new;
>> my $result = $ua->post('http://localhost:8000/api/token/' => json => { 
>> username => 'username', password => 'mypassword' })
>> ->result
>> ->json;
>> my $access_token = $result->{access};
>> my $refresh_token = $result->{refresh};
>> print "Access Token: " . $result->{access}, "\n";
>> print "Refresh Token: " . $result->{refresh}, "\n\n";
>>
>>
>> $ua = Mojo::UserAgent->new;
>> $result = $ua->post('http://' . 'localhost:8000' . '/api/token/refresh/' 
>> => json => { refresh => $refresh_token })
>> ->result
>> ->json;
>>
>>
>> my $agent = Mojo::UserAgent->new;
>> async post_user_p => sub ($url) {
>> say "\n\n", $url;
>> my $tx = await $agent->post_p(
>> $url,
>> {
>> Authorization => 'Bearer ' . $result->{access},
>> },
>> form => {"username" => "username"}, 
>>
>> );
>> return trim from_json($tx->result->body)->{first_name};
>> };
>>
>> async main => sub (@urls) {
>> my @promises = map { post_user_p($_) } @urls;
>> my @names = await Mojo::Promise->all(@promises);
>> say for map { $_->[0] } @names;
>> };
>>
>> my @urls = (qw(
>> http://localhost:8000/api-converge/auth/user/
>> ));
>>
>> main(@urls)->wait;
>>
>>
>>
>>
>> On Wednesday, 27 May 2020 23:41:27 UTC+5:30, Jeyaraj Durairaj wrote:
>>>
>>> I tried generating an example app and copied pasted the code segment you 
>>> posted here and then tried.
>>>
>>> "Action not found!" error is shown.
>>>
>>> Should I reinstall Perl again and then try?
>>> Will it work under morbo or works only on Hypnotoad?
>>> I am using Windows for my development, wherein morbo is the only server 
>>> I can test.
>>> Or can I test it on daemon mode and try>
>>> Please suggest as to how I should diagnose it.
>>> I would need this Async/await to be working in my system.
>>> I have tried without Async, all other functionalities rock both in 
>>> development and production (hypnotoad). Mojo::UserAgent is amazing to fetch 
>>> API call data from Django server (running under Apache).
>>>
>>> I am completely counting on Mojolicious as my primary framework for my 
>>> new projects. Please help.
>>>
>>>
>>> Regards/Jeyaraj
>>>
>>> On Wednesday, 27 May 2020 17:46:49 UTC+5:30, Sebastian Riedel wrote:

 I'll assume it was you who asked the same question on IRC earlier. Had 
 you been sticking around for a bit longer you would have seen my 
 instructions for getting a working application that i tested locally.

 14:08  to be sure i did a "mojo generate app" and then 
 replaced the controller with http://paste.scsys.co.uk/589044

 That's the important part, if that doesn't work your Perl or some 
 module you installed is broken.

 --
 sebastian

>>>

-- 
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 mojolicious+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/mojolicious/d71b7bba-9aeb-480a-86f0-98db94956c6a%40googlegroups.com.


Re: [Mojolicious] Async/await in Mojolicious Full App

2020-05-28 Thread Jeyaraj Durairaj
any luck on the solutions?

-- Jeyaraj

On Thursday, 28 May 2020 00:10:48 UTC+5:30, Jeyaraj Durairaj wrote:
>
> However, the below code perfectly work for me outside Mojolicious App.
>
>
> use Modern::Perl;
> use Mojo::Base -strict, -signatures;
> use Mojo::UserAgent;
> use Mojo::Promise;
> use Mojo::IOLoop;
> use Mojo::Util 'trim';
> use Mojo::AsyncAwait;
> use LWP::UserAgent;
> use JSON;
>
>
> my $ua = Mojo::UserAgent->new;
> my $result = $ua->post('http://localhost:8000/api/token/' => json => { 
> username => 'username', password => 'mypassword' })
> ->result
> ->json;
> my $access_token = $result->{access};
> my $refresh_token = $result->{refresh};
> print "Access Token: " . $result->{access}, "\n";
> print "Refresh Token: " . $result->{refresh}, "\n\n";
>
>
> $ua = Mojo::UserAgent->new;
> $result = $ua->post('http://' . 'localhost:8000' . '/api/token/refresh/' 
> => json => { refresh => $refresh_token })
> ->result
> ->json;
>
>
> my $agent = Mojo::UserAgent->new;
> async post_user_p => sub ($url) {
> say "\n\n", $url;
> my $tx = await $agent->post_p(
> $url,
> {
> Authorization => 'Bearer ' . $result->{access},
> },
> form => {"username" => "username"}, 
>
> );
> return trim from_json($tx->result->body)->{first_name};
> };
>
> async main => sub (@urls) {
> my @promises = map { post_user_p($_) } @urls;
> my @names = await Mojo::Promise->all(@promises);
> say for map { $_->[0] } @names;
> };
>
> my @urls = (qw(
> http://localhost:8000/api-converge/auth/user/
> ));
>
> main(@urls)->wait;
>
>
>
>
> On Wednesday, 27 May 2020 23:41:27 UTC+5:30, Jeyaraj Durairaj wrote:
>>
>> I tried generating an example app and copied pasted the code segment you 
>> posted here and then tried.
>>
>> "Action not found!" error is shown.
>>
>> Should I reinstall Perl again and then try?
>> Will it work under morbo or works only on Hypnotoad?
>> I am using Windows for my development, wherein morbo is the only server I 
>> can test.
>> Or can I test it on daemon mode and try>
>> Please suggest as to how I should diagnose it.
>> I would need this Async/await to be working in my system.
>> I have tried without Async, all other functionalities rock both in 
>> development and production (hypnotoad). Mojo::UserAgent is amazing to fetch 
>> API call data from Django server (running under Apache).
>>
>> I am completely counting on Mojolicious as my primary framework for my 
>> new projects. Please help.
>>
>>
>> Regards/Jeyaraj
>>
>> On Wednesday, 27 May 2020 17:46:49 UTC+5:30, Sebastian Riedel wrote:
>>>
>>> I'll assume it was you who asked the same question on IRC earlier. Had 
>>> you been sticking around for a bit longer you would have seen my 
>>> instructions for getting a working application that i tested locally.
>>>
>>> 14:08  to be sure i did a "mojo generate app" and then 
>>> replaced the controller with http://paste.scsys.co.uk/589044
>>>
>>> That's the important part, if that doesn't work your Perl or some module 
>>> you installed is broken.
>>>
>>> --
>>> sebastian
>>>
>>

-- 
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 mojolicious+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/mojolicious/a628cb9e-6a9f-4d43-9106-62407fc34055%40googlegroups.com.


Re: [Mojolicious] Async/await in Mojolicious Full App

2020-05-27 Thread Jeyaraj Durairaj
However, the below code perfectly work for me outside Mojolicious App.


use Modern::Perl;
use Mojo::Base -strict, -signatures;
use Mojo::UserAgent;
use Mojo::Promise;
use Mojo::IOLoop;
use Mojo::Util 'trim';
use Mojo::AsyncAwait;
use LWP::UserAgent;
use JSON;


my $ua = Mojo::UserAgent->new;
my $result = $ua->post('http://localhost:8000/api/token/' => json => { 
username => 'username', password => 'mypassword' })
->result
->json;
my $access_token = $result->{access};
my $refresh_token = $result->{refresh};
print "Access Token: " . $result->{access}, "\n";
print "Refresh Token: " . $result->{refresh}, "\n\n";


$ua = Mojo::UserAgent->new;
$result = $ua->post('http://' . 'localhost:8000' . '/api/token/refresh/' => 
json => { refresh => $refresh_token })
->result
->json;


my $agent = Mojo::UserAgent->new;
async post_user_p => sub ($url) {
say "\n\n", $url;
my $tx = await $agent->post_p(
$url,
{
Authorization => 'Bearer ' . $result->{access},
},
form => {"username" => "username"}, 

);
return trim from_json($tx->result->body)->{first_name};
};

async main => sub (@urls) {
my @promises = map { post_user_p($_) } @urls;
my @names = await Mojo::Promise->all(@promises);
say for map { $_->[0] } @names;
};

my @urls = (qw(
http://localhost:8000/api-converge/auth/user/
));

main(@urls)->wait;




On Wednesday, 27 May 2020 23:41:27 UTC+5:30, Jeyaraj Durairaj wrote:
>
> I tried generating an example app and copied pasted the code segment you 
> posted here and then tried.
>
> "Action not found!" error is shown.
>
> Should I reinstall Perl again and then try?
> Will it work under morbo or works only on Hypnotoad?
> I am using Windows for my development, wherein morbo is the only server I 
> can test.
> Or can I test it on daemon mode and try>
> Please suggest as to how I should diagnose it.
> I would need this Async/await to be working in my system.
> I have tried without Async, all other functionalities rock both in 
> development and production (hypnotoad). Mojo::UserAgent is amazing to fetch 
> API call data from Django server (running under Apache).
>
> I am completely counting on Mojolicious as my primary framework for my new 
> projects. Please help.
>
>
> Regards/Jeyaraj
>
> On Wednesday, 27 May 2020 17:46:49 UTC+5:30, Sebastian Riedel wrote:
>>
>> I'll assume it was you who asked the same question on IRC earlier. Had 
>> you been sticking around for a bit longer you would have seen my 
>> instructions for getting a working application that i tested locally.
>>
>> 14:08  to be sure i did a "mojo generate app" and then 
>> replaced the controller with http://paste.scsys.co.uk/589044
>>
>> That's the important part, if that doesn't work your Perl or some module 
>> you installed is broken.
>>
>> --
>> sebastian
>>
>

-- 
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 mojolicious+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/mojolicious/126ed3a6-bb0a-4a8c-8d6d-12e27701f187%40googlegroups.com.


Re: [Mojolicious] Async/await in Mojolicious Full App

2020-05-27 Thread Jeyaraj Durairaj
I have uninstalled and reinstalled perl.
I am getting the same error.

On Wednesday, 27 May 2020 23:41:27 UTC+5:30, Jeyaraj Durairaj wrote:
>
> I tried generating an example app and copied pasted the code segment you 
> posted here and then tried.
>
> "Action not found!" error is shown.
>
> Should I reinstall Perl again and then try?
> Will it work under morbo or works only on Hypnotoad?
> I am using Windows for my development, wherein morbo is the only server I 
> can test.
> Or can I test it on daemon mode and try>
> Please suggest as to how I should diagnose it.
> I would need this Async/await to be working in my system.
> I have tried without Async, all other functionalities rock both in 
> development and production (hypnotoad). Mojo::UserAgent is amazing to fetch 
> API call data from Django server (running under Apache).
>
> I am completely counting on Mojolicious as my primary framework for my new 
> projects. Please help.
>
>
> Regards/Jeyaraj
>
> On Wednesday, 27 May 2020 17:46:49 UTC+5:30, Sebastian Riedel wrote:
>>
>> I'll assume it was you who asked the same question on IRC earlier. Had 
>> you been sticking around for a bit longer you would have seen my 
>> instructions for getting a working application that i tested locally.
>>
>> 14:08  to be sure i did a "mojo generate app" and then 
>> replaced the controller with http://paste.scsys.co.uk/589044
>>
>> That's the important part, if that doesn't work your Perl or some module 
>> you installed is broken.
>>
>> --
>> sebastian
>>
>

-- 
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 mojolicious+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/mojolicious/1968f75d-f14f-42ff-8504-33de0d97d360%40googlegroups.com.


Re: [Mojolicious] Async/await in Mojolicious Full App

2020-05-27 Thread Jeyaraj Durairaj
I tried generating an example app and copied pasted the code segment you 
posted here and then tried.

"Action not found!" error is shown.

Should I reinstall Perl again and then try?
Will it work under morbo or works only on Hypnotoad?
I am using Windows for my development, wherein morbo is the only server I 
can test.
Or can I test it on daemon mode and try>
Please suggest as to how I should diagnose it.
I would need this Async/await to be working in my system.
I have tried without Async, all other functionalities rock both in 
development and production (hypnotoad). Mojo::UserAgent is amazing to fetch 
API call data from Django server (running under Apache).

I am completely counting on Mojolicious as my primary framework for my new 
projects. Please help.


Regards/Jeyaraj

On Wednesday, 27 May 2020 17:46:49 UTC+5:30, Sebastian Riedel wrote:
>
> I'll assume it was you who asked the same question on IRC earlier. Had you 
> been sticking around for a bit longer you would have seen my instructions 
> for getting a working application that i tested locally.
>
> 14:08  to be sure i did a "mojo generate app" and then replaced 
> the controller with http://paste.scsys.co.uk/589044
>
> That's the important part, if that doesn't work your Perl or some module 
> you installed is broken.
>
> --
> sebastian
>

-- 
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 mojolicious+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/mojolicious/736982de-8132-4b0c-90b1-8dde9868aace%40googlegroups.com.


Re: [Mojolicious] Async/await in Mojolicious Full App

2020-05-27 Thread Jeyaraj Durairaj
Sure sir, I will stick to it.

On Wednesday, 27 May 2020 23:02:36 UTC+5:30, Sebastian Riedel wrote:
>
> Oops! my bad. Apologies! I should have stayed. But, I had to get into a 
>> skype call.
>>
>
> IRC is rarely synchronous, if you can't wait a few hours for an answer 
> just stick to the mailing-list and
> forget IRC. The friendly folks in #mojo will answer almost any question, 
> but you might have to wait
> 24 hours for the right person to be online. We are distributed all around 
> the world after all.
>
> --
> sebastian 
>

-- 
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 mojolicious+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/mojolicious/b7ba5d60-2020-460a-b35a-c095a563ac58%40googlegroups.com.


Re: [Mojolicious] Async/await in Mojolicious Full App

2020-05-27 Thread Sebastian Riedel

>
> Oops! my bad. Apologies! I should have stayed. But, I had to get into a 
> skype call.
>

IRC is rarely synchronous, if you can't wait a few hours for an answer just 
stick to the mailing-list and
forget IRC. The friendly folks in #mojo will answer almost any question, 
but you might have to wait
24 hours for the right person to be online. We are distributed all around 
the world after all.

--
sebastian 

-- 
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 mojolicious+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/mojolicious/184fb652-1e8c-4646-9683-324d22b33c66%40googlegroups.com.


Re: [Mojolicious] Async/await in Mojolicious Full App

2020-05-27 Thread Jeyaraj Durairaj
Oops! my bad. Apologies! I should have stayed. But, I had to get into a 
skype call.

I will follow your advise and redo all and confirm sir.


On Wednesday, 27 May 2020 17:46:49 UTC+5:30, Sebastian Riedel wrote:
>
> I'll assume it was you who asked the same question on IRC earlier. Had you 
> been sticking around for a bit longer you would have seen my instructions 
> for getting a working application that i tested locally.
>
> 14:08  to be sure i did a "mojo generate app" and then replaced 
> the controller with http://paste.scsys.co.uk/589044
>
> That's the important part, if that doesn't work your Perl or some module 
> you installed is broken.
>
> --
> sebastian
>

-- 
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 mojolicious+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/mojolicious/04d77c02-1778-4958-a5ad-089ca7c4ea29%40googlegroups.com.


Re: [Mojolicious] Async/await in Mojolicious Full App

2020-05-27 Thread Sebastian Riedel
I'll assume it was you who asked the same question on IRC earlier. Had you 
been sticking around for a bit longer you would have seen my instructions 
for getting a working application that i tested locally.

14:08  to be sure i did a "mojo generate app" and then replaced 
the controller with http://paste.scsys.co.uk/589044

That's the important part, if that doesn't work your Perl or some module 
you installed is broken.

--
sebastian

-- 
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 mojolicious+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/mojolicious/b4dd93ac-e60a-4973-828c-4d1b364889af%40googlegroups.com.


Re: [Mojolicious] Async/await in Mojolicious Full App

2020-05-26 Thread Jeyaraj Durairaj
I tried. getting the same error.

On Tuesday, 26 May 2020 23:41:23 UTC+5:30, Vincent Tondellier wrote:
>
> On Tuesday 26 May 2020 11:06:50 Jeyaraj Durairaj wrote : 
> > use Mojo::Base 'Mojolicious::Controller'; 
> > use Mojo::Base -async_await; 
>
> Try instead: 
>
> use Mojo::Base 'Mojolicious::Controller',  -async_await; 
>

-- 
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 mojolicious+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/mojolicious/251ef79e-486a-45b0-b43f-1ebb6c8869f9%40googlegroups.com.


Re: [Mojolicious] Async/await in Mojolicious Full App

2020-05-26 Thread Jeyaraj Durairaj
Hi,

I corrected it.

But, I am still getting the syntax error and the following log.


use Mojo::Base 'Mojolicious::Controller', -async_await, -signatures;


# This action will render a template
async sub on_user_login_p ($self) {
$self->render_later;

# Authenticate by sending the request parameters directly
if ($self->authenticate($self->param('username'), 
$self->param('password'))) {
my $access_token = 
$self->access_token($self->session('refresh_token'));
my $user = await $self->user_data_p($access_token);
return $self->render(text => 'Unauthenticated Access', status => 
403) unless ($user->{is_staff});
return $self->render(text => 'You are not an active User', status 
=> 403) unless ($user->{is_active});
$self->set_authorization($user);
$self->flash(message_type => 'success');
$self->flash(message => 'Congratulations ' . 
$self->session('full_name') . '!');
$self->redirect_to('bi-home');
} else {
$self->flash(message_type => 'danger');
$self->flash(message => 'Wrong SSOID/Password!');
return $self->redirect_to('login', status => 403);
#return $self->render(text => 'wrong ssoid/password', status => 
403);
}
}

async sub user_data_p ($c, $access_token) {
my $ua = Mojo::UserAgent->new;
my $tx = await $ua->post_p(
'http://' . $c->config->{API_IP} . '/api-converge/auth/user/',
{
Authorization => 'Bearer ' . $access_token,
},
form => {username => $c->session('username')}, 

);
if ($tx->is_success) {
return from_json($tx->result->body);
}
$c->render(text => 'User Data can not be obtained', status => 500);
}



[2020-05-26 23:53:56.00449] [-15696] [debug] GET "/" (e7a8d2e9)
[2020-05-26 23:53:56.01464] [-15696] [error] syntax error at 
C:.../projects/perl_projects/mojo_projects/converge_at_commex/script/../lib/ConvergeAtCommex/Controller/Sessions.pm
 
line 38, near "async sub on_user_login_p ($self) "
Global symbol "$self" requires explicit package name (did you forget to 
declare "my $self"?) at 
C:.../projects/perl_projects/mojo_projects/converge_at_commex/script/../lib/ConvergeAtCommex/Controller/Sessions.pm
 
line 39.
Global symbol "$self" requires explicit package name (did you forget to 
declare "my $self"?) at 
C:.../projects/perl_projects/mojo_projects/converge_at_commex/script/../lib/ConvergeAtCommex/Controller/Sessions.pm
 
line 42.
Global symbol "$self" requires explicit package name (did you forget to 
declare "my $self"?) at 
C:.../projects/perl_projects/mojo_projects/converge_at_commex/script/../lib/ConvergeAtCommex/Controller/Sessions.pm
 
line 42.
Global symbol "$self" requires explicit package name (did you forget to 
declare "my $self"?) at 
C:.../projects/perl_projects/mojo_projects/converge_at_commex/script/../lib/ConvergeAtCommex/Controller/Sessions.pm
 
line 42.
Global symbol "$self" requires explicit package name (did you forget to 
declare "my $self"?) at 
C:.../projects/perl_projects/mojo_projects/converge_at_commex/script/../lib/ConvergeAtCommex/Controller/Sessions.pm
 
line 43.
Global symbol "$self" requires explicit package name (did you forget to 
declare "my $self"?) at 
C:.../projects/perl_projects/mojo_projects/converge_at_commex/script/../lib/ConvergeAtCommex/Controller/Sessions.pm
 
line 43.
Global symbol "$self" requires explicit package name (did you forget to 
declare "my $self"?) at 
C:.../projects/perl_projects/mojo_projects/converge_at_commex/script/../lib/ConvergeAtCommex/Controller/Sessions.pm
 
line 44.
Global symbol "$self" requires explicit package name (did you forget to 
declare "my $self"?) at 
C:.../projects/perl_projects/mojo_projects/converge_at_commex/script/../lib/ConvergeAtCommex/Controller/Sessions.pm
 
line 45.
Global symbol "$self" requires explicit package name (did you forget to 
declare "my $self"?) at 
C:.../projects/perl_projects/mojo_projects/converge_at_commex/script/../lib/ConvergeAtCommex/Controller/Sessions.pm
 
line 46.
Global symbol "$self" requires explicit package name (did you forget to 
declare "my $self"?) at 
C:.../projects/perl_projects/mojo_projects/converge_at_commex/script/../lib/ConvergeAtCommex/Controller/Sessions.pm
 
line 47.
Global symbol "$self" requires explicit package name (did you forget to 
declare "my $self"?) at 
C:.../projects/perl_projects/mojo_projects/converge_at_commex/script/../lib/ConvergeAtCommex/Controller/Sessions.pm
 
line 48.
Global symbol "$self" requires explicit package name (did you forget to 
declare "my $self"?) at 
C:.../projects/perl_projects/mojo_projects/converge_at_commex/script/../lib/ConvergeAtCommex/Controller/Sessions.pm
 
line 49.
Global symbol "$self" requires explicit package name (did you forget to 
declare "my $self"?) at 
C:.../projects/perl_projects/mojo_projects/converge_at_commex/script/../lib/ConvergeAtCommex/Controller/Sessions.pm
 
line 49.
Global symbol "$self" requires explicit package

Re: [Mojolicious] Async/await in Mojolicious Full App

2020-05-26 Thread Dan Book
On Tue, May 26, 2020 at 2:06 PM Jeyaraj Durairaj 
wrote:

> async on_user_login_p => sub {
>
> async sub user_data_p () {
>

These two declarations are not quite right in different ways. The first one
is giving you a syntax error because it isn't any supported syntax. Just do
"async sub foo {"

-Dan

-- 
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 mojolicious+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/mojolicious/CABMkAVWxy5oxqn_2e%3DRgH%3DZWo6CiK35z8dpf4rWxZ0ycd4jNuA%40mail.gmail.com.


Re: [Mojolicious] Async/await in Mojolicious Full App

2020-05-26 Thread 'Vincent Tondellier' via Mojolicious
On Tuesday 26 May 2020 11:06:50 Jeyaraj Durairaj wrote :
> use Mojo::Base 'Mojolicious::Controller';
> use Mojo::Base -async_await;

Try instead:

use Mojo::Base 'Mojolicious::Controller',  -async_await;

-- 
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 mojolicious+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/mojolicious/2143882.7O9tEhJyZY%40quad.