Re: [Mojolicious] Systemd "Can't locate Mojo/Base.pm in @INC"

2021-04-30 Thread Dan Book
The current working directory in Perl should be retrieved using Cwd, not
$ENV{PWD}. Regardless, putting paths in your program based on CWD is a bug,
since the program could be run with any CWD and that should not change its
behavior. I wrote a similar module to the FindBin interface using the same
method as lib::relative for creating arbitrary file paths relative to the
current file: https://metacpan.org/pod/Path::This

With an up to date Mojolicious, curfile can of course solve both these
problems.

-Dan

On Fri, Apr 30, 2021 at 10:50 AM llaro...@gmail.com 
wrote:

> Thanks to both of you, I managed to get past loading modules while
> starting the service from systemd. Now there is another bug regarding
> relative paths and I wonder how to solve it, it seems lib::relative might
> not do the trick
>
> my $homedir = $ENV{'HOME'};
> my $cwd = $ENV{'PWD'};
> my $log = Mojo::Log->new(path => $cwd . '/log/ccdapi.log', level =>
> 'info');
>
> Use of uninitialized value $cwd in concatenation (.) or string at
> /srv/ccdapi/VM01/PROD/v1/ccdapi.pl line 21.
> Apr 29 16:16:19 vl-vm-sr824.lb ccdapi[65656]: Can't load application from
> file "/srv/ccdapi/VM01/PROD/v1/ccdapi.pl": Can't open file
> "/log/ccdapi.log": No such file or directory at
> /srv/ccdapi/.perlbrew/libs/perl-5.24.0@ccd
> Apr 29 16:16:19 vl-vm-sr824.lb ccdapi[65656]: Compilation failed in
> require at (eval 81) line 1.
>
> Cheers !
>
> On Thursday, 29 April 2021 at 14:26:01 UTC-4 dim0xff wrote:
>
>> Here is my Service with perlbrew
>> [Service]
>> Type=forking
>> User=backend
>> Group=backend
>> WorkingDirectory=/home/backend/app
>> Environment=PERLBREW_ROOT=/home/backend/perl5/perlbrew
>> ExecStart=/home/backend/perl5/perlbrew/bin/perlbrew exec -q --with
>> perl-5.28.0 hypnotoad /home/backend/app/app_backend.pl
>> ...
>>
>>
>> Here is perlbrew info:
>> $ > perlbrew info
>> Current perl:
>> Name: perl-5.28.0
>> Path: /home/backend/perl5/perlbrew/perls/perl-5.28.0/bin/perl
>> Config: -de -Dprefix=/home/backend/perl5/perlbrew/perls/perl-5.28.0
>> -Aeval:scriptdir=/home/backend/perl5/perlbrew/perls/perl-5.28.0/bin
>> Compiled at: Jul 8 2018 23:47:31
>>
>> perlbrew:
>> version: 0.84
>> ENV:
>> PERLBREW_ROOT: /home/backend/perl5/perlbrew
>> PERLBREW_HOME: /home/backend/.perlbrew
>> PERLBREW_PATH:
>> /home/backend/perl5/perlbrew/bin:/home/backend/perl5/perlbrew/perls/perl-5.28.0/bin
>>
>> PERLBREW_MANPATH: /home/backend/perl5/perlbrew/perls/perl-5.28.0/man
>>
>>
>> On Thu, 29 Apr 2021 at 00:28, llaro...@gmail.com 
>> wrote:
>> >
>> > Hi, I'm trying to register my hypnotoad daemon as a service in
>> >
>> > cat /lib/systemd/system/ccdapi.service
>> > [Unit]
>> > Description=MY CCDAPI LAB
>> > Requires=network.target
>> > After=network.target
>> > User=ccdapi
>> > Group=ccdapi
>> > # put here other service requirements
>> >
>> > [Service]
>> > User=ccdapi
>> > Group=ccdapi
>> > Type=simple
>> > Restart=always
>> > SyslogIdentifier=ccdapi
>> > PIDFile=/home/srv/ccdapi/v1/etc/ccdapi.pid
>> > ExecStart=/srv/ccdapi/.perlbrew/libs/perl-5.24.0@ccdapi/bin/hypnotoad
>> /srv/ccdapi/VM01/PROD/v1/ccdapi.pl -f
>> > ExecStop=/srv/ccdapi/.perlbrew/libs/perl-5.24.0@ccdapi/bin/hypnotoad
>> -s /srv/ccdapi/VM01/PROD/v1/ccdapi.pl
>> > ExecReload=/srv/ccdapi/.perlbrew/libs/perl-5.24.0@ccdapi/bin/hypnotoad
>> /srv/ccdapi/VM01/PROD/v1/ccdapi.pl
>> > KillMode=process
>> > WorkingDirectory=/srv/ccdapi
>> >
>> > [Install]
>> > WantedBy=multi.user.target
>> >
>> > When I try to start the service I get
>> >
>> > -- Unit ccdapi.service has begun starting up.
>> > Apr 28 16:41:48 vl-vm-sr824.lb.videotron.ca ccdapi[63200]: Can't
>> locate Mojo/Base.pm in @INC (you may need to install the Mojo::Base module)
>> (@INC contains:
>> /srv/ccdapi/perl5/perlbrew/perls/perl-5.24.0/lib/site_perl/5.24.0/x86_64-linux
>>
>> > Apr 28 16:41:48 vl-vm-sr824.lb.videotron.ca ccdapi[63200]: BEGIN
>> failed--compilation aborted at 
>> /srv/ccdapi/.perlbrew/libs/perl-5.24.0@ccdapi/bin/hypnotoad
>> line 2.
>> > Apr 28 16:41:48 vl-vm-sr824.lb.videotron.ca systemd[1]:
>> ccdapi.service: main process exited, code=exited, status=2/INVALIDARGUMENT
>> > Apr 28 16:41:48 vl-vm-sr824.lb.videotron.ca ccdapi[63201]: Can't
>> locate Mojo/Base.pm in @INC (you may need to install the Mojo::Base module)
>> (@INC contains:
>> /srv/ccdapi/perl5/perlbrew/perls/perl-5.24.0/lib/site_perl/5.24.0/x86_64-linux
>>
>> > Apr 28 16:41:48 vl-vm-sr824.lb.videotron.ca ccdapi[63201]: BEGIN
>> failed--compilation aborted at 
>> /srv/ccdapi/.perlbrew/libs/perl-5.24.0@ccdapi/bin/hypnotoad
>> line 2.
>> > Apr 28 16:41:48 vl-vm-sr824.lb.videotron.ca systemd[1]:
>> ccdapi.service: control process exited, code=exited status=2
>> > Apr 28 16:41:48 vl-vm-sr824.lb.videotron.ca systemd[1]: Unit
>> ccdapi.service entered failed state.
>> > Apr 28 16:41:48 vl-vm-sr824.lb.videotron.ca systemd[1]: ccdapi.service
>> failed.
>> > Apr 28 16:41:48 vl-vm-sr824.lb.videotron.ca systemd[1]: ccdapi.service
>> holdoff time over, scheduling restart.
>> > Apr 28 

Re: [Mojolicious] Systemd "Can't locate Mojo/Base.pm in @INC"

2021-04-29 Thread Dan Book
Yes, or install and use https://metacpan.org/pod/lib::relative

On Thu, Apr 29, 2021 at 1:55 PM llaro...@gmail.com 
wrote:

> "curfile" is not exported by the Mojo::File module
>
> should I update Mojolicious ?
>
> On Thursday, 29 April 2021 at 09:45:05 UTC-4 llaro...@gmail.com wrote:
>
>> Thanks, I'll give it a try today ! Looks like FindBin but Mojolicious' way
>>
>> On Wednesday, 28 April 2021 at 20:55:21 UTC-4 gri...@gmail.com wrote:
>>
>>> You have to add the path that contains the Methods directory, not the
>>> Methods directory itself.
>>>
>>> If it's deployed relative to your script, consider adding it like in
>>> this example:
>>> https://metacpan.org/pod/Mojolicious::Guides::Growing#Script
>>>
>>> # add directory script is in
>>> use lib curfile->dirname->to_string;
>>>
>>> -Dan
>>>
>>> On Wed, Apr 28, 2021 at 8:52 PM llaro...@gmail.com 
>>> wrote:
>>>
 I removed the first line and added the "Environment" entry in Service
 section, now I have a new issue ... home made modules

 Apr 28 20:10:45 vl-vm-sr824.lb systemd[1]: Started MY CCDAPI LAB.
 Apr 28 20:10:45 vl-vm-sr824.lb systemd[1]: Starting MY CCDAPI LAB...
 Apr 28 20:10:45 vl-vm-sr824.lb ccdapi[63913]: Can't load application
 from file "/srv/ccdapi/VM01/PROD/v1/ccdapi.pl": Can't locate Methods/
 cmtsc.pm in @INC (you may need to install the Methods::cmtsc
 module...x /srv/ccdapi/.
 Apr 28 20:10:45 vl-vm-sr824.lb ccdapi[63913]: BEGIN
 failed--compilation aborted at /srv/ccdapi/VM01/PROD/v1/ccdapi.pl line
 10.
 Apr 28 20:10:45 vl-vm-sr824.lb ccdapi[63913]: Compilation failed in
 require at (eval 80) line 1.
 Apr 28 20:10:45 vl-vm-sr824.lb systemd[1]: ccdapi.service: main
 process exited, code=exited, status=2/INVALIDARGUMENT

 They are in the path of my application. I tried "use lib
 qw(/path/Methods/) but it failed too

 I tried a list in environement separated by ";" but it failed too.

 What am I missing ?

 On Wednesday, 28 April 2021 at 17:33:23 UTC-4 gri...@gmail.com wrote:

> You have installed it to a local::lib in the perlbrew. The systemd
> service won't have that active. You could fix it by adding to the 
> [Service]
> block:
>
> Environment="PERL5LIB=/srv/ccdapi/.perlbrew/libs/perl-5.24.0@ccdapi
> /lib/perl5"
>
> On Wed, Apr 28, 2021 at 5:28 PM llaro...@gmail.com 
> wrote:
>
>> Hi, I'm trying to register my hypnotoad daemon as a service in
>>
>>   cat /lib/systemd/system/ccdapi.service
>> [Unit]
>> Description=MY CCDAPI LAB
>> Requires=network.target
>> After=network.target
>> User=ccdapi
>> Group=ccdapi
>> # put here other service requirements
>>
>> [Service]
>> User=ccdapi
>> Group=ccdapi
>> Type=simple
>> Restart=always
>> SyslogIdentifier=ccdapi
>> PIDFile=/home/srv/ccdapi/v1/etc/ccdapi.pid
>> ExecStart=/srv/ccdapi/.perlbrew/libs/perl-5.24.0@ccdapi/bin/hypnotoad
>> /srv/ccdapi/VM01/PROD/v1/ccdapi.pl -f
>> ExecStop=/srv/ccdapi/.perlbrew/libs/perl-5.24.0@ccdapi/bin/hypnotoad
>> -s /srv/ccdapi/VM01/PROD/v1/ccdapi.pl
>> ExecReload=/srv/ccdapi/.perlbrew/libs/perl-5.24.0@ccdapi/bin/hypnotoad
>> /srv/ccdapi/VM01/PROD/v1/ccdapi.pl
>> KillMode=process
>> WorkingDirectory=/srv/ccdapi
>>
>> [Install]
>> WantedBy=multi.user.target
>>
>> When I try to start the service I get
>>
>> -- Unit ccdapi.service has begun starting up.
>> Apr 28 16:41:48 vl-vm-sr824.lb.videotron.ca ccdapi[63200]: Can't
>> locate Mojo/Base.pm in @INC (you may need to install the Mojo::Base 
>> module)
>> (@INC contains:
>> /srv/ccdapi/perl5/perlbrew/perls/perl-5.24.0/lib/site_perl/5.24.0/x86_64-linux
>> Apr 28 16:41:48 vl-vm-sr824.lb.videotron.ca ccdapi[63200]: BEGIN
>> failed--compilation aborted at 
>> /srv/ccdapi/.perlbrew/libs/perl-5.24.0@ccdapi/bin/hypnotoad
>> line 2.
>> Apr 28 16:41:48 vl-vm-sr824.lb.videotron.ca systemd[1]:
>> ccdapi.service: main process exited, code=exited, 
>> status=2/INVALIDARGUMENT
>> Apr 28 16:41:48 vl-vm-sr824.lb.videotron.ca ccdapi[63201]: Can't
>> locate Mojo/Base.pm in @INC (you may need to install the Mojo::Base 
>> module)
>> (@INC contains:
>> /srv/ccdapi/perl5/perlbrew/perls/perl-5.24.0/lib/site_perl/5.24.0/x86_64-linux
>> Apr 28 16:41:48 vl-vm-sr824.lb.videotron.ca ccdapi[63201]: BEGIN
>> failed--compilation aborted at 
>> /srv/ccdapi/.perlbrew/libs/perl-5.24.0@ccdapi/bin/hypnotoad
>> line 2.
>> Apr 28 16:41:48 vl-vm-sr824.lb.videotron.ca systemd[1]:
>> ccdapi.service: control process exited, code=exited status=2
>> Apr 28 16:41:48 vl-vm-sr824.lb.videotron.ca systemd[1]: Unit
>> ccdapi.service entered failed state.
>> Apr 28 16:41:48 vl-vm-sr824.lb.videotron.ca systemd[1]:
>> ccdapi.service failed.
>> Apr 28 16:41:48 

Re: [Mojolicious] Systemd "Can't locate Mojo/Base.pm in @INC"

2021-04-28 Thread Dan Book
You have to add the path that contains the Methods directory, not the
Methods directory itself.

If it's deployed relative to your script, consider adding it like in this
example: https://metacpan.org/pod/Mojolicious::Guides::Growing#Script

# add directory script is in
use lib curfile->dirname->to_string;

-Dan

On Wed, Apr 28, 2021 at 8:52 PM llaro...@gmail.com 
wrote:

> I removed the first line and added the "Environment" entry in Service
> section, now I have a new issue ... home made modules
>
> Apr 28 20:10:45 vl-vm-sr824.lb systemd[1]: Started MY CCDAPI LAB.
> Apr 28 20:10:45 vl-vm-sr824.lb systemd[1]: Starting MY CCDAPI LAB...
> Apr 28 20:10:45 vl-vm-sr824.lb ccdapi[63913]: Can't load application from
> file "/srv/ccdapi/VM01/PROD/v1/ccdapi.pl": Can't locate Methods/cmtsc.pm
> in @INC (you may need to install the Methods::cmtsc module...x /srv/ccdapi/.
> Apr 28 20:10:45 vl-vm-sr824.lb ccdapi[63913]: BEGIN failed--compilation
> aborted at /srv/ccdapi/VM01/PROD/v1/ccdapi.pl line 10.
> Apr 28 20:10:45 vl-vm-sr824.lb ccdapi[63913]: Compilation failed in
> require at (eval 80) line 1.
> Apr 28 20:10:45 vl-vm-sr824.lb systemd[1]: ccdapi.service: main process
> exited, code=exited, status=2/INVALIDARGUMENT
>
> They are in the path of my application. I tried "use lib
> qw(/path/Methods/) but it failed too
>
> I tried a list in environement separated by ";" but it failed too.
>
> What am I missing ?
>
> On Wednesday, 28 April 2021 at 17:33:23 UTC-4 gri...@gmail.com wrote:
>
>> You have installed it to a local::lib in the perlbrew. The systemd
>> service won't have that active. You could fix it by adding to the [Service]
>> block:
>>
>> Environment="PERL5LIB=/srv/ccdapi/.perlbrew/libs/perl-5.24.0@ccdapi
>> /lib/perl5"
>>
>> On Wed, Apr 28, 2021 at 5:28 PM llaro...@gmail.com 
>> wrote:
>>
>>> Hi, I'm trying to register my hypnotoad daemon as a service in
>>>
>>>   cat /lib/systemd/system/ccdapi.service
>>> [Unit]
>>> Description=MY CCDAPI LAB
>>> Requires=network.target
>>> After=network.target
>>> User=ccdapi
>>> Group=ccdapi
>>> # put here other service requirements
>>>
>>> [Service]
>>> User=ccdapi
>>> Group=ccdapi
>>> Type=simple
>>> Restart=always
>>> SyslogIdentifier=ccdapi
>>> PIDFile=/home/srv/ccdapi/v1/etc/ccdapi.pid
>>> ExecStart=/srv/ccdapi/.perlbrew/libs/perl-5.24.0@ccdapi/bin/hypnotoad
>>> /srv/ccdapi/VM01/PROD/v1/ccdapi.pl -f
>>> ExecStop=/srv/ccdapi/.perlbrew/libs/perl-5.24.0@ccdapi/bin/hypnotoad -s
>>> /srv/ccdapi/VM01/PROD/v1/ccdapi.pl
>>> ExecReload=/srv/ccdapi/.perlbrew/libs/perl-5.24.0@ccdapi/bin/hypnotoad
>>> /srv/ccdapi/VM01/PROD/v1/ccdapi.pl
>>> KillMode=process
>>> WorkingDirectory=/srv/ccdapi
>>>
>>> [Install]
>>> WantedBy=multi.user.target
>>>
>>> When I try to start the service I get
>>>
>>> -- Unit ccdapi.service has begun starting up.
>>> Apr 28 16:41:48 vl-vm-sr824.lb.videotron.ca ccdapi[63200]: Can't locate
>>> Mojo/Base.pm in @INC (you may need to install the Mojo::Base module) (@INC
>>> contains:
>>> /srv/ccdapi/perl5/perlbrew/perls/perl-5.24.0/lib/site_perl/5.24.0/x86_64-linux
>>> Apr 28 16:41:48 vl-vm-sr824.lb.videotron.ca ccdapi[63200]: BEGIN
>>> failed--compilation aborted at 
>>> /srv/ccdapi/.perlbrew/libs/perl-5.24.0@ccdapi/bin/hypnotoad
>>> line 2.
>>> Apr 28 16:41:48 vl-vm-sr824.lb.videotron.ca systemd[1]: ccdapi.service:
>>> main process exited, code=exited, status=2/INVALIDARGUMENT
>>> Apr 28 16:41:48 vl-vm-sr824.lb.videotron.ca ccdapi[63201]: Can't locate
>>> Mojo/Base.pm in @INC (you may need to install the Mojo::Base module) (@INC
>>> contains:
>>> /srv/ccdapi/perl5/perlbrew/perls/perl-5.24.0/lib/site_perl/5.24.0/x86_64-linux
>>> Apr 28 16:41:48 vl-vm-sr824.lb.videotron.ca ccdapi[63201]: BEGIN
>>> failed--compilation aborted at 
>>> /srv/ccdapi/.perlbrew/libs/perl-5.24.0@ccdapi/bin/hypnotoad
>>> line 2.
>>> Apr 28 16:41:48 vl-vm-sr824.lb.videotron.ca systemd[1]: ccdapi.service:
>>> control process exited, code=exited status=2
>>> Apr 28 16:41:48 vl-vm-sr824.lb.videotron.ca systemd[1]: Unit
>>> ccdapi.service entered failed state.
>>> Apr 28 16:41:48 vl-vm-sr824.lb.videotron.ca systemd[1]: ccdapi.service
>>> failed.
>>> Apr 28 16:41:48 vl-vm-sr824.lb.videotron.ca systemd[1]: ccdapi.service
>>> holdoff time over, scheduling restart.
>>> Apr 28 16:41:48 vl-vm-sr824.lb.videotron.ca systemd[1]: start request
>>> repeated too quickly for ccdapi.service
>>> Apr 28 16:41:48 vl-vm-sr824.lb.videotron.ca systemd[1]: Failed to start
>>> MY CCDAPI LAB.
>>> -- Subject: Unit ccdapi.service has failed
>>> -- Defined-By: systemd
>>>
>>>
>>> So I've double-checked Mojo::Base exists ...
>>>
>>> [ccdapi@vl-vm-sr824 ~]$ find . | grep 'Mojo.*Base.pm'
>>> ./VM01/PROD/perl5/lib/perl5/Mojo/Base.pm
>>> ./VM01/perl5/lib/perl5/Mojo/Base.pm
>>> ./temp/report/bin/lib/Mojo/Base.pm
>>> ./.cpan/build/Mojolicious-7.37-yGj97y/blib/lib/Mojo/Base.pm
>>> ./.cpan/build/Mojolicious-7.37-yGj97y/lib/Mojo/Base.pm
>>> ./.perlbrew/libs/perl-5.24.0@ccdapi/lib/perl5/Mojo/Base.pm
>>> 

Re: [Mojolicious] Systemd "Can't locate Mojo/Base.pm in @INC"

2021-04-28 Thread Dan Book
On Wed, Apr 28, 2021 at 5:28 PM llaro...@gmail.com 
wrote:

> And I have added the path with "use lib qw(/my/path/) such as
>
> [ccdapi@vl-vm-sr824 ~]$ head ./VM01/PROD/v1/ccdapi.pl
> use lib qw(/srv/ccdapi/perl5/lib/perl5/);
> use Mojolicious::Lite;
>

Make sure to remove this. The local::lib you have in ~/perl5/lib/perl5 is
not compatible with perlbrew.

-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/CABMkAVW241JCsK5ZaP0vzKZGOxH9oJfWLAFREirZ2dT_no7A5g%40mail.gmail.com.


Re: [Mojolicious] Systemd "Can't locate Mojo/Base.pm in @INC"

2021-04-28 Thread Dan Book
You have installed it to a local::lib in the perlbrew. The systemd service
won't have that active. You could fix it by adding to the [Service] block:

Environment="PERL5LIB=/srv/ccdapi/.perlbrew/libs/perl-5.24.0@ccdapi
/lib/perl5"

On Wed, Apr 28, 2021 at 5:28 PM llaro...@gmail.com 
wrote:

> Hi, I'm trying to register my hypnotoad daemon as a service in
>
>   cat /lib/systemd/system/ccdapi.service
> [Unit]
> Description=MY CCDAPI LAB
> Requires=network.target
> After=network.target
> User=ccdapi
> Group=ccdapi
> # put here other service requirements
>
> [Service]
> User=ccdapi
> Group=ccdapi
> Type=simple
> Restart=always
> SyslogIdentifier=ccdapi
> PIDFile=/home/srv/ccdapi/v1/etc/ccdapi.pid
> ExecStart=/srv/ccdapi/.perlbrew/libs/perl-5.24.0@ccdapi/bin/hypnotoad
> /srv/ccdapi/VM01/PROD/v1/ccdapi.pl -f
> ExecStop=/srv/ccdapi/.perlbrew/libs/perl-5.24.0@ccdapi/bin/hypnotoad -s
> /srv/ccdapi/VM01/PROD/v1/ccdapi.pl
> ExecReload=/srv/ccdapi/.perlbrew/libs/perl-5.24.0@ccdapi/bin/hypnotoad
> /srv/ccdapi/VM01/PROD/v1/ccdapi.pl
> KillMode=process
> WorkingDirectory=/srv/ccdapi
>
> [Install]
> WantedBy=multi.user.target
>
> When I try to start the service I get
>
> -- Unit ccdapi.service has begun starting up.
> Apr 28 16:41:48 vl-vm-sr824.lb.videotron.ca ccdapi[63200]: Can't locate
> Mojo/Base.pm in @INC (you may need to install the Mojo::Base module) (@INC
> contains:
> /srv/ccdapi/perl5/perlbrew/perls/perl-5.24.0/lib/site_perl/5.24.0/x86_64-linux
> Apr 28 16:41:48 vl-vm-sr824.lb.videotron.ca ccdapi[63200]: BEGIN
> failed--compilation aborted at 
> /srv/ccdapi/.perlbrew/libs/perl-5.24.0@ccdapi/bin/hypnotoad
> line 2.
> Apr 28 16:41:48 vl-vm-sr824.lb.videotron.ca systemd[1]: ccdapi.service:
> main process exited, code=exited, status=2/INVALIDARGUMENT
> Apr 28 16:41:48 vl-vm-sr824.lb.videotron.ca ccdapi[63201]: Can't locate
> Mojo/Base.pm in @INC (you may need to install the Mojo::Base module) (@INC
> contains:
> /srv/ccdapi/perl5/perlbrew/perls/perl-5.24.0/lib/site_perl/5.24.0/x86_64-linux
> Apr 28 16:41:48 vl-vm-sr824.lb.videotron.ca ccdapi[63201]: BEGIN
> failed--compilation aborted at 
> /srv/ccdapi/.perlbrew/libs/perl-5.24.0@ccdapi/bin/hypnotoad
> line 2.
> Apr 28 16:41:48 vl-vm-sr824.lb.videotron.ca systemd[1]: ccdapi.service:
> control process exited, code=exited status=2
> Apr 28 16:41:48 vl-vm-sr824.lb.videotron.ca systemd[1]: Unit
> ccdapi.service entered failed state.
> Apr 28 16:41:48 vl-vm-sr824.lb.videotron.ca systemd[1]: ccdapi.service
> failed.
> Apr 28 16:41:48 vl-vm-sr824.lb.videotron.ca systemd[1]: ccdapi.service
> holdoff time over, scheduling restart.
> Apr 28 16:41:48 vl-vm-sr824.lb.videotron.ca systemd[1]: start request
> repeated too quickly for ccdapi.service
> Apr 28 16:41:48 vl-vm-sr824.lb.videotron.ca systemd[1]: Failed to start
> MY CCDAPI LAB.
> -- Subject: Unit ccdapi.service has failed
> -- Defined-By: systemd
>
>
> So I've double-checked Mojo::Base exists ...
>
> [ccdapi@vl-vm-sr824 ~]$ find . | grep 'Mojo.*Base.pm'
> ./VM01/PROD/perl5/lib/perl5/Mojo/Base.pm
> ./VM01/perl5/lib/perl5/Mojo/Base.pm
> ./temp/report/bin/lib/Mojo/Base.pm
> ./.cpan/build/Mojolicious-7.37-yGj97y/blib/lib/Mojo/Base.pm
> ./.cpan/build/Mojolicious-7.37-yGj97y/lib/Mojo/Base.pm
> ./.perlbrew/libs/perl-5.24.0@ccdapi/lib/perl5/Mojo/Base.pm
> ./perl5/lib/perl5/Mojo/Base.pm
>
>
> And I have added the path with "use lib qw(/my/path/) such as
>
> [ccdapi@vl-vm-sr824 ~]$ head ./VM01/PROD/v1/ccdapi.pl
> use lib qw(/srv/ccdapi/perl5/lib/perl5/);
> use Mojolicious::Lite;
>
>
> But still it won't start. Can anyone help please ? I'm aware this seems
> like a general Perl problem though but not so sure what am I doing wrong or
> is there some sort of bug ?!
>
> Cheers,
> Luc
>
> --
> 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/af5527ae-18eb-49ae-91b9-37a1d7fb7a43n%40googlegroups.com
> 
> .
>

-- 
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/CABMkAVWTQfOSBLZdDZSq0eUqMygxWTgJAR7jTTS%3DGUkz0Z7b4w%40mail.gmail.com.


Re: [Mojolicious] multiple concurrent event loops

2021-02-19 Thread Dan Book
The first example that comes to mind is Mojo::UserAgent, which uses a
secondary IOLoop (from its ioloop attribute) for blocking requests, so that
it can run them in a blocking manner even while the main loop is active.

This mailing list is sorta deprecated for the Github discussions forum:
https://github.com/mojolicious/mojo/discussions

-Dan

On Fri, Feb 19, 2021 at 6:01 PM Felipe Gasper 
wrote:

> Hello,
>
> In a PR thread yesterday Sebastian mentioned that Mojo allows
> multiple concurrent event loops.
>
> When and why would someone want such a configuration?
>
> Thank you!
>
> cheers,
> -Felipe Gasper
>
> --
> 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/EED46BD6-1A44-4B7C-B5C9-50A4D276D17B%40felipegasper.com
> .
>

-- 
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/CABMkAVWBkwcTBb3PYwUHCEoVk717HhGoeD%3D8-rxJabuFB_%3DnFA%40mail.gmail.com.


Re: [Mojolicious] Hypnotoad ? Required

2020-11-26 Thread Dan Book
Note that prefork servers including hypnotoad are not supported on windows
(and the benefit of hypnotoad over the standard server is only hot
deployment, which also doesn't work on windows). You will just want to use
a regular single process daemon, which the cookbook also covers, and you
can proxy to it from apache in the same way, just make sure to set
production mode since the servers other than hypnotoad default to
development mode.

-Dan

On Thu, Nov 26, 2020 at 3:31 PM bs.machine...@gmail.com <
bs.machinemanagem...@gmail.com> wrote:

> So Hypnotoad or Apache mod_proxy seem like preferred setup or Elzar for
> Windows
>
> I guess I'll go down the hypnotoad path and see where it takes me
> Thanks
>
> On Thursday, November 26, 2020 at 11:07:01 AM UTC-8 Scotticles wrote:
>
>> https://docs.mojolicious.org/Mojolicious/Guides/Cookbook#DEPLOYMENT
>>
>> On Thu, Nov 26, 2020 at 11:55 AM bs.machine...@gmail.com <
>> bs.machine...@gmail.com> wrote:
>>
>>> Not sure I have this right.
>>> Is hypnotoad required to use mobolicious, or can I use Apache?
>>>
>>> --
>>> 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...@googlegroups.com.
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/mojolicious/e10c82c3-20a3-4452-82f1-d28f54427ebfn%40googlegroups.com
>>> 
>>> .
>>>
>> --
> 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/7f32a56b-1548-4ab5-beb1-5135280158c2n%40googlegroups.com
> 
> .
>

-- 
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/CABMkAVU33Bg72UW_b0NUowJcg81jEnakSeO2VrvLfpRB%3D6gqPQ%40mail.gmail.com.


Re: [Mojolicious] Problem with hypnotoad

2020-11-19 Thread Dan Book
Make sure your actions aren't going to hang up for excessive amounts of
time, or the manager process will attempt to replace it (possibly causing
your excessive forking). See
https://metacpan.org/pod/Mojo::Server::Hypnotoad#heartbeat_timeout
(defaults to 50 seconds)

Make sure you are invoking hypnotoad using its full path, and that it is
the hypnotoad installed for the same Perl you've installed all your
dependencies to.

Make sure you are using a fork safe database connection manager like
DBIx::Connector or Mojo::Pg, and not attempting to share any live database
connections across forks (e.g. the body of the Lite script will run in the
manager process before workers are forked from it - request handlers should
retrieve a new connection from your connection manager so they can connect
anew if needed).

-Dan

On Thu, Nov 19, 2020 at 4:57 PM Joseph Fridy  wrote:

> I have recently transitioned from solo development to beta testing for a
> Mojolicious::Lite application.  Upon this transition, I switched from my
> casual use of morbo to hypnotoad.  In order to not change my nginx
> configuration, I had hypnotoad listen on port 3000.  The application
> appeared and I made my beta testers aware of its existence and went to
> bed.  Some time the next day, I got word of failures.  When I tried to
> connect to the application, I could connect but I was unable to access
> database objects correctly.  The Mojolicious::Lite script is named
> setupTransfer.pl.  There were many tens of processes named setupTransfer.pl
> running on the server.  I attempted hypnotoad --stop setupTransfer.pl, but
> it failed with an error on Time::Piece.  I rather inelegantly killed all
> the setupTransfer.pl processes and hypnotoad.  I checked my script for
> errors, and found nothing salient.  I restarted hypnotoad, and all appeared
> to be working, but within a few hours setupTransfer.pl processes started to
> proliferate, apparently without bound.  I have stopped and restarted
> hypnotoad several times since.  For fear that this is a consequence of some
> confusion because of making hypnotoad listen on port 3000, I have changed
> my nginx configuration and switched to port 8080.  Clearly I am ignorant,
> and doing something stupid, but cursory documentation checks have not
> pointed out my error.  hypnotoad starts with an initial inventory of
> setupTransfer.pl processes of 9, and they appear to increase monotonically
> with activity.  The server (a fairly lightweight ec2 instance) starts to
> exhibit problems somewhere in the 60 or 70 range.
>
> What stupid thing am I doing?
>
> Regards,
>
> Joe Fridy
>
> --
> 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/CA%2Bj3PDg%3DTdMhCWnh6aNHenRX-HJcJTCgeQL5rK9riRHq1gHoUQ%40mail.gmail.com
> 
> .
>

-- 
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/CABMkAVUFWqd_So2wiY-M4rkzWbTX4U%2BZb_pywNY33rFWzQRDGw%40mail.gmail.com.


Re: [Mojolicious] Suggestions how to avoid "Useless use of private variable in void context" ?

2020-11-16 Thread Dan Book
That is, after the ->reply->exception.

-Dan

On Mon, Nov 16, 2020 at 12:18 PM Dan Book  wrote:

> A common idiom is `undef $tx;` since you are also done with the object at
> that point.
>
> -Dan
>
> On Mon, Nov 16, 2020 at 8:41 AM Felipe Gasper 
> wrote:
>
>> I think you could do:
>>
>> $tx = $tx;
>>
>> … instead. (It might be worth updating the FAQ to do that?)
>>
>> -F
>>
>> > On Nov 16, 2020, at 8:08 AM, Edward Baudrez 
>> wrote:
>> >
>> > Hello list
>> >
>> > There is this hint in the FAQ about keeping a strong reference to the
>> transaction object $tx around, so that the message "Transaction already
>> destroyed" does not appear in the logs:
>> >
>> >
>> https://docs.mojolicious.org/Mojolicious/Guides/FAQ#What-does-Transaction-already-destroyed-mean
>> >
>> > However, that yields a warning, viz. "Useless use of private variable
>> in void context" at the lone "$tx". Any hints how to avoid this warning?
>> >
>> >
>> > Kind regards
>> > Edward
>> >
>> > --
>> > 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/8b3ab4a2-5f18-4d1f-8743-82b573af26bbn%40googlegroups.com
>> .
>>
>> --
>> 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/F3AF3253-E058-4351-B913-12244352F95E%40felipegasper.com
>> .
>>
>

-- 
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/CABMkAVXepzVyiSJGku5TePBACbMfBPGNHAkW65yPBvUqa%3DAXsA%40mail.gmail.com.


Re: [Mojolicious] Suggestions how to avoid "Useless use of private variable in void context" ?

2020-11-16 Thread Dan Book
A common idiom is `undef $tx;` since you are also done with the object at
that point.

-Dan

On Mon, Nov 16, 2020 at 8:41 AM Felipe Gasper 
wrote:

> I think you could do:
>
> $tx = $tx;
>
> … instead. (It might be worth updating the FAQ to do that?)
>
> -F
>
> > On Nov 16, 2020, at 8:08 AM, Edward Baudrez 
> wrote:
> >
> > Hello list
> >
> > There is this hint in the FAQ about keeping a strong reference to the
> transaction object $tx around, so that the message "Transaction already
> destroyed" does not appear in the logs:
> >
> >
> https://docs.mojolicious.org/Mojolicious/Guides/FAQ#What-does-Transaction-already-destroyed-mean
> >
> > However, that yields a warning, viz. "Useless use of private variable in
> void context" at the lone "$tx". Any hints how to avoid this warning?
> >
> >
> > Kind regards
> > Edward
> >
> > --
> > 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/8b3ab4a2-5f18-4d1f-8743-82b573af26bbn%40googlegroups.com
> .
>
> --
> 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/F3AF3253-E058-4351-B913-12244352F95E%40felipegasper.com
> .
>

-- 
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/CABMkAVX-ky7kJKFqV6pOy2mCMdYZh%3Dmgog%2BqCbJSjXKkAJVyWw%40mail.gmail.com.


Re: [Mojolicious] Re: Mojo::Log and UTF-8

2020-10-31 Thread Dan Book
Any layer on standard handles will cause double encoding when a module like
Mojo::Log encodes to bytes before printing. These layers are global
unfortunately.

-Dan

On Sat, Oct 31, 2020 at 1:54 PM kon...@gmail.com  wrote:

> I found a problem. Some module did:
>
> binmode STDOUT, ':encoding(UTF-8)';
> binmode STDERR, ':encoding(UTF-8)';
>
> and, probably, when STDERR was redirected to STDOUT by Mojo::Log then
> double encoding occur.
>
> Is it worth to check that STDERR and STDOUT have not same layers before
> redirecting?
>
> On Saturday, October 31, 2020 at 6:16:55 PM UTC+2 Sebastian Riedel wrote:
>
>> Ok, data is encoded from UTF-8 into bytes when I log a message,
>>> but when this data is printed to STDERR
>>> How make it decoded from bytes to UTF-8 back?
>>> my terminal supports UTF-8 and I want see nice messages instead of
>>> ХабÐ
>>>
>>
>> UTF-8 *is* bytes. If you are encoding already encoded UTF-8 then you are
>> double encoding.
>>
>> --
>> 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/f276d64e-f215-47d8-af7b-893d9c200ef4n%40googlegroups.com
> 
> .
>

-- 
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/CABMkAVX4mqdx6m0HPR8fo5owa4B6rixb9i4bsocimop5755GEQ%40mail.gmail.com.


Re: [Mojolicious] Trouble with Mojolicious::Guides::Grow

2020-10-10 Thread Dan Book
This is not a perl module, it's a documentation page that comes with the
Mojolicious distribution. You can install it by installing any module in
that distribution, such as Mojolicious.

-Dan

On Sat, Oct 10, 2020 at 4:39 PM marckp  wrote:

>
> Hello community,
>
> I am new to Mojolicious. My os is centos 8. I'm having difficulty
> installing Mojolicious::Guides::Grow. The neither install commands succeed:
>
> > cpanm Mojolicious
> ! Finding Mojolicious::Guides::Growing on capnmtadb failed.
> ! Finding Mojolicious::Guides::Growing () on mirror http://www.cpan.org
> failed.
> ! Couldn't find module or a distribution Mojolicious::Guides::Growing
>
> > perl -MCPAN -e shell
> Database was generated on Fri, 09 Oct 2020 19:17:03 GMT
> Fetching with HTTP::Tiny:
> http://www.cpan.org/authors/01mailrc.txt.gz
> Reading '/home/aqlserv/.local/share/.cpan/sources/authors/01mailrc.txt.gz'
>
> DONE
> Fetching with HTTP::Tiny:
> http://www.cpan.org/modules/02packages.details.txt.gz
> Reading
> '/home/aqlserv/.local/share/.cpan/sources/modules/02packages.details.txt.gz'
>   Database was generated on Sat, 10 Oct 2020 19:56:00 GMT
>   HTTP::Date not available
> .
>   New CPAN.pm version (v2.28) available.
>   [Currently running version is v2.18]
>   You might want to try
> install CPAN
> reload cpan
>   to both upgrade CPAN.pm and run the new version without leaving
>   the current session.
>
>
> ...DONE
> Fetching with HTTP::Tiny:
> http://www.cpan.org/modules/03modlist.data.gz
> Reading
> '/home/aqlserv/.local/share/.cpan/sources/modules/03modlist.data.gz'
> DONE
> Writing /home/aqlserv/.local/share/.cpan/Metadata
> Warning: Cannot install Mojolicious::Guides::Growing, don't know what it
> is.
> Try the command
>
> i /Mojolicious::Guides::Growing/
>
> to find objects with matching identifiers.
>
> **
>
> I tried the suggested I tried the following command:
>
> cpan[2]> i /Mojolicious::Guides::Growing/
> No objects found of any type for argument /Mojolicious::Guides::Growing/
>
> And, again not luck.
>
> I'm I missing a repository in /etc/yum.repos.d ? or is there some other
> problem?
>
> Thank you for your consideration,
> Marc
>
>
>
>
>
>
> --
> 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/5f2a8ed4-9328-4246-bbfb-e1dd04310bf7n%40googlegroups.com
> 
> .
>

-- 
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/CABMkAVXQ%2BriAGoUsn0%3DSCEv5JL0VUd%2Bz2V5eo74hgRLSLJNuTQ%40mail.gmail.com.


Re: [Mojolicious] How to use put_p or put properly in the controller?

2020-07-15 Thread Dan Book
The URL you are PUTting to does not appear to expect a form, but raw
content, so you will not want to use the "form" generator. You can pass raw
content as a bare argument like so:

$self->ua->put_p($url, $file_object->asset->slurp);

You will probably also want to set a Content-Type header for the MIME type
of the file contents. This would be set by a hash between the URL and
content, there are some examples in
https://metacpan.org/pod/Mojo::UserAgent#SYNOPSIS.

-Dan

On Wed, Jul 15, 2020 at 10:00 PM Gordon Dollarnanda 
wrote:

>
> hi guys,
>
>   Just started on a project with Mojolicious.
>
> Task: to upload a file into mojo and then issue a PUT command to transfer
> that file to a file server.
>
> I have been struggling to find documentation on using put_p/put in terms
> of the parameters for the syntax.
>
> Often, looking at https://mojolicious.org/perldoc/Mojo/UserAgent#put_p,
> it is too brief and not concise.
>  I have also tried to look for the source code in the Mojolicious
> framework which does the actual put_p/put to no avail. I had looked up the
> source of Mojo  :: UserAgen
> t and the packages it is
> "use"-ing also to no avail.
>
> 
>$self->ua->put_p(
>
># my_target_url_object is a Mojo::URL with the
># user info and actual url of the
># file server defined.
>
># $file_object is a Mojo::File::Asset representing a file I
> had uploaded from my local machine
>
> *$my_target_url_object => form => {*
>
> *'content' => $file_object->asset->{'content'},
> }*
> )->then(
> sub ($tx) {
> return $self->parse_response_p($tx);
> }
> )->catch(
> sub($error) {
> p->reject("Connection error: $error");
> }
> );
> ---
> When I use the put call above,  the content of my input file becomes
> "content=+Why+Georgia%3F%0A" instead of just "Why Georgia" (which was what
> I had uploaded earlier).
> I must be doing something wrong.
>
>  I have since tried many variations  to the call to put_p to no avail.
> Sometimes, if i do not provide the hash key, 'content', the actual cost
> when i cat the file in the target webserver directory would be literally
> 'HASH%3234234234';
>
> Can any one please point me to proper documentation clearly describing how
> to execute a put/put_p in a  Mojolicious controller?
>
> Thank you, guys
>
>
> Gordon
>
>
>
>
>
> --
> 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/19d370c9-81e3-4a52-aac9-254eef693bb8n%40googlegroups.com
> 
> .
>

-- 
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/CABMkAVXTWi%3DLbW%3DW_4B2%2BCfbJFattYVB9Sh%3DxMsAsP3Eg60zYA%40mail.gmail.com.


Re: [Mojolicious] set full package name for controller in a route

2020-06-21 Thread Dan Book
You need to set it as the namespace for the route:
https://metacpan.org/pod/Mojolicious::Guides::Routing#Namespaces

-Dan

On Sun, Jun 21, 2020 at 12:35 PM Miguel Prz  wrote:

> I want to reuse a set of controllers of a different hierarchy (starting
> with MyOther) used by my application (MyApp::Controller). But when I set:
>
> $app->routes->get('/init/:id')->to(controller =>"MyOther::Controller",
> action=> 'init' );
>
> I get an error in run time: (...) Controller "MyApp::MyOther::Controller"
> does not exist
>
> I don't know how to avoid the automatic "MyApp::" prefix
>
> Thanks!
>
> --
> 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/2abe60b0-ca69-4f87-9c6d-5a9b22d7e1cdo%40googlegroups.com
> 
> .
>

-- 
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/CABMkAVV2VkCdHn2e5REqZ42kC4syKM2CsUjTUYPejSnqLDG%2Bqg%40mail.gmail.com.


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] Best alternative for client / server polling?

2020-05-18 Thread Dan Book
Mojo::UserAgent is a great websocket client. See
https://metacpan.org/pod/Mojolicious::Guides::Cookbook#WebSockets, and for
the server
https://metacpan.org/pod/Mojolicious::Guides::Cookbook#WebSocket-web-service
.

-Dan

On Mon, May 18, 2020 at 7:47 PM Miguel Manso  wrote:

> Hi there,
>
> Ive a Perl client that fetched some data every 3 seconds and post it to an
> API. Both client and server are written using mojo. Client uses
> Mojo::UserAgent to post JSON and server is a Mojolicious app being served
> with hypnotoad.
>
> I can have dozens of these clients which mean that each of them will be
> posting data and receiving from the server every 3 secs. I can easily do
> this using basic post calls but I wonder if there is a better way to
> achieve the same? Something like keeping connections opened for a period of
> time while sending and receiving data through the same connection?
>
> Ive seen websockets info but it seems it’s allways oriented to the client
> being in JavaScript.
>
> Any thoughts on the subject?
>
> Thanks in advance.
>
> --
> 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/127f7769-222c-4e76-80bf-af36df28a5e0%40googlegroups.com
> .
>

-- 
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/CABMkAVU4OL2D6j8hmXpPwTif-5KW2WTDeeF2Enczmizod0Q6uQ%40mail.gmail.com.


Re: [Mojolicious] Re: Problem with streaming...

2020-05-15 Thread Dan Book
Take a look at the proxy helpers added recently, at the least they should
provide inspiration:
https://metacpan.org/pod/Mojolicious::Plugin::DefaultHelpers#proxy-%3Eget_p

-Dan

On Fri, May 15, 2020 at 1:13 AM Joseph Fridy  wrote:

> I have Mojo::UserAgent working to get the file from AWS S3 (including all
> the crypto foo), but I cannot stream its output from a controller attached
> to a Mojolicious::Lite route.  I am running into the same problem as is
> discussed in this thread from 2018:
>
> https://groups.google.com/forum/#!topic/mojolicious/fIGwnDOxl2E
>
> $ua->start($tx) is a blocking call, and as a result my chunks merely
> append to a buffer with nowhere to go until memory fills up.
> Unfortunately, if the way to solve this problem is answered in the
> responses to the thread above, said answer is too subtle for me to suss out.
>
> So, to restate my problem in words:
>
> given a Mojo::UserAgent transaction that can read a very large file, how
> can I stream its output, buffer by buffer, into a browser via a
> Mojolicious::Lite route?
>
> Regards,
>
> Joe Fridy
>
>
> --
> 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/ce448a79-c8d4-4098-b0b0-d9564259b632%40googlegroups.com
> 
> .
>

-- 
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/CABMkAVWo9iLVHZMF0YaGkCEekqXQ_XN4bLZDRB-4%3DJ6O9ezPgg%40mail.gmail.com.


Re: [Mojolicious] Re: curl works, Mojo::UserAgent doesn't

2020-05-15 Thread Dan Book
The built in "multipart" generator is pretty similar to this. You need to
create the parts and set the content type yourself still but it does give
you a little flexibility with hashrefs. See the end of the docs for
https://metacpan.org/pod/Mojo::UserAgent::Transactor#tx

-Dan

On Fri, May 15, 2020 at 12:10 AM Stefan Adams  wrote:

>
>
> On Thu, May 14, 2020 at 7:52 AM 'Michael Lackhoff' via Mojolicious <
> mojolicious@googlegroups.com> wrote:
>
>> When I change the sequence of the form parameters in curl, it fails in
>> the same way. So I guess the sequence is important and my question now is:
>>   Is there a way to pass the form parameters with fixed sequence in M::U
>> (the form-hash of course has a random order)? Perhaps as an array?
>>
>
> Good question.  Probably what you want then is to override the built-in "
> form "
> generator.  You can either override (by simply redefining it), or you can 
> create
> your own generator
> 
> and use it.
>
> $ua->transactor->add_generator(fritz => sub {
>   my ($t, $tx, $args) = @_;
>   my ($sid, $pwd, $config) = @$args;
>   my $sorted_parts = [...];
>   $tx->req->content->parts($sorted_parts);
> });
> $ua->post('http://fritz.box/cgi-bin/firmwarecfg' => fritz => [$SID,
> $BAKPWD, undef]);
>
> You could use a hash instead of an array for your fritz args if you wanted
> to, and still pull out the pieces you want to assemble the array as
> desired.  It's very flexible.
>
> But since you're currently using the "form" generator and learning a good
> deal about it and have determined a solution using the form generator, you
> might want to copy the form generator into your own fritz generator and
> then do the differences you need to (as you wished).  Or you might be able
> to simplify it and just do the content->parts as you alluded to.
> TMTOWTDI!  :D
>
> --
> 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/CACyQ%2BFRSawHXv92ScBL8nc2U_dWVFWwD5KnLqwjCvtKdX8eaPg%40mail.gmail.com
> 
> .
>

-- 
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/CABMkAVWK%3Dki20sC_fhzQpWskD9qrB0qygZuJWMTp2Zsy1zewdw%40mail.gmail.com.


Re: [Mojolicious] Problem with streaming...

2020-05-04 Thread Dan Book
So there is a lot here and there's definitely easier ways to do it but just
to start, Mojo::UserAgent can handle the streaming response in a more async
manner so you may want to start by replacing the shell out to curl with
that. Then see
https://metacpan.org/pod/Mojolicious::Guides::Cookbook#Streaming-response for
a way to deal with the response as it is received, and
https://metacpan.org/pod/Mojolicious::Guides::Rendering#Streaming for how
to write it to the response.

-Dan

On Mon, May 4, 2020 at 3:05 AM Joseph Fridy  wrote:

> I am attempting to stream the output of a curl command with Mojolicious.
> The curl command looks (roughly) like this:
>
> curl -H "x-amz-server-side-encryption-customer-algorithm:AES256" -H
> "x-amz-server-side-encryption-cust\
>
> omer-key:secretKey=" -H "x-amz-server-side-encryption-customer-key-M\
>
> D5:HashOfASecret==" 
> "https://mybucket.s3.amazonaws.com/obscureFileLocation?AWSAccessKeyId=secretStuff=1588568911=moreSecrets;
> --\
>
> dump-header header.461 --silent
>
>
> The curl command references a pre-signed URL of a file in AWS stored with
> Server Side Encryption with Client Side Keys (SSE-C), and supplies the
> necessary key information via HTTP headers (the -H command options).  The
> curl command works - but I don't want my users to have to have a system
> with curl on it to access their files.  The plan is to open the curl
> command as input to a pipe, and stream its output to the user's browser
> with Mojolicious.  The curl command also dumps out the HTTP headers from
> Amazon, so they can be used by Mojolicious.  They look like this:
>
>
> x-amz-id-2:
> sgMzHD2FJEGJrcbvzQwdhZK6mxUW+ePd6xdghTfgSlV45lMhliIw4prfk4cZMTHbS4fJN8N7xio=
>
> x-amz-request-id: 99B9CA56083DD9ED
>
> Date: Mon, 04 May 2020 04:57:22 GMT
>
> Last-Modified: Sat, 02 May 2020 03:47:35 GMT
>
> ETag: "b3a11409be2705e4581119fa59af79d3-1025"
>
> x-amz-server-side-encryption-customer-algorithm: AES256
>
> x-amz-server-side-encryption-customer-key-MD5: HashOfSecretKey==
>
> Content-Disposition: attachment; filename = "fiveGigFile"
>
> Accept-Ranges: bytes
>
> Content-Type: application/octet-stream; charset=UTF-8
>
> Content-Length: 5368709125
>
> Server: AmazonS3
>
>
> Note that the file is 5Gig.
>
>
>
> This is my stab at streaming with Mojolicious:
>
>
> use strict;
> use Mojolicious::Lite;
> use FileHandle;
> use Digest::MD5;
>
> any '/' => sub {
>   my $c = shift;
>   $c->render(template => "test");
> };
>
> any 'pickup' => sub {
>   my $c = shift;
>   my $nGigs = 0;
>   my $nMegs = 0;
>   $| = 1;
>   open(CURLCMD,"curlCmd");
>   my $curlCmd = ;
>   if ($curlCmd =~ /dump-header\s*(\S+)\s+/) {
>
> my $headerFile = $1;
> open(my $curl,"$curlCmd |");
> binmode $curl;
> my $initialized = 0;
> my $digester = Digest::MD5->new;
>
>   my $transferLength = 0;
>
>   my $drain;
>
>   $drain = sub {
>
>   my $c = shift;
>
>   my $chunk;
>
>   sysread($curl,$chunk,1024*1024);
>
>   if (!$initialized) {
>   # read the headers, and set up the transfer...
>
>open(HEADERS,$headerFile);
>
>while(my $line = ) {
>
>  $c->res->headers->parse($line);
>
>}
>close(HEADERS);
>
>$initialized = 1;
>
>print "header initialization completed for the following
> headers\n";
>
>print join("\n",@{$c->res->headers->names}),"\n";
>
>   }
>
>   if ($initialized) {
>
>  while (length($chunk)) {
>
>$digester->add($chunk);
>
>$transferLength += length($chunk);
>
>$c->write($chunk,$drain);
>
>my $currentMegs = int($transferLength/(1024*1024));
>
>if (($currentMegs > $nMegs) && ($currentMegs < 1024)) {
>
>  print "TransferLength: $transferLength\n";
>
>  $nMegs = $currentMegs;
>
>}
>
>my $currentGigs = int($transferLength/(1024*1024*1024));
>
>if ($currentGigs > $nGigs) {
>
>  print "TransferLength: $transferLength\n";
>
>  $nGigs = $currentGigs;
>
>}
>
>  }
>
>  if (length($chunk) <= 1) {
>
>if ($chunk == 0) {
>
> print "End of file found on curl pipe.";
>
> print "$transferLength bytes transmitted\n";
>
> print "with an MD5 hash of ",$digester->hexdigest,"\n";
>
> $drain = undef;
>
>}
>
>if (!defined $chunk) {
>
> print "Transfer error encountered on curl pipe.\n";
>
> print "Error:",$!,"\n";
>
> $drain = undef;
>
>   }
>
> }
>
>   }
>
> };
>
> $c->$drain;
>
>   }
>
> };
>
> app->start;
>
> __DATA__
>
>
> @@ test.html.ep
>
> 
>
> 
>
> 
>
> Test of curl streaming... 
>
> 
>
> 
>
>
>
> When I ran this the first time, it read about 606MB of data, and the
> server crashed with an "Out of memory!".  Subsequent runs failed at about
> 139MB, with a server crash and no "Out of memory!" message.
>
>
> Obviously, 

Re: [Mojolicious] Mojo::Reactor

2020-04-18 Thread Dan Book
The reactor is essentially an abstract class for low level event loop
implementations, stripped to the functionality that each implementation can
implement differently. They don't do anything except watch filehandles and
set timers, start and stop, and run callbacks when something happens while
running. Mojo::IOLoop is the user interface that can decide what reactor
implementation to use, implements the singleton that different parts of the
process can hook into, and implements higher level abstractions like
streams, clients, and servers.

-Dan

On Sat, Apr 18, 2020 at 11:26 PM Stefan Adams  wrote:

> There's a current PR for addressing an issue regarding Mojo::Reactor. I
> feel like I have a good understanding of all the parts of Mojolicious,
> except Mojo::Reactor. I simply do not understand it at all. My confusion is
> increased by the similarity with Mojo::IOLoop. Much of the docs make use of
> IOLoop modules but I can't think of an example that uses Reactor.
>
> Can anyone provide some insight into this module, what it's for, and how
> and why it's different from IOLoop?
>
> --
> 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/CACyQ%2BFQPo67qOjjr7xuWSeTb%2BC8axQUVEqiHWg3_ryBE6Q8TQg%40mail.gmail.com
> 
> .
>

-- 
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/CABMkAVVtwONXioM1_k9Zhfy82AzcVxnHk9A3JLSrVqN%2BEBmZRQ%40mail.gmail.com.


Re: [Mojolicious] $c->log

2020-04-09 Thread Dan Book
Oh I see, setting it in the model attribute. No, that won't work in an
asynchronous application, because two requests may share a model object.

-Dan

On Thu, Apr 9, 2020 at 8:55 PM Dan Book  wrote:

> Yes...? That is passing $c->log each time the helper is called, which is
> what was suggested.
>
> -Dan
>
> On Thu, Apr 9, 2020 at 7:43 PM Stefan Adams  wrote:
>
>> Hmm...  But isn't this below including the context of the request ID for
>> each request?
>>
>> $self->helper(model => sub {$model->log(shift->log)});
>>
>>
>> Each request will have a different context.
>>
>> Using apachebench to concurrently send requests to the preforking
>> application, we get this:
>>
>> $ perl script/my_app prefork & ab -n 100 -c 100 http://localhost:3000/
>> [2020-04-09 23:28:01.39904] [12961] [debug] [3457c2a0] GET "/"
>> [2020-04-09 23:28:01.39820] [12962] [debug] [c759c8bd] Routing to a
>> callback
>> [2020-04-09 23:28:01.39929] [12962] [debug] [c759c8bd] got: model logged
>> with request id
>> [2020-04-09 23:28:01.39940] [12959] [debug] [b0ba4af8] GET "/"
>> [2020-04-09 23:28:01.39953] [12959] [debug] [b0ba4af8] Routing to a
>> callback
>> [2020-04-09 23:28:01.39959] [12959] [debug] [b0ba4af8] got: model logged
>> with request id
>> [2020-04-09 23:28:01.39967] [12962] [debug] [c759c8bd] 204 No Content
>> (0.002487s, 402.091/s)
>> [2020-04-09 23:28:01.39969] [12959] [debug] [b0ba4af8] 204 No Content
>> (0.000277s, 3610.108/s)
>> [2020-04-09 23:28:01.40082] [12962] [debug] [b38bd53f] GET "/"
>> [2020-04-09 23:28:01.40088] [12960] [debug] [b0ba4af8] GET "/"
>> [2020-04-09 23:28:01.40102] [12961] [debug] [3457c2a0] Routing to a
>> callback
>> [2020-04-09 23:28:01.40118] [12960] [debug] [b0ba4af8] Routing to a
>> callback
>> [2020-04-09 23:28:01.40118] [12961] [debug] [3457c2a0] got: model logged
>> with request id
>> [2020-04-09 23:28:01.40125] [12960] [debug] [b0ba4af8] got: model logged
>> with request id
>> [2020-04-09 23:28:01.40139] [12960] [debug] [b0ba4af8] 204 No Content
>> (0.000497s, 2012.072/s)
>> [2020-04-09 23:28:01.40148] [12961] [debug] [3457c2a0] 204 No Content
>> (0.002434s, 410.846/s)
>> [2020-04-09 23:28:01.40207] [12962] [debug] [b38bd53f] Routing to a
>> callback
>> [2020-04-09 23:28:01.40221] [12962] [debug] [b38bd53f] got: model logged
>> with request id
>> [2020-04-09 23:28:01.40239] [12962] [debug] [b38bd53f] 204 No Content
>> (0.001559s, 641.437/s)
>>
>> It shows that the logging context used in the model's get method has the
>> same context as in the routing action that renders the response.
>>
>>
>> On Thu, Apr 9, 2020 at 6:19 PM Dan Book  wrote:
>>
>>> No, the purpose of passing the log from each request is that it includes
>>> the context of the request ID (using the new context feature of Mojo::Log).
>>>
>>> -Dan
>>>
>>> On Thu, Apr 9, 2020 at 7:12 PM Stefan Adams  wrote:
>>>
>>>> Excellent!  I'm not finding there to be any difference, either.  Thank
>>>> you for the reply!
>>>>
>>>> As precise as the documentation is, I thought I would check to make
>>>> sure there wasn't a good reason for it.
>>>>
>>>> The documentation shows that the controller log helper can be passed to
>>>> a model in this way...  Rather than passing the log helper to *each* method
>>>> as shown in the documentation, could we store it in the model object so
>>>> that all methods would be able to use it and not need to have the log
>>>> helper called explicitly each time?
>>>>
>>>> Here's an example gist
>>>> <https://gist.github.com/s1037989/8993ddb90778befb51a4f334087a97ca>.
>>>>
>>>> On Thu, Apr 9, 2020 at 5:59 PM Dan Book  wrote:
>>>>
>>>>> I don't believe there would be any difference.
>>>>>
>>>>> -Dan
>>>>>
>>>>> On Thu, Apr 9, 2020 at 6:13 PM Stefan Adams 
>>>>> wrote:
>>>>>
>>>>>> In Mojolicious::Plugin::DefaultHelpers#og
>>>>>> <https://mojolicious.org/perldoc/Mojolicious/Plugin/DefaultHelpers#log>
>>>>>>
>>>>>> I suspect there is a good, fundamental reason behind this decision in
>>>>>> the documents, but I'm not sure what it is.
>>>>>>
>>>>>> Why is $log passed to the model method
>>>>>>
>&

Re: [Mojolicious] $c->log

2020-04-09 Thread Dan Book
No, the purpose of passing the log from each request is that it includes
the context of the request ID (using the new context feature of Mojo::Log).

-Dan

On Thu, Apr 9, 2020 at 7:12 PM Stefan Adams  wrote:

> Excellent!  I'm not finding there to be any difference, either.  Thank you
> for the reply!
>
> As precise as the documentation is, I thought I would check to make sure
> there wasn't a good reason for it.
>
> The documentation shows that the controller log helper can be passed to a
> model in this way...  Rather than passing the log helper to *each* method
> as shown in the documentation, could we store it in the model object so
> that all methods would be able to use it and not need to have the log
> helper called explicitly each time?
>
> Here's an example gist
> <https://gist.github.com/s1037989/8993ddb90778befb51a4f334087a97ca>.
>
> On Thu, Apr 9, 2020 at 5:59 PM Dan Book  wrote:
>
>> I don't believe there would be any difference.
>>
>> -Dan
>>
>> On Thu, Apr 9, 2020 at 6:13 PM Stefan Adams  wrote:
>>
>>> In Mojolicious::Plugin::DefaultHelpers#og
>>> <https://mojolicious.org/perldoc/Mojolicious/Plugin/DefaultHelpers#log>
>>>
>>> I suspect there is a good, fundamental reason behind this decision in
>>> the documents, but I'm not sure what it is.
>>>
>>> Why is $log passed to the model method
>>>
>>> # Pass logger with context to modelmy $log = $c->log;
>>> $c->some_model->create({foo => $foo}, $log);
>>>
>>>
>>> Instead of $c->log
>>>
>>> # Pass logger with context to model
>>> $c->some_model->create({foo => $foo}, $c->log);
>>>
>>>
>>> --
>>> 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/CACyQ%2BFTSncQ%3D2ff9wf5Q6wOOH0RQp96-LPMbNyv2sGoJNri1eg%40mail.gmail.com
>>> <https://groups.google.com/d/msgid/mojolicious/CACyQ%2BFTSncQ%3D2ff9wf5Q6wOOH0RQp96-LPMbNyv2sGoJNri1eg%40mail.gmail.com?utm_medium=email_source=footer>
>>> .
>>>
>> --
>> 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/CABMkAVV%2BOE7OERWzmc0-h7OhobvAteKqVAhWQJkK1kxyQY8ZqA%40mail.gmail.com
>> <https://groups.google.com/d/msgid/mojolicious/CABMkAVV%2BOE7OERWzmc0-h7OhobvAteKqVAhWQJkK1kxyQY8ZqA%40mail.gmail.com?utm_medium=email_source=footer>
>> .
>>
> --
> 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/CACyQ%2BFTpazf5vzBE7wVr0tadTt%3DxXKTCBN5NvWMRFJv4Wi46Dg%40mail.gmail.com
> <https://groups.google.com/d/msgid/mojolicious/CACyQ%2BFTpazf5vzBE7wVr0tadTt%3DxXKTCBN5NvWMRFJv4Wi46Dg%40mail.gmail.com?utm_medium=email_source=footer>
> .
>

-- 
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/CABMkAVVqT%3DTYO2rMY_NSSPC8v4m9R-S_Ckz1LoEkxvCdHgfTVw%40mail.gmail.com.


Re: [Mojolicious] $c->log

2020-04-09 Thread Dan Book
I don't believe there would be any difference.

-Dan

On Thu, Apr 9, 2020 at 6:13 PM Stefan Adams  wrote:

> In Mojolicious::Plugin::DefaultHelpers#og
> 
>
> I suspect there is a good, fundamental reason behind this decision in the
> documents, but I'm not sure what it is.
>
> Why is $log passed to the model method
>
> # Pass logger with context to modelmy $log = $c->log;
> $c->some_model->create({foo => $foo}, $log);
>
>
> Instead of $c->log
>
> # Pass logger with context to model
> $c->some_model->create({foo => $foo}, $c->log);
>
>
> --
> 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/CACyQ%2BFTSncQ%3D2ff9wf5Q6wOOH0RQp96-LPMbNyv2sGoJNri1eg%40mail.gmail.com
> 
> .
>

-- 
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/CABMkAVV%2BOE7OERWzmc0-h7OhobvAteKqVAhWQJkK1kxyQY8ZqA%40mail.gmail.com.


Re: [Mojolicious] Startup/Shutdown hook for worker processes

2020-03-27 Thread Dan Book
You could try shutting it down in an END {} block. To do this you would
need to store the instance to shut down by process ID so you know which one
to shut down.

-Dan

On Fri, Mar 27, 2020 at 8:31 AM 'Frank Brendel' via Mojolicious <
mojolicious@googlegroups.com> wrote:

> Hi,
>
> my application needs to load Selenium::Chrome for every single worker
> process.
> I made this via
> Mojo::IOLoop->next_tick(sub {
>   $Self->{Chrome} = Selenium::Chrome->new(
>  extra_capabilities => {
> chromeOptions => {
>args => [
>   'headless', 'no-sandbox', 'window-size=1400,900',
>   'disk-cache-size=0', 'disable-gpu',
> 'v8-cache-options=off'
>]
> }
>  },
>   );
>
> But I have no idea where to shutdown the chrome binary.
>
> I've tried it via the
> Mojo::IOLoop->on(finish
>
> event but that stops the chromedriver to early so that outstanding
> Selenium requests fail.
>
> Thanks
> Frank
>
> --
> 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/58314c80-14ee-4cbe-8e2f-c7a5bebc7c0a%40googlegroups.com
> 
> .
>

-- 
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/CABMkAVVkdrq%3DunQ02jMB8PUZi539wxHFP7h_mDi6ObF9rcqBXg%40mail.gmail.com.


Re: [Mojolicious] Dynamically set the controller in "under"

2020-03-15 Thread Dan Book
Correct, if it works in any sense it's accidental.

-Dan

On Sun, Mar 15, 2020 at 11:39 PM Stefan Adams  wrote:

> Thanks, Dan! Does that mean, then, that what I provided as a solution is
> actually a bad idea and may not always work as I'm anticipating?
>
> On Sun, Mar 15, 2020, 9:41 PM Dan Book  wrote:
>
>> Mojolicious does not support dynamic routing. Once a route has matched,
>> the only thing an under can determine is if the dispatch chain continues or
>> stops.
>>
>> -Dan
>>
>> On Sun, Mar 15, 2020 at 10:28 PM Stefan Adams  wrote:
>>
>>> I'm wanting to dynamically set the controller in, for example, an under
>>>
>>> my $admin = $self->routes->under('/admin' => sub { ... });
>>>
>>>
>>> The only way I have found is like so
>>>
>>> my $admin = $self->routes->under('/admin' => sub {
>>>   shift->match->stack->[-1]->{controller} = 'something';
>>> });
>>>
>>>
>>> Is this the right way?  The best way?  The only way?
>>>
>>> I could have sworn it was possible to set the controller in an under by
>>> simply setting it in the stash, but that is not working for me.
>>>
>>> --
>>> 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/CACyQ%2BFTGpPNNfc5E9oPj-KzV6nD4-%3DBXQHyz-iJHwoeWCi3bjg%40mail.gmail.com
>>> <https://groups.google.com/d/msgid/mojolicious/CACyQ%2BFTGpPNNfc5E9oPj-KzV6nD4-%3DBXQHyz-iJHwoeWCi3bjg%40mail.gmail.com?utm_medium=email_source=footer>
>>> .
>>>
>> --
>> 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/CABMkAVUZDdegns3wRWojpXJX15vePVtY%3DvRkfh-RKyar88JPxw%40mail.gmail.com
>> <https://groups.google.com/d/msgid/mojolicious/CABMkAVUZDdegns3wRWojpXJX15vePVtY%3DvRkfh-RKyar88JPxw%40mail.gmail.com?utm_medium=email_source=footer>
>> .
>>
> --
> 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/CACyQ%2BFRjaVzGikOFOAWuLX2%2BbGU5GjsD%3DDX3p_B4WEcS9WxOAg%40mail.gmail.com
> <https://groups.google.com/d/msgid/mojolicious/CACyQ%2BFRjaVzGikOFOAWuLX2%2BbGU5GjsD%3DDX3p_B4WEcS9WxOAg%40mail.gmail.com?utm_medium=email_source=footer>
> .
>

-- 
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/CABMkAVW9tQr1N9Gx_y%2BF6YMJj%2BZU2hCFF%2BMt9OOOZSi4qzN-tw%40mail.gmail.com.


Re: [Mojolicious] Time::Local 2020 issue

2020-03-06 Thread Dan Book
Looking at the usage of timegm in Mojo::Date, it is used to parse date
formats that either provide a 4 digit year or a 2 digit year which is
ambiguous as to its century (RFC 850). As such I think the original timegm
year parsing is actually the best option here, an alternative is to always
interpret 2 digit years as being in the 1900s and use timegm_modern.

-Dan

On Fri, Mar 6, 2020 at 11:58 AM Dan Book  wrote:

> Updating Time::Local does not fix anything by itself, it only gives you
> more options. Additionally, the dependency is a minimum requirement, you
> are free to install the newer version that does not fail its own tests. I
> will audit the use of Time::Local to ensure it is not falling prey to the
> issue.
>
> -Dan
>
> On Fri, Mar 6, 2020 at 5:46 AM Raluca Farcas 
> wrote:
>
>> Time::Local updated some unit tests in version 1.26 to resolve this
>> problem: https://rt.cpan.org/Public/Bug/Display.html?id=124787. The test
>> should have failed in 2020 for previous versions. I've seen last version of
>> Mojolicious is still using Time::Local version 1.2. And on my application
>> this goes on failing the Time::Local unit test. Do you know about the
>> problem? Is there a chance to update your dependencies, especially
>> Time::Local to a version >= 1.26? Thanks in advance for the answer.
>>
>> --
>> 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/cc37b38e-362c-4316-90b3-1c502fe1ca33%40googlegroups.com
>> <https://groups.google.com/d/msgid/mojolicious/cc37b38e-362c-4316-90b3-1c502fe1ca33%40googlegroups.com?utm_medium=email_source=footer>
>> .
>>
>

-- 
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/CABMkAVVmhLXXo1DvLFftL70p3-YqJOZgdw0KO8pOZedUSMtoZw%40mail.gmail.com.


Re: [Mojolicious] Time::Local 2020 issue

2020-03-06 Thread Dan Book
Updating Time::Local does not fix anything by itself, it only gives you
more options. Additionally, the dependency is a minimum requirement, you
are free to install the newer version that does not fail its own tests. I
will audit the use of Time::Local to ensure it is not falling prey to the
issue.

-Dan

On Fri, Mar 6, 2020 at 5:46 AM Raluca Farcas  wrote:

> Time::Local updated some unit tests in version 1.26 to resolve this
> problem: https://rt.cpan.org/Public/Bug/Display.html?id=124787. The test
> should have failed in 2020 for previous versions. I've seen last version of
> Mojolicious is still using Time::Local version 1.2. And on my application
> this goes on failing the Time::Local unit test. Do you know about the
> problem? Is there a chance to update your dependencies, especially
> Time::Local to a version >= 1.26? Thanks in advance for the answer.
>
> --
> 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/cc37b38e-362c-4316-90b3-1c502fe1ca33%40googlegroups.com
> 
> .
>

-- 
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/CABMkAVX7bpZHgia4AC_o-kDhJV_XVnWoLJGTHSCMo7H%3DTXLM4w%40mail.gmail.com.


Re: [Mojolicious] Get an array from checkboxes

2020-03-02 Thread Dan Book
That is correct, it should return all "values" of checked items with that
"name". I don't know what the distinction of "new checked values" is that
you mention. Make sure the checkboxes are all within the same form tag.

-Dan

On Mon, Mar 2, 2020 at 10:38 AM mab974  wrote:

> Thanks Dan !
>
> It seems I get only the NEW checked values not all checked values.
> Do I use it the right way ?
>
>  my @members = @{$c->every_param('groupMembers')};
>
>
>
> Selon Dan Book  :
> > param returns a single value, by design, because this avoids the context
> > sensitivity bug that led to for example
> > https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2014-1572. To get
> > multiple values, use every_param, which returns an array reference:
> >
> >   my $groups = $c->every_param('groupMemberships');
> >
> > -Dan
> >
> > On Sun, Mar 1, 2020 at 3:46 PM mab974  wrote:
> >
> > > Hi,
> > >
> > > How do I get multiple checkbox values as an array?
> > > I always get the value of the last checked checkbox.
> > >
> > >
> > > my example :
> > > in template
> > >
> > >   %= check_box 'groupMemberships' => $groupname
> > >
> > > or when checked
> > >
> > > 
> > >
> > > and in controller
> > >
> > > my @groups = $c->param('groupMemberships');
> > >
> > > Thanks in advance.
> > >
> > > Regards,
> > >
> > > -*-
> > > mab974
> > >
> > > --
>
> -*-
> mab974
>
> --
> 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/20200302193802.4f94f42c5414f87a1cf133d8%40gmail.com
> .
>

-- 
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/CABMkAVWFJ1PAZ%3D7CY9J9MktTB-rNCo8A36p3K2uGppPhHTF7-w%40mail.gmail.com.


Re: [Mojolicious] Get an array from checkboxes

2020-03-01 Thread Dan Book
param returns a single value, by design, because this avoids the context
sensitivity bug that led to for example
https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2014-1572. To get
multiple values, use every_param, which returns an array reference:

  my $groups = $c->every_param('groupMemberships');

-Dan

On Sun, Mar 1, 2020 at 3:46 PM mab974  wrote:

> Hi,
>
> How do I get multiple checkbox values as an array?
> I always get the value of the last checked checkbox.
>
>
> my example :
> in template
>
>   %= check_box 'groupMemberships' => $groupname
>
> or when checked
>
> 
>
> and in controller
>
> my @groups = $c->param('groupMemberships');
>
> Thanks in advance.
>
> Regards,
>
> -*-
> mab974
>
> --
> 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/20200302002747.9c63598aae28de1f8a08e4ab%40gmail.com
> .
>

-- 
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/CABMkAVUHD3RYQChd0wNQLNs9ENVoxePNFeUug3At_eHy8L2k7Q%40mail.gmail.com.


Re: [Mojolicious] DATA templates

2020-02-22 Thread Dan Book
I believe it is required in that configuration to allow POD after the DATA
section. If you moved the POD before DATA (what I usually do) it wouldn't
be needed.

-Dan

On Sat, Feb 22, 2020 at 12:03 PM Stefan Adams  wrote:

>
>
> On Sat, Feb 22, 2020 at 10:56 AM Dan Book  wrote:
>
>> It is not well defined. __END__ and __DATA__ even serve the same purpose
>> within the main script file (but not in module files). I recommend not
>> combining them.
>>
>
> Interesting!  I did `mojo generate plugin` and it added perldoc after
> __END__ so I didn't think to remove it, but I wanted to add __DATA__.  What
> do you think about removing __END__ from the generator
> <https://github.com/mojolicious/mojo/blob/master/lib/Mojolicious/Command/Author/generate/plugin.pm#L110>
> ?
>
> --
> 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/CACyQ%2BFRivNu1RtmhDG2kM_HtiTqUHN%3DhjSJrwHdQgB5DLYoSpQ%40mail.gmail.com
> <https://groups.google.com/d/msgid/mojolicious/CACyQ%2BFRivNu1RtmhDG2kM_HtiTqUHN%3DhjSJrwHdQgB5DLYoSpQ%40mail.gmail.com?utm_medium=email_source=footer>
> .
>

-- 
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/CABMkAVXYnxdj%2B6QHGUkBk850tRKDG0YV-25t8WyEzxpOo8LO1A%40mail.gmail.com.


Re: [Mojolicious] DATA templates

2020-02-22 Thread Dan Book
It is not well defined. __END__ and __DATA__ even serve the same purpose
within the main script file (but not in module files). I recommend not
combining them.

-Dan

On Sat, Feb 22, 2020 at 10:45 AM Илья  wrote:

> To be honest, perl documentation doesn't shed any light on case where
> __END__ and __DATA__ tokens coexists in one file. But I'm sure that it is
> not mojolicious problem, but perl behaviour in that case.
> On 22.02.2020 18:40, Mike Lieman wrote:
>
> >The two control characters ^D and ^Z, and the tokens __END__ and __DATA__
> may be used to indicate the logical end of the script before the actual end
> of file. * Any following text is ignored.*
>
> https://perldoc.perl.org/perldata.html#Special-Literals
>
> On Sat, Feb 22, 2020 at 10:12 AM Stefan Adams  wrote:
>
>> I just spent more time than I should admit about figuring this out.
>>
>> *Templates in the DATA section must come before the END section.*
>>
>> Is this common to all of Perl that DATA must come before END? Can anyone
>> point me to a document resource for this, so that I can read it and beat it
>> into my head? This is not the first time I've gotten tripped up on this.
>> --
>> 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/CACyQ%2BFQZykiSrmiFxoEdRYB-KdOw%3DeDPTQ86zC%3DNu428EuOJEA%40mail.gmail.com
>> 
>> .
>>
> --
> 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/CAG2_C8CWUeAvZ6fguaaADBqzDV4PZBhvrh%2ByUBsx8H5g%3D6_xoQ%40mail.gmail.com
> 
> .
>
> --
> 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/9cf87eba-ab47-9e7c-285d-519abc39da77%40gmail.com
> 
> .
>

-- 
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/CABMkAVUKRaw%2BUD-MaSZw%2Bkyew1ONt%2BQgVv%2BzosYJ6wvHK9j0ng%40mail.gmail.com.


Re: [Mojolicious] Best practices for dynamic workflows

2020-02-14 Thread Dan Book
For distribution outside of CPAN, a cpanfile can specify "features" that
can be requested when installing dependencies like: cpanm --installdeps
--with-feature=foo .

https://metacpan.org/pod/cpanfile#feature

For CPAN distributions, you can use optional features as well, but most
people will ignore it because cpanm defaults to non-interactive. I would
recommend providing additional distributions as plugins which provide the
dependencies needed for their task.

-Dan

On Fri, Feb 14, 2020 at 8:12 AM Alberto Mijares  wrote:

> Dear mojo devs,
>
> I want to design and develop a generic framework for documents
> processing. Basically, a data input, validations, business rules,
> optional rendering and delivery. So, the data input module might be
> static but all the other modules would be custom according to the
> needs. For example, one might want to deliver to a S3 bucket while
> others might want to deliver via email or SMS.
>
> Now the question is: what's the best approach for easily installing
> and configuring such modules in the framework? The link between
> modules would be a queue, not sure about the backend for those queues
> yet, though, perhaps Pg or Celery. Ideally, when you install the
> framework it comes with default "dummy" modules with some very basic
> functionality that also serves as template for developing custom
> modules.
>
> Thanks in advance for your suggestions.
>
>
> Alberto Mijares
>
> --
> 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/CAGZBXN8s_aVkb81mQCnpeMO%2B7wOxyqWEKQ0My43TF3rbjqCDzg%40mail.gmail.com
> .
>

-- 
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/CABMkAVUpmFiDamB8Ze%3D4d%3DkStTgbADN%3DnnMfiuL-vZKeVk-MJA%40mail.gmail.com.


Re: [Mojolicious] Test::Mojo to test WS client?

2020-01-22 Thread Dan Book
You mentioned using Test::Mojo - the test file you mentioned does this, it
tests both client and server.

-Dan

On Wed, Jan 22, 2020 at 10:38 AM Dan Book  wrote:

> https://github.com/mojolicious/mojo/blob/master/t/mojo/websocket.t
>
> -Dan
>
> On Wed, Jan 22, 2020 at 10:34 AM Felipe Gasper 
> wrote:
>
>> Hello,
>>
>> I see t/mojolicious/websocket_lite_app.t in the Mojolicious
>> distribution, but this seems to test Mojo as a WS server. Are there any
>> examples of using Test::Mojo--or any other tool--to test Mojo-powered WS
>> clients?
>>
>> Thank you!
>>
>> -FG
>>
>> --
>> 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/80877B50-2AD9-4C15-9410-52D74C104161%40felipegasper.com
>> .
>>
>

-- 
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/CABMkAVVE1dvq-wv5HqTcXDExqUpOa4_%3DsZCZDh%3DZ7zJGvwDs4Q%40mail.gmail.com.


Re: [Mojolicious] Test::Mojo to test WS client?

2020-01-22 Thread Dan Book
https://github.com/mojolicious/mojo/blob/master/t/mojo/websocket.t

-Dan

On Wed, Jan 22, 2020 at 10:34 AM Felipe Gasper 
wrote:

> Hello,
>
> I see t/mojolicious/websocket_lite_app.t in the Mojolicious
> distribution, but this seems to test Mojo as a WS server. Are there any
> examples of using Test::Mojo--or any other tool--to test Mojo-powered WS
> clients?
>
> Thank you!
>
> -FG
>
> --
> 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/80877B50-2AD9-4C15-9410-52D74C104161%40felipegasper.com
> .
>

-- 
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/CABMkAVVwPgA-ShmkE1q5h-FvHzHUJNhbMtfEyy5FYVzW1%2BihWg%40mail.gmail.com.


Re: [Mojolicious] named route not working after upgrade from 7.33

2020-01-09 Thread Dan Book
And added:
https://github.com/mojolicious/mojo/wiki/Upgrading#upgrading-to-mojolicious-788

-Dan

On Thu, Jan 9, 2020 at 5:21 PM Dan Book  wrote:

> Placeholder syntax was changed from parentheses to chevrons <> in 7.75. I
> will add this to https://github.com/mojolicious/mojo/wiki/Upgrading once
> I figure out when the old syntax was actually removed.
>
> -Dan
>
> On Thu, Jan 9, 2020 at 5:17 PM 'Rolf Schaufelberger' via Mojolicious <
> mojolicious@googlegroups.com> wrote:
>
>> Hi,
>>  I have a route definition like this
>>
>> my $order = $r->any('/order')->to(controller => 'order');
>> $order->get('/')->to(action => 'index');
>> $order->post('/find')->to(action => 'find');
>> $order->get('/edit/:id')->to(action => 'index');
>> $order->get('/edit/:id(*tab)')->to(action => 'index', title => 'Auftrag
>> bearbeiten')->name('order_edit');
>>
>> in Order::find I then have :
>> ...
>> return $self->redirect_to('order_edit', id => $order->id) if $order;
>>
>> which works fine in 7.33
>>
>> After upgrading to 8.29 it doesn't work any more, instead I get
>>
>> [Mojolicious::Routes ] Routing to controller "Eller::Controller::Order"
>> and action "find" [Mojolicious::Controller ] 302 Found (0.089613s,
>> 11.159/s) [Mojolicious ] GET "/order/edit/243"
>>
>> Changing my routes to:
>>
>> my $order = $r->any('/order')->to(controller => 'order');
>> $order->get('/')->to(action => 'index');
>> $order->post('/find')->to(action => 'find');
>> $order->get('/edit/:id')->to(action => 'index')*->name('order_edit');*
>> $order->get('/edit/:id(*tab)')->to(action => 'index', title => 'Auftrag
>> bearbeiten');
>>
>> again works, yet, this isn't exactly the same.
>> I couldn't find any hints in the release notes, that sth. has changed for
>> the routing.
>>
>> "routes -v" gives
>> +/order  * order ^\/order +/  GET ^/?(?:\.([^/]+))?$ +/find 
>> POST find ^\/find/?(?:\.([^/]+))?$ +/edit/:id  GET editid
>> ^\/edit/([^/.]+)/?(?:\.([^/]+))?$ +/edit/:id(*tab)  GET "order_edit"
>> ^\/edit/([^/.]+)/?(?:\.([^/]+))?$
>>
>> for both 7.33 and 8.29
>>
>> Any idea?
>> Rolf
>>
>> --
>> 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/66b70122-cd26-4d14-8127-f4421526212b%40googlegroups.com
>> <https://groups.google.com/d/msgid/mojolicious/66b70122-cd26-4d14-8127-f4421526212b%40googlegroups.com?utm_medium=email_source=footer>
>> .
>>
>

-- 
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/CABMkAVWK2Uh5fSQ270JJguKCWSRQo1BfEOnHwt0ER303%2BU2fZw%40mail.gmail.com.


Re: [Mojolicious] named route not working after upgrade from 7.33

2020-01-09 Thread Dan Book
Placeholder syntax was changed from parentheses to chevrons <> in 7.75. I
will add this to https://github.com/mojolicious/mojo/wiki/Upgrading once I
figure out when the old syntax was actually removed.

-Dan

On Thu, Jan 9, 2020 at 5:17 PM 'Rolf Schaufelberger' via Mojolicious <
mojolicious@googlegroups.com> wrote:

> Hi,
>  I have a route definition like this
>
> my $order = $r->any('/order')->to(controller => 'order');
> $order->get('/')->to(action => 'index');
> $order->post('/find')->to(action => 'find');
> $order->get('/edit/:id')->to(action => 'index');
> $order->get('/edit/:id(*tab)')->to(action => 'index', title => 'Auftrag
> bearbeiten')->name('order_edit');
>
> in Order::find I then have :
> ...
> return $self->redirect_to('order_edit', id => $order->id) if $order;
>
> which works fine in 7.33
>
> After upgrading to 8.29 it doesn't work any more, instead I get
>
> [Mojolicious::Routes ] Routing to controller "Eller::Controller::Order"
> and action "find" [Mojolicious::Controller ] 302 Found (0.089613s,
> 11.159/s) [Mojolicious ] GET "/order/edit/243"
>
> Changing my routes to:
>
> my $order = $r->any('/order')->to(controller => 'order');
> $order->get('/')->to(action => 'index');
> $order->post('/find')->to(action => 'find');
> $order->get('/edit/:id')->to(action => 'index')*->name('order_edit');*
> $order->get('/edit/:id(*tab)')->to(action => 'index', title => 'Auftrag
> bearbeiten');
>
> again works, yet, this isn't exactly the same.
> I couldn't find any hints in the release notes, that sth. has changed for
> the routing.
>
> "routes -v" gives
> +/order  * order ^\/order +/  GET ^/?(?:\.([^/]+))?$ +/find 
> POST find ^\/find/?(?:\.([^/]+))?$ +/edit/:id  GET editid
> ^\/edit/([^/.]+)/?(?:\.([^/]+))?$ +/edit/:id(*tab)  GET "order_edit"
> ^\/edit/([^/.]+)/?(?:\.([^/]+))?$
>
> for both 7.33 and 8.29
>
> Any idea?
> Rolf
>
> --
> 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/66b70122-cd26-4d14-8127-f4421526212b%40googlegroups.com
> 
> .
>

-- 
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/CABMkAVVQXorrSzzbxbjNWrNFEeqE2ux0mj8_w%3DOY%3DAcoZDdYuQ%40mail.gmail.com.


Re: [Mojolicious] Best practices for embedding a javascript app in a Mojo app.

2019-11-07 Thread Dan Book
It's really just an organizational question. You can easily have the
javascript and the API as two separate projects and design them to work
independently, or as the same project so you can more easily coordinate
changes between them. In either case something will need to serve the
javascript files from the back-end as well.

-Dan

On Thu, Nov 7, 2019 at 10:51 AM Alberto Mijares  wrote:

> Hi guys,
>
> I need to write an API with its front-end in javascript. There's a
> node module I can install with npm that would be very helpful. Is it a
> good practice to have both projects in the same tree? Should I have
> separated projects?
>
> I never had to deal with frontend development before, so I have no
> idea how to do it following best practices.
>
> Thanks in advance.
>
> Regards,
>
>
> Alberto Mijares
>
> --
> 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/CAGZBXN-0yS%2Bi7AjH06DsS76b3AzB%3DqykyGTwXiXunLNySa6kAg%40mail.gmail.com
> .
>

-- 
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/CABMkAVVA9aN1utzpKTGoHm8fA5SOC7aSPsqLr1AUXquYzTTdbw%40mail.gmail.com.


Re: [Mojolicious] Re: mojo generate role

2019-10-23 Thread Dan Book
The general policy is the same as applied to plugins or things in the
Mojo:: namespace: it's fine to upload CPAN modules under them as long as
you defer to the core team if they want to claim the namespace.

-Dan

On Wed, Oct 23, 2019 at 6:50 PM Roger Crew  wrote:

> yes, mine actually is under ..::Author::generate::
>
> (didn't realize it was actually okay to pee in that space, although maybe
> this is more of a case of cant-do-anything-about-it; welcome to CPAN)
>
> On Wednesday, October 23, 2019 at 3:30:00 PM UTC-7, Dan Book wrote:
>>
>> Actually the generate command moved so it would be under
>> Mojolicious::Command::Author::generate::foo in recent versions.
>>
>> -Dan
>>
>> On Wed, Oct 23, 2019 at 6:25 PM Dan Book  wrote:
>>
>>> You would install it under Mojolicious::Command::generate, as described
>>> at
>>> https://metacpan.org/pod/Mojolicious::Guides::Cookbook#Adding-commands-to-Mojolicious.
>>> Easiest if you have a local::lib and simply put it under
>>> ~/perl5/lib/perl5/Mojolicious/Command/...
>>>
>>> -Dan
>>>
>>> On Wed, Oct 23, 2019 at 6:16 PM Roger Crew 
>>> wrote:
>>>
>>>> what's the right way to get something like this
>>>> (i.e., new mojo generate commands, or variations/additional-options on
>>>> existing ones)
>>>> added to my 'mojo' command search space.
>>>>
>>>> I can't do it as a plugin, since plugin stuff doesn't becomes available
>>>> until you actually *add* the plugin to the application you're
>>>> currently working on (assuming it even *is *an application that you're
>>>> working on, as opposed to a plugin, or a role, or something else), and the 
>>>> mojo
>>>> generate commands are all for *creating* source-trees from scratch.
>>>>
>>>> About the only thing I can come up with is playing games with @INC in
>>>> order to swap in my own version of Mojo::HelloWorld to add stuff to
>>>> its ->commands,
>>>>
>>>> ... which all looks to be at least medium evil.
>>>>
>>>> but I also hate to ask for Yet Another Environment Variable (but maybe
>>>> that's the RIght Thing here?)
>>>>
>>>>
>>>> On Tuesday, October 1, 2019 at 6:23:53 AM UTC-7, Roger Crew wrote:
>>>>>
>>>>> so, on the theory that if I'm doing something at least twice there
>>>>> should be a script for it,
>>>>> I wrote a "mojo generate role", role.pm,
>>>>>
>>>>> that is mostly a ripoff of "mojo generate plugin" but with some better
>>>>> defaults
>>>>> i.e.,
>>>>>
>>>>> mojo generate role BaseClass RoleName
>>>>>
>>>>> creates a rudimentary development directory for the
>>>>> BaseClass::Role::RoleName role
>>>>> with a single testcase template (...that will actually work straight
>>>>> out of the box if you chose
>>>>> a baseclass that doesn't require arguments to build...).
>>>>>
>>>>> I can do a pull request if there's interest in this and you want
>>>>> actual code to look at.
>>>>>
>>>> --
>>>> 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 mojol...@googlegroups.com.
>>>> To view this discussion on the web visit
>>>> https://groups.google.com/d/msgid/mojolicious/e3795845-2934-4dce-b95f-a1d76fc9d6f4%40googlegroups.com
>>>> <https://groups.google.com/d/msgid/mojolicious/e3795845-2934-4dce-b95f-a1d76fc9d6f4%40googlegroups.com?utm_medium=email_source=footer>
>>>> .
>>>>
>>> --
> 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/4265d0f9-01bd-4f60-bd7a-b69fa3951d62%40googlegroups.com
> <https://groups.google.com/d/msgid/mojolicious/4265d0f9-01bd-4f60-bd7a-b69fa3951d62%40googlegroups.com?utm_medium=email_source=footer>
> .
>

-- 
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/CABMkAVWQNxv%3D-1gYP0tob31uTB8p0Ev9zUTVVOh4US7gLfKu2Q%40mail.gmail.com.


Re: [Mojolicious] Re: mojo generate role

2019-10-23 Thread Dan Book
Actually the generate command moved so it would be under
Mojolicious::Command::Author::generate::foo in recent versions.

-Dan

On Wed, Oct 23, 2019 at 6:25 PM Dan Book  wrote:

> You would install it under Mojolicious::Command::generate, as described at
> https://metacpan.org/pod/Mojolicious::Guides::Cookbook#Adding-commands-to-Mojolicious.
> Easiest if you have a local::lib and simply put it under
> ~/perl5/lib/perl5/Mojolicious/Command/...
>
> -Dan
>
> On Wed, Oct 23, 2019 at 6:16 PM Roger Crew  wrote:
>
>> what's the right way to get something like this
>> (i.e., new mojo generate commands, or variations/additional-options on
>> existing ones)
>> added to my 'mojo' command search space.
>>
>> I can't do it as a plugin, since plugin stuff doesn't becomes available
>> until you actually *add* the plugin to the application you're currently
>> working on (assuming it even *is *an application that you're working on,
>> as opposed to a plugin, or a role, or something else), and the mojo
>> generate commands are all for *creating* source-trees from scratch.
>>
>> About the only thing I can come up with is playing games with @INC in
>> order to swap in my own version of Mojo::HelloWorld to add stuff to its
>> ->commands,
>>
>> ... which all looks to be at least medium evil.
>>
>> but I also hate to ask for Yet Another Environment Variable (but maybe
>> that's the RIght Thing here?)
>>
>>
>> On Tuesday, October 1, 2019 at 6:23:53 AM UTC-7, Roger Crew wrote:
>>>
>>> so, on the theory that if I'm doing something at least twice there
>>> should be a script for it,
>>> I wrote a "mojo generate role", role.pm,
>>>
>>> that is mostly a ripoff of "mojo generate plugin" but with some better
>>> defaults
>>> i.e.,
>>>
>>> mojo generate role BaseClass RoleName
>>>
>>> creates a rudimentary development directory for the
>>> BaseClass::Role::RoleName role
>>> with a single testcase template (...that will actually work straight out
>>> of the box if you chose
>>> a baseclass that doesn't require arguments to build...).
>>>
>>> I can do a pull request if there's interest in this and you want actual
>>> code to look at.
>>>
>> --
>> 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/e3795845-2934-4dce-b95f-a1d76fc9d6f4%40googlegroups.com
>> <https://groups.google.com/d/msgid/mojolicious/e3795845-2934-4dce-b95f-a1d76fc9d6f4%40googlegroups.com?utm_medium=email_source=footer>
>> .
>>
>

-- 
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/CABMkAVU0s%3DRfr9N7a4iQb0W%3Dfz5no6A%2B0Z5VNUt5gNF0%2BZ6Eew%40mail.gmail.com.


Re: [Mojolicious] Re: mojo generate role

2019-10-23 Thread Dan Book
There are many such global commands released to CPAN for example:
https://metacpan.org/search?q=Mojolicious%3A%3ACommand%3A%3A

-Dan

On Wed, Oct 23, 2019 at 6:25 PM Dan Book  wrote:

> You would install it under Mojolicious::Command::generate, as described at
> https://metacpan.org/pod/Mojolicious::Guides::Cookbook#Adding-commands-to-Mojolicious.
> Easiest if you have a local::lib and simply put it under
> ~/perl5/lib/perl5/Mojolicious/Command/...
>
> -Dan
>
> On Wed, Oct 23, 2019 at 6:16 PM Roger Crew  wrote:
>
>> what's the right way to get something like this
>> (i.e., new mojo generate commands, or variations/additional-options on
>> existing ones)
>> added to my 'mojo' command search space.
>>
>> I can't do it as a plugin, since plugin stuff doesn't becomes available
>> until you actually *add* the plugin to the application you're currently
>> working on (assuming it even *is *an application that you're working on,
>> as opposed to a plugin, or a role, or something else), and the mojo
>> generate commands are all for *creating* source-trees from scratch.
>>
>> About the only thing I can come up with is playing games with @INC in
>> order to swap in my own version of Mojo::HelloWorld to add stuff to its
>> ->commands,
>>
>> ... which all looks to be at least medium evil.
>>
>> but I also hate to ask for Yet Another Environment Variable (but maybe
>> that's the RIght Thing here?)
>>
>>
>> On Tuesday, October 1, 2019 at 6:23:53 AM UTC-7, Roger Crew wrote:
>>>
>>> so, on the theory that if I'm doing something at least twice there
>>> should be a script for it,
>>> I wrote a "mojo generate role", role.pm,
>>>
>>> that is mostly a ripoff of "mojo generate plugin" but with some better
>>> defaults
>>> i.e.,
>>>
>>> mojo generate role BaseClass RoleName
>>>
>>> creates a rudimentary development directory for the
>>> BaseClass::Role::RoleName role
>>> with a single testcase template (...that will actually work straight out
>>> of the box if you chose
>>> a baseclass that doesn't require arguments to build...).
>>>
>>> I can do a pull request if there's interest in this and you want actual
>>> code to look at.
>>>
>> --
>> 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/e3795845-2934-4dce-b95f-a1d76fc9d6f4%40googlegroups.com
>> <https://groups.google.com/d/msgid/mojolicious/e3795845-2934-4dce-b95f-a1d76fc9d6f4%40googlegroups.com?utm_medium=email_source=footer>
>> .
>>
>

-- 
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/CABMkAVUix3H%2BSs9s7UaQsSo7kSKwHS%2BonEphPhJmpjfPLsq6GQ%40mail.gmail.com.


Re: [Mojolicious] Re: mojo generate role

2019-10-23 Thread Dan Book
You would install it under Mojolicious::Command::generate, as described at
https://metacpan.org/pod/Mojolicious::Guides::Cookbook#Adding-commands-to-Mojolicious.
Easiest if you have a local::lib and simply put it under
~/perl5/lib/perl5/Mojolicious/Command/...

-Dan

On Wed, Oct 23, 2019 at 6:16 PM Roger Crew  wrote:

> what's the right way to get something like this
> (i.e., new mojo generate commands, or variations/additional-options on
> existing ones)
> added to my 'mojo' command search space.
>
> I can't do it as a plugin, since plugin stuff doesn't becomes available
> until you actually *add* the plugin to the application you're currently
> working on (assuming it even *is *an application that you're working on,
> as opposed to a plugin, or a role, or something else), and the mojo
> generate commands are all for *creating* source-trees from scratch.
>
> About the only thing I can come up with is playing games with @INC in
> order to swap in my own version of Mojo::HelloWorld to add stuff to its
> ->commands,
>
> ... which all looks to be at least medium evil.
>
> but I also hate to ask for Yet Another Environment Variable (but maybe
> that's the RIght Thing here?)
>
>
> On Tuesday, October 1, 2019 at 6:23:53 AM UTC-7, Roger Crew wrote:
>>
>> so, on the theory that if I'm doing something at least twice there should
>> be a script for it,
>> I wrote a "mojo generate role", role.pm,
>>
>> that is mostly a ripoff of "mojo generate plugin" but with some better
>> defaults
>> i.e.,
>>
>> mojo generate role BaseClass RoleName
>>
>> creates a rudimentary development directory for the
>> BaseClass::Role::RoleName role
>> with a single testcase template (...that will actually work straight out
>> of the box if you chose
>> a baseclass that doesn't require arguments to build...).
>>
>> I can do a pull request if there's interest in this and you want actual
>> code to look at.
>>
> --
> 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/e3795845-2934-4dce-b95f-a1d76fc9d6f4%40googlegroups.com
> 
> .
>

-- 
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/CABMkAVVnGpdR_7U07hR_NV3KMA1R3A-Pg-eBjYuS117U9QfUsQ%40mail.gmail.com.


Re: [Mojolicious] Rendering templates question

2019-10-04 Thread Dan Book
Mojolicious::Plugin::EPRenderer passes the stash as args to Mojo::Template,
which has the vars option enabled and thus creates variables based on the
passed hash.

-Dan

On Fri, Oct 4, 2019 at 1:33 PM Stefan Adams  wrote:

> In Mojolicious::Guides::Render#Embedded-Perl
> ,
> it says:
>
> At the beginning of the template, stash values that don't have invalid
> characters in their name get automatically initialized as normal variables,
> and the controller object as both $self and $c.
>
>
> How are stash values initialized as normal variables?  That is, what code
> is responsible for making this happen?
>
> --
> 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/CACyQ%2BFSdKdJ15sPUTv19N3U7wc81O%3D7hv4i-kk%2BJ%3D_9Q%2BUd7Cw%40mail.gmail.com
> 
> .
>

-- 
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/CABMkAVWt%3DQhwzi-iDc7dQxxVf0whvWnG8_7bZpVEJC8om%3DSFCQ%40mail.gmail.com.


Re: [Mojolicious] iterated promises (Mojo::Promise::Role::Repeat)

2019-10-01 Thread Dan Book
You might look at the existing art of
https://metacpan.org/pod/Future::Utils#REPEATING-A-BLOCK-OF-CODE which can
be used with Mojo::Promise via futurify/promisify, and seems a lot clearer
to me.

-Dan

On Tue, Oct 1, 2019 at 9:04 AM Roger Crew  wrote:

> something I have found vaguely useful that I just uploaded to CPAN for
> people to play with
> Mojo::Promise::Role::Repeat,
>
> adds a *repeat()* method to the promise class/objects.
>
> The essential idea is that
>
> $promise->repeat(sub{...})
>
>
> is equivalent to
>
> $promise->then(sub{...})->then(sub{...})->then(sub{...})->then(sub{...}) #
>  forever
>
>
> except that repeat() also returns a "final" promise, which is
>
>- rejected, if any iteration dies with a value or returns a promise
>that gets rejected
>- resolved with @values, if any iteration calls $_->(@values)
>
> and if any run of the handler sub{...} returns normally or with a promise
> that gets resolved, those values get fed to the next run,
>
> $_ being bound, at the start of each run, to an escape function that
> doesn't return -- the moral equivalent of a break statement -- *but *you
> can also use this function to break out of nested loops/handlers as well
> (though you'll need to stash it in a lexical if you're going to do that).
>
> The pattern that seems to be coming up a lot for me is
>
> $ua->get_p($first_url)->repeat(sub {
>  # ... parse page ...
>  $_->() if (victory);
>  # ...
>  $ua->get_p($next_url);
> })
>
>
> (I may eventually want to petition for some form of this to be added to
> Mojo::Promise, but one thing at a time...)
>
> --
> 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/8ab45fa4-2b24-417a-8f57-4b99cfe82a4b%40googlegroups.com
> 
> .
>

-- 
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/CABMkAVV3aB-JxtUPzB5-G3RrG81C9D33j%2B5_PdV14fxCBkaV-w%40mail.gmail.com.


Re: [Mojolicious] Reverse Proxy

2019-09-10 Thread Dan Book
Most commonly, different nginx servers (the nginx equivalent of Apache
virtualhosts) will listen on different hostnames, and then proxy to
different backend applications.

-Dan

On Tue, Sep 10, 2019 at 2:17 AM Stefan Adams  wrote:

> From the Cookbook#Reverse Proxy
> 
> :
>
> *[A reverse proxy] can provide a lot of benefits, like terminating SSL
> connections from the outside, limiting the number of concurrent open
> sockets towards the Mojolicious application (or even using Unix sockets),
> balancing load across multiple instances, or supporting several
> applications through the same IP/port.*
>
>
> What steps are necessary to support several applications through the same
> IP/port?
>
> I'm picturing having two separate Mojolicious applications running in two
> separate system processes, each with their own Perl binary even.  What is
> necessary to reverse proxy a connection to these two separate apps
> listening on the same IP/port?  How does the reverse proxy (nginx) know
> which process should get the request proxied to it?
>
> Or am I misunderstanding what is stated in bold above?
>
> --
> 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/CACyQ%2BFSkT_YXpnUbakT%3DO%2Bi1y99vVxpg8rVo%3D8V33LUtLhNfPQ%40mail.gmail.com
> 
> .
>

-- 
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/CABMkAVUec9he1116T6Mu%3Dd1ZdAR7Cj_UdaFTxSD%2BrC8wm7UvmQ%40mail.gmail.com.


Re: [Mojolicious] how to run my_app with hypnotoad?

2019-08-26 Thread Dan Book
It is simply "hypnotoad script/my_app". Not sure what you mean by passing
dir scheme.

-Dan

On Mon, Aug 26, 2019 at 2:29 PM Caveman Pl  wrote:

> Hi,
>
> I'm runing my_app with command
>
> morbo -w ./lib -w ./public -w templates  script/my_app -l
> http://192.168.10.130:1773
>
>
> my_app file is
>
> #!/usr/bin/env perl
> use strict;
> use warnings;
> use FindBin;
> BEGIN { unshift @INC, "$FindBin::Bin/../lib" }
> use Mojolicious::Commands;
> use Mojolicious::Lite;
> # Start command line interface for application
> Mojolicious::Commands->start_app('MyApp');
>
>
> whole site works great with morbo but now I need move it from development
> to production (many people will use it).
>
> site directories scheme is
>
> /mojolicious/tmp/my_app
> /mojolicious/tmp/my_app/my_app.conf
> /mojolicious/tmp/my_app/lib
> /mojolicious/tmp/my_app/lib/MyApp
> /mojolicious/tmp/my_app/lib/MyApp.pm
> /mojolicious/tmp/my_app/script
> /mojolicious/tmp/my_app/script/my_app
> /mojolicious/tmp/my_app/templates
>
>
> When I look at my_app and dir scheme I understand how it works.
> I dont know how to pass dir scheme to hypnotoad.
>
> Yes, I have read doc...
>
> Thank you for help,
>
> tj
>
> --
> 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/0c681653-af92-45ae-b0c6-c271268145e3%40googlegroups.com
> 
> .
>

-- 
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/CABMkAVWC0kbnkHYtxwZ%3Dn9hs%3DOtdJQaF0t%2BhVeK_QXmuGQA7Zg%40mail.gmail.com.


Re: [Mojolicious] PostgreSQL connection problem

2019-08-22 Thread Dan Book
I recommend a connection manager for all DBI usage, and for Mojolicious a
great one is Mojo::Pg. A DBI object cannot handle disconnections or
reconnecting on fork, but by storing only a Mojo::Pg object, and getting a
->db from it only when you need to run queries, that ->db call can
reconnect if needed.

-Dan

On Thu, Aug 22, 2019 at 10:59 AM Mark Jones  wrote:

> Hi,
>
> I have an issue with a Mojolicious app that seems to loose connection to a
> Postgres database whenever the postgres service is restarted. Is this
> normal behavior, shouldn't the Mojo app automatically reconnect without
> having to restart hypnotoad?
>
> The error that gets logged is:
> [error] no connection to the server at /var/www/mojoApp...
>
> Postgres db connection:
>
> app->attr(db => sub {
> my $self = shift;
> my $dbh = ('dbname');
> return $dbh;
> });
>
> connect sub:
>
> my ($dbname) = shift;
>
> if($dbname && $dbname ne '')
> {
> my $host='xx.xx.xx.xx';
> my $dsn=qq(dbi:Pg:dbname=$dbname;host=$host);
> my $dbusername = xx;
> my $password = xx;
> my $dbh = DBI->connect($dsn,$dbusername,$password)||
> die("Connect error: $DBI::errstr");
> return $dbh;
> }
>
> Is there something else that I need to add?
>
> Thanks
>
> --
> 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/742b60f5-af10-44db-b303-e1631272ca15%40googlegroups.com
> 
> .
>

-- 
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/CABMkAVX3QBP-o89NacUXYMRaCYCyd%2BRnzVYGDKf7_f_Sb3rtmw%40mail.gmail.com.


Re: [Mojolicious] 'Under' controller method called multiple times

2019-06-14 Thread Dan Book
To just "establish a URL path", under is not needed, you can just use any
which does not create a discrete action.

-Dan

On Fri, Jun 14, 2019 at 11:32 AM Dan Book  wrote:

> The explanation is that each 'under' route is a discrete action from the
> endpoints, and must be defined and return 1 to continue the dispatch chain.
>
> -Dan
>
> On Fri, Jun 14, 2019 at 11:10 AM Stefan Adams  wrote:
>
>> I don't have an explanation for why this seems to be necessary for your
>> situation, but after reading Mojolicious::Guides::Routing#Under
>> <https://mojolicious.org/perldoc/Mojolicious/Guides/Routing#Under>, I
>> found that this should work for you:
>>
>>   # REST interface
>>   my $rest_v1 = $r->under('/rest/v1'* => sub{1}*);
>>   $rest_v1->get('/')->to('example#welcome');
>>
>> On Thu, Jun 13, 2019 at 1:09 AM Justin Hawkins 
>> wrote:
>>
>>> Hello all,
>>>
>>> I think there is a good chance this is a case of “holding it wrong”, so
>>> I will first explain what I’m trying to achieve.
>>>
>>> Standard web app, multiple ways of establishing rights to privileged
>>> routes.
>>>
>>> The first is standard username/password, establishing a session.
>>>
>>> The second is via an API key (supplied with a header).
>>>
>>> I use two separate controller methods, one to check the session, one to
>>> check the header. Each one has the opportunity to set a stash variable
>>> indicating that the user has a valid session (via either cookie session or
>>> API key).
>>>
>>> So I use two “under” routes to call each method. So far so good, things
>>> work ok.
>>>
>>> The problem I have is that I later have another under route, to
>>> establish a new URL path for my REST interface.
>>>
>>> Any requests that go through routes derived from that third “under" have
>>> a strange behaviour - they call the second ‘under’ controller twice!
>>>
>>> This is probably easiest to see with an example:
>>>
>>> package TestUnder;
>>> use Mojo::Base 'Mojolicious';
>>>
>>> # This method will run once at server start
>>> sub startup {
>>>   my $self = shift;
>>>
>>>   # Load configuration from hash returned by config file
>>>   my $config = $self->plugin('Config');
>>>
>>>   # Configure the application
>>>   $self->secrets($config->{secrets});
>>>
>>>   # Router
>>>   my $r = $self->routes;
>>>
>>>   # All requests should go through these two
>>>   $r = $r->under()->to('example#under_one');
>>>   $r = $r->under()->to('example#under_two');
>>>   $r->get('/')->to('example#welcome');
>>>
>>>   # REST interface
>>>   my $rest_v1 = $r->under('/rest/v1');
>>>   $rest_v1->get('/')->to('example#welcome');
>>>
>>> }
>>>
>>> package TestUnder::Controller::Example;
>>>
>>> use Mojo::Base 'Mojolicious::Controller';
>>>
>>> sub under_one {
>>>   my $self = shift;
>>>   $self->app->log->info("under_one called");
>>>   1;
>>> }
>>>
>>> sub under_two {
>>>   my $self = shift;
>>>   $self->app->log->info("under_two called");
>>>   1;
>>> }
>>>
>>> sub welcome {
>>>   my $self = shift;
>>>   $self->render(text => 'hi');
>>> }
>>>
>>> 1;
>>>
>>> Example below - you can easily see that for the “REST” route,
>>> ‘under_two’ is called twice:
>>>
>>>
>>>
>>>
>>> $ script/test_under get / >/dev/null
>>> [2019-06-13 15:28:30.55547] [44306] [debug] GET "/" (9ca39c7c)
>>> [2019-06-13 15:28:30.55627] [44306] [debug] Routing to controller
>>> "TestUnder::Controller::Example" and action "under_one"
>>> [2019-06-13 15:28:30.55637] [44306] [info] under_one called
>>> [2019-06-13 15:28:30.55651] [44306] [debug] Routing to controller
>>> "TestUnder::Controller::Example" and action "under_two"
>>> [2019-06-13 15:28:30.55661] [44306] [info] under_two called
>>> [2019-06-13 15:28:30.55675] [44306] [debug] Routing to controller
>>> "TestUnder::Controller::Example" and action "welcome"
>>> [2019-06-13 15:28:30.55704] [44306] [debug] 200 OK (0.001571s, 636.537/s)
>&

Re: [Mojolicious] 'Under' controller method called multiple times

2019-06-14 Thread Dan Book
The explanation is that each 'under' route is a discrete action from the
endpoints, and must be defined and return 1 to continue the dispatch chain.

-Dan

On Fri, Jun 14, 2019 at 11:10 AM Stefan Adams  wrote:

> I don't have an explanation for why this seems to be necessary for your
> situation, but after reading Mojolicious::Guides::Routing#Under
> , I
> found that this should work for you:
>
>   # REST interface
>   my $rest_v1 = $r->under('/rest/v1'* => sub{1}*);
>   $rest_v1->get('/')->to('example#welcome');
>
> On Thu, Jun 13, 2019 at 1:09 AM Justin Hawkins 
> wrote:
>
>> Hello all,
>>
>> I think there is a good chance this is a case of “holding it wrong”, so I
>> will first explain what I’m trying to achieve.
>>
>> Standard web app, multiple ways of establishing rights to privileged
>> routes.
>>
>> The first is standard username/password, establishing a session.
>>
>> The second is via an API key (supplied with a header).
>>
>> I use two separate controller methods, one to check the session, one to
>> check the header. Each one has the opportunity to set a stash variable
>> indicating that the user has a valid session (via either cookie session or
>> API key).
>>
>> So I use two “under” routes to call each method. So far so good, things
>> work ok.
>>
>> The problem I have is that I later have another under route, to establish
>> a new URL path for my REST interface.
>>
>> Any requests that go through routes derived from that third “under" have
>> a strange behaviour - they call the second ‘under’ controller twice!
>>
>> This is probably easiest to see with an example:
>>
>> package TestUnder;
>> use Mojo::Base 'Mojolicious';
>>
>> # This method will run once at server start
>> sub startup {
>>   my $self = shift;
>>
>>   # Load configuration from hash returned by config file
>>   my $config = $self->plugin('Config');
>>
>>   # Configure the application
>>   $self->secrets($config->{secrets});
>>
>>   # Router
>>   my $r = $self->routes;
>>
>>   # All requests should go through these two
>>   $r = $r->under()->to('example#under_one');
>>   $r = $r->under()->to('example#under_two');
>>   $r->get('/')->to('example#welcome');
>>
>>   # REST interface
>>   my $rest_v1 = $r->under('/rest/v1');
>>   $rest_v1->get('/')->to('example#welcome');
>>
>> }
>>
>> package TestUnder::Controller::Example;
>>
>> use Mojo::Base 'Mojolicious::Controller';
>>
>> sub under_one {
>>   my $self = shift;
>>   $self->app->log->info("under_one called");
>>   1;
>> }
>>
>> sub under_two {
>>   my $self = shift;
>>   $self->app->log->info("under_two called");
>>   1;
>> }
>>
>> sub welcome {
>>   my $self = shift;
>>   $self->render(text => 'hi');
>> }
>>
>> 1;
>>
>> Example below - you can easily see that for the “REST” route, ‘under_two’
>> is called twice:
>>
>>
>>
>>
>> $ script/test_under get / >/dev/null
>> [2019-06-13 15:28:30.55547] [44306] [debug] GET "/" (9ca39c7c)
>> [2019-06-13 15:28:30.55627] [44306] [debug] Routing to controller
>> "TestUnder::Controller::Example" and action "under_one"
>> [2019-06-13 15:28:30.55637] [44306] [info] under_one called
>> [2019-06-13 15:28:30.55651] [44306] [debug] Routing to controller
>> "TestUnder::Controller::Example" and action "under_two"
>> [2019-06-13 15:28:30.55661] [44306] [info] under_two called
>> [2019-06-13 15:28:30.55675] [44306] [debug] Routing to controller
>> "TestUnder::Controller::Example" and action "welcome"
>> [2019-06-13 15:28:30.55704] [44306] [debug] 200 OK (0.001571s, 636.537/s)
>>
>> $ script/test_under get /rest/v1 >/dev/null
>> [2019-06-13 15:28:34.95883] [44315] [debug] GET "/rest/v1" (6aad1c75)
>> [2019-06-13 15:28:34.95975] [44315] [debug] Routing to controller
>> "TestUnder::Controller::Example" and action "under_one"
>> [2019-06-13 15:28:34.95984] [44315] [info] under_one called
>> [2019-06-13 15:28:34.95997] [44315] [debug] Routing to controller
>> "TestUnder::Controller::Example" and action "under_two"
>> [2019-06-13 15:28:34.96005] [44315] [info] under_two called
>> [2019-06-13 15:28:34.96020] [44315] [debug] Routing to controller
>> "TestUnder::Controller::Example" and action "under_two"
>> [2019-06-13 15:28:34.96031] [44315] [info] under_two called
>> [2019-06-13 15:28:34.96044] [44315] [debug] Routing to controller
>> "TestUnder::Controller::Example" and action "welcome"
>> [2019-06-13 15:28:34.96083] [44315] [debug] 200 OK (0.001985s, 503.778/s)
>>
>> $ mojo version
>> CORE
>>   Perl(v5.26.1, darwin)
>>   Mojolicious (8.17, Supervillain)
>>
>> OPTIONAL
>>   Cpanel::JSON::XS 4.04+  (n/a)
>>   EV 4.0+ (n/a)
>>   IO::Socket::Socks 0.64+ (n/a)
>>   IO::Socket::SSL 2.009+  (2.051)
>>   Net::DNS::Native 0.15+  (n/a)
>>   Role::Tiny 2.01+(2.05)
>>
>> This version is up to date, have fun!
>>
>> Regards,
>>
>> Justin
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Mojolicious" group.
>> To unsubscribe from 

Re: [Mojolicious] How to have debug msg with a full Mojolicious app

2019-06-04 Thread Dan Book
Do you have a log directory? If it is present logs will go there instead of
STDERR.

-Dan

On Tue, Jun 4, 2019 at 6:07 AM François Rappaz  wrote:

> With Mojolicious::Lite, I have no problem in having debug message using
> $c->app->log->debug();
>
> When I start a full Mololicious app with a script, named my_lib.pl,
> ending in
>
>
> Mojolicious::Commands->start_app('MyLib');
>
>
> and that script is run from the windows command (Yes, I'm on Windows) with
>
> morbo my_lib.pl
>
>
> I do not have any message that way, What am I missing ? How can I have
> these ?
> Thanks
> F.
>
> --
> 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 post to this group, send email to mojolicious@googlegroups.com.
> Visit this group at https://groups.google.com/group/mojolicious.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/mojolicious/319fdacc-a66c-4201-8e15-5964c52f2de9%40googlegroups.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 post to this group, send email to mojolicious@googlegroups.com.
Visit this group at https://groups.google.com/group/mojolicious.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/mojolicious/CABMkAVX9rWuMVYT09GZqLEDcgS4jSfjnzWV3xXD7GSjVr%2BwCsQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Mojolicious] Mojolicious::Lite HTTPS / SSL / TLS not working

2019-05-23 Thread Dan Book
You could easily try by installing them to a local::lib with cpanm and
temporarily adding the local::lib to your PERL5LIB. This would at least
help isolate the problem.

$ wget -qO cpanm https://cpanmin.us # or App::cpanminus probably available
from repo
$ perl ./cpanm -l local Net::SSLeay IO::Socket::SSL
$ PERL5LIB=local/lib/perl5 perl app.pl daemon ...

-Dan

On Thu, May 23, 2019 at 2:04 PM Celejar  wrote:

>
>
> On Wednesday, May 22, 2019 at 10:21:56 AM UTC-4, Stefan Adams wrote:
>>
>>
>>
>> On Wed, May 22, 2019 at 7:20 AM Celejar  wrote:
>>
>>> Make sure everything is up to snuff with IO::Socket::SSL

>>>
>>> What would you suggest I do, specifically?
>>>
>>
>> Unfortunately, I'll be of little help here.   Did listening on https for
>> your app ever work on this instance that is currently failing?  The latest
>> version of IO::Socket::SSL is 2.066 -- perhaps update?  I think
>> IO::Socket::SSL depends on Net::SSLeay, perhaps update it to the latest
>> version 1.88?  Of course, it's always a good idea to update Mojolicious to
>> the latest version.  Do those one at a time and test after each update.
>> What about updating your openssl library openssl, libssl1.0.0, and
>> libssl-dev?  I'm on Ubuntu 16.04 with openssl 1.0.2g.
>>
>
> Thanks. I'm not sure these version are available from the Debian repos,
> and installing them by hand will take some doing. [I already tried updating
> one of the perl modules via Debian's dh-make-perl tool, but the resulting
> package wouldn't install. I've never used raw CPAN.]
>
>>
>> Before doing any of that, I'm just curious: openssl, curl, and wget all
>> fail for you...  what about trying the mojo useragent?
>>
>
>
>>
>> $ mojo get -k https://127.0.0.1:3000
>> Your Mojo is working!
>>
>>
> $ mojo get -k https://127.0.0.1:3000
> SSL connect attempt failed
>  at /usr/share/perl5/Mojolicious/Command/get.pm line 77.
>
>
> --
> 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 post to this group, send email to mojolicious@googlegroups.com.
> Visit this group at https://groups.google.com/group/mojolicious.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/mojolicious/cb8237fb-7a77-4ac8-b4ee-add1fb233d33%40googlegroups.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 post to this group, send email to mojolicious@googlegroups.com.
Visit this group at https://groups.google.com/group/mojolicious.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/mojolicious/CABMkAVU7541DHvGi-wfQiJ2LQ3mKm5D0W6xwu8%2BizYhzxx8xUw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Mojolicious] Reverse Proxy Standards

2019-05-19 Thread Dan Book
It can't use the first entry, because each reverse proxy will append to the
header, and so the first one could be anything supplied by the user. This
is also why reverse proxy detection must be opted into to begin with. You
can use https://metacpan.org/pod/Mojolicious::Plugin::ForwardedFor to
specify how many reverse proxy levels you are deploying behind to retrieve
the correct address.

-Dan

On Sun, May 19, 2019 at 3:23 PM Veesh Goldman  wrote:

> I'm currently working on a project using Google's App Engine. I noticed an
> issue with the reverse proxy feature, that mojolicious pulls the last entry
> from the header (the X-Forwarded-For header is a list of the proxies that
> the request traversed). The way google sets it up is that the first entry
> is the actual request ip, not the last entry.
>
> Is this a nonstandard move on Google's half, or on Mojo's?
>
> --
> 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 post to this group, send email to mojolicious@googlegroups.com.
> Visit this group at https://groups.google.com/group/mojolicious.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/mojolicious/CAO-W_8C9BFq3qhEcrwyDOttnqQvFuHTuii52UO7h5BmmLcSPVQ%40mail.gmail.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 post to this group, send email to mojolicious@googlegroups.com.
Visit this group at https://groups.google.com/group/mojolicious.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/mojolicious/CABMkAVW4gcRF5%3D0RboQhn3JcunG7qNqPuzR3oq4jmDFE%3DN4Z8A%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Mojolicious] Sharing memory amongst hypnotoad workers

2019-05-16 Thread Dan Book
Note SQLite with Mojo::SQLite is an option for an external database that
doesn't require setting up any other server, if you won't have heavy load.

-Dan

On Thu, May 16, 2019 at 2:38 AM Илья Рассадин  wrote:

> Hi!
>
> As you said, you can use any type of external database.
>
> If you're looking for something more simple - try Cache::FastMMap.
>
> The only way to do that without external modules (just perl core +
> Mojolicious) I can think of is a file, but you need to use some locking
> mechanism like flock.
>
> If you can use external modules - it's better to do that. If you need
> persistent storage - using external database like Redis is probably the
> most appropriate solution.
> On 16/05/2019 09:24, Veesh Goldman wrote:
>
> What are my options if I need all of my workers to share some bit of
> dynamic data? Let's say there's some counter that needs to be incremented
> every time something happens, but is only relevant while the app is
> running. Do I need to use a DB for that, or Redis or memcached, or is there
> something built in to help with that.
> I'm assuming that the memory isn't shared because the process forks to
> make the workers.
> Thanks
> --
> 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 post to this group, send email to mojolicious@googlegroups.com.
> Visit this group at https://groups.google.com/group/mojolicious.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/mojolicious/CAO-W_8CrrP-DXxPP_TXxP7wf-dQY1e7nezqSgFHe8BTo6_853Q%40mail.gmail.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>
> --
> 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 post to this group, send email to mojolicious@googlegroups.com.
> Visit this group at https://groups.google.com/group/mojolicious.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/mojolicious/ad4f971b-9cc8-1cd6-f101-e0c63fadc672%40gmail.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 post to this group, send email to mojolicious@googlegroups.com.
Visit this group at https://groups.google.com/group/mojolicious.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/mojolicious/CABMkAVXkp47j5tNY88656HKHnR3aRBF2wjLCn2Hz%2BNgqdUAsDg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Mojolicious] How to send a job in the backend and refresh status in web app ?

2019-05-09 Thread Dan Book
Pubsub over a db like Pg or Redis might be useful if you are using one of
those. Otherwise the Mercury websocket broker can also act as a pubsub
daemon.

-Dan

On Thu, May 9, 2019 at 4:17 PM Luc Larochelle  wrote:

> Hi,
>
> I've researched this subject and read a lot, but can't come to a
> conclusion. I need help to get things straight ...
>
> In my web app, I simply manage elements in a DB with API endpoints. So
> far, this is awesome. My setup is Mojolicious + AngularJS + Bootstrap.
>
> The way I see this, my question has 2 approaches :
>
> 1) When I add a new element in the table, I'd like to deploy a job, where
> a backend scripts connects to the element and reports a status to the web
> app.
>
> 2) Some daemon is periodically watching an "inventory" API endpoint and
> when a new element is detected, the backend script connects to the element
> and reports a status to the web app.
>
>
> For instance, it could set a status light for connectivity and
> authentication success on each line of my table.
>
>
> In any ways, I thought websockets + minions would be my friends, but the
> more I read about it, the more I get confused. Are Minions suited for this
> task ?
>
> How should I achieve this ?
>
> --
> 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 post to this group, send email to mojolicious@googlegroups.com.
> Visit this group at https://groups.google.com/group/mojolicious.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/mojolicious/ccfe44d6-38b8-405d-92f6-189f4c377b3a%40googlegroups.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 post to this group, send email to mojolicious@googlegroups.com.
Visit this group at https://groups.google.com/group/mojolicious.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/mojolicious/CABMkAVXFoB%3DTwONPC1F%2BJaf-fnuanYkc9YB%3DCS0Suw8xgOSSug%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Mojolicious] Error handling with Mojo::SQLite

2019-05-09 Thread Dan Book
It is so the eval returns true if it succeeds. If an exception is thrown,
eval always returns undef. Thus by this difference you can determine
without fail whether an exception occurred.

-Dan

On Thu, May 9, 2019 at 9:49 AM Luc Larochelle  wrote:

> Hi Dan,
>
> What does the " 1 " stands for in the line : if (eval { ...; *1* }) { ?
>
> I've never used that kind of notation before. I think it could be some
> sort of default *true ?*
>
>
>
> On Wednesday, 8 May 2019 14:10:51 UTC-4, Dan Book wrote:
>>
>> Testing $@ is not the best way to determine an exception occurred. I'd
>> recommend Syntax::Keyword::Try as it handles all the edge cases for you,
>> but otherwise this gets you most of the way:
>>
>> if (eval { ...; 1 }) {
>>   # success
>> } else {
>>   my $err = $@;
>> }
>>
>> And make sure you log errors and rethrow any exceptions you do not
>> handle. You will want to see the error logging later.
>>
>> -Dan
>>
>> On Wed, May 8, 2019 at 1:18 PM Luc Larochelle  wrote:
>>
>>> This works just as expected. In my case I wanted to catch foreign key
>>> constraints. Now I'm prepared for the critics, I'll post my "del" route,
>>> it's from an Lite application serving a web app. I wonder if I'm doing
>>> things the right way.
>>>
>>> I tried to make it idempotent for GET, POST, PUT & DEL but since I have
>>> to deal with little exceptions in the given routes, they all have their
>>> definitions. For instance, :id is *id in the GET route, since its principal
>>> task is to display the whole table. The helpers though (model ?) are not
>>> dealing with exceptions at all and are used to execute simple tasks to the
>>> db given the params feeded by the routes.
>>>
>>> I'm very opened to discuss all of this, this has to be my most serious
>>> project since I started using Mojolicious and I'm learning frontend coding
>>> on-the-fly ...
>>>
>>> helper insertOne => sub {
>>> my ($c,$table) = @_;
>>> $c->sqlite->db->insert($table, $c->element);
>>> };
>>>
>>>
>>> helper deleteOne => sub {
>>>
>>> my ($c,$table,$param) = @_;
>>> $c->sqlite->db->delete($table, {$tables->{$table} => $param});
>>> };
>>>
>>>
>>>
>>> del '/api/select/:table/:id' => sub {
>>>
>>> my $c = shift;
>>> if ($c->selectOne($c->param('id'))) {
>>> eval { $c->deleteOne($c->param('table'),$c->param('id')) };
>>> unless($@) {
>>> $c->render(status => 200, json => {message => $c->param('id') .
>>> $messages->{'Del'}});
>>> } elsif ($@ =~ /FOREIGN KEY constraint failed/) {
>>> $c->render(status => 400, json => {message => $c->param('id') .
>>> $messages->{'FK'}});
>>> }
>>> } else {
>>> $c->render(status => 404, json => {message => "Not found"});
>>> }
>>>
>>> };
>>>
>>>
>>>
>>> On Wednesday, 20 March 2019 11:58:04 UTC-4, Luc Larochelle wrote:
>>>>
>>>> Thanks ! Maybe I read only the sections and bold titles :)
>>>>
>>>> I'll have a second look.
>>>>
>>>>
>>>> On Monday, 18 March 2019 12:35:48 UTC-4, Dan Book wrote:
>>>>>
>>>>> As mentioned in the documentation: "Any database errors will throw an
>>>>> exception as RaiseError is automatically enabled, so use eval or
>>>>> Try::Tiny <https://metacpan.org/pod/Try::Tiny> to catch them. "
>>>>>
>>>>> This is the standard way to handle errors in Perl.
>>>>> Syntax::Keyword::Try is also a nicer interface if you can use keyword
>>>>> plugins (perl 5.14+).
>>>>>
>>>>> -Dan
>>>>>
>>>>> On Mon, Mar 18, 2019 at 10:00 AM Luc Larochelle 
>>>>> wrote:
>>>>>
>>>>>> Hello Veesh, well to me that looks like "eval" , right ? I meant is
>>>>>> there a way with Mojo::SQLite to check errors ?
>>>>>>
>>>>>> On Saturday, 16 March 2019 15:12:11 UTC-4, Veesh Goldman wrote:
>>>>>>>
>>>>>>> Does Try::Tiny strike your fancy? It'll put the error into $_ in the
>>>>>>> catch block.
>>>>>>>
>>>>>>> Short of that, I'm fairly cert

Re: [Mojolicious] Mojo::SQLite && foreign keys support ?

2019-05-08 Thread Dan Book
A lexical variable is still bound to a scope, even if it's the file scope.
If that scope is run again (such as creating another instance of the same
application) then that will have a separate instance of that lexical
variable. State variables are initialized once and shared between any
access for the rest of that process. It can't know what outer scope you
might have wanted to store it in. It can still be useful but you have to
make sure that's what you want.

-Dan

On Wed, May 8, 2019 at 11:45 PM Veesh Goldman  wrote:

>
>
> On Wed, May 8, 2019, 5:55 PM Dan Book  wrote:
>
>>
>> Alternatively you can use 'state $sqlite = ' inside the helper but this
>> approach breaks the ability to run multiple separate apps in the same
>> process, because it will make one $sqlite per whole process.
>>
>> -Dan
>>
>
>
> Could you expound on this problem? I thought state is just a shortcut to
> closing over a lexical variable.
>
> --
> 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 post to this group, send email to mojolicious@googlegroups.com.
> Visit this group at https://groups.google.com/group/mojolicious.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/mojolicious/CAO-W_8CVM9NnBMXuyvHi_FCT7p8%2B11FxTn6it9%3D%3D2JpUr78nfw%40mail.gmail.com
> <https://groups.google.com/d/msgid/mojolicious/CAO-W_8CVM9NnBMXuyvHi_FCT7p8%2B11FxTn6it9%3D%3D2JpUr78nfw%40mail.gmail.com?utm_medium=email_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 post to this group, send email to mojolicious@googlegroups.com.
Visit this group at https://groups.google.com/group/mojolicious.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/mojolicious/CABMkAVUWJc-rYw4DhThw9YGcp7OdCh3d0djXRoPLpRkq-vESZg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Mojolicious] Error handling with Mojo::SQLite

2019-05-08 Thread Dan Book
Testing $@ is not the best way to determine an exception occurred. I'd
recommend Syntax::Keyword::Try as it handles all the edge cases for you,
but otherwise this gets you most of the way:

if (eval { ...; 1 }) {
  # success
} else {
  my $err = $@;
}

And make sure you log errors and rethrow any exceptions you do not handle.
You will want to see the error logging later.

-Dan

On Wed, May 8, 2019 at 1:18 PM Luc Larochelle  wrote:

> This works just as expected. In my case I wanted to catch foreign key
> constraints. Now I'm prepared for the critics, I'll post my "del" route,
> it's from an Lite application serving a web app. I wonder if I'm doing
> things the right way.
>
> I tried to make it idempotent for GET, POST, PUT & DEL but since I have to
> deal with little exceptions in the given routes, they all have their
> definitions. For instance, :id is *id in the GET route, since its principal
> task is to display the whole table. The helpers though (model ?) are not
> dealing with exceptions at all and are used to execute simple tasks to the
> db given the params feeded by the routes.
>
> I'm very opened to discuss all of this, this has to be my most serious
> project since I started using Mojolicious and I'm learning frontend coding
> on-the-fly ...
>
> helper insertOne => sub {
> my ($c,$table) = @_;
> $c->sqlite->db->insert($table, $c->element);
> };
>
>
> helper deleteOne => sub {
>
> my ($c,$table,$param) = @_;
> $c->sqlite->db->delete($table, {$tables->{$table} => $param});
> };
>
>
>
> del '/api/select/:table/:id' => sub {
>
> my $c = shift;
> if ($c->selectOne($c->param('id'))) {
> eval { $c->deleteOne($c->param('table'),$c->param('id')) };
> unless($@) {
> $c->render(status => 200, json => {message => $c->param('id') .
> $messages->{'Del'}});
> } elsif ($@ =~ /FOREIGN KEY constraint failed/) {
> $c->render(status => 400, json => {message => $c->param('id') .
> $messages->{'FK'}});
> }
> } else {
> $c->render(status => 404, json => {message => "Not found"});
> }
>
> };
>
>
>
> On Wednesday, 20 March 2019 11:58:04 UTC-4, Luc Larochelle wrote:
>>
>> Thanks ! Maybe I read only the sections and bold titles :)
>>
>> I'll have a second look.
>>
>>
>> On Monday, 18 March 2019 12:35:48 UTC-4, Dan Book wrote:
>>>
>>> As mentioned in the documentation: "Any database errors will throw an
>>> exception as RaiseError is automatically enabled, so use eval or
>>> Try::Tiny <https://metacpan.org/pod/Try::Tiny> to catch them. "
>>>
>>> This is the standard way to handle errors in Perl. Syntax::Keyword::Try
>>> is also a nicer interface if you can use keyword plugins (perl 5.14+).
>>>
>>> -Dan
>>>
>>> On Mon, Mar 18, 2019 at 10:00 AM Luc Larochelle 
>>> wrote:
>>>
>>>> Hello Veesh, well to me that looks like "eval" , right ? I meant is
>>>> there a way with Mojo::SQLite to check errors ?
>>>>
>>>> On Saturday, 16 March 2019 15:12:11 UTC-4, Veesh Goldman wrote:
>>>>>
>>>>> Does Try::Tiny strike your fancy? It'll put the error into $_ in the
>>>>> catch block.
>>>>>
>>>>> Short of that, I'm fairly certain it'll crash your thread if it fails.
>>>>>
>>>>> On Fri, Mar 15, 2019, 10:22 PM Luc Larochelle 
>>>>> wrote:
>>>>>
>>>>>> Hello everyone,
>>>>>>
>>>>>> While a 'select' statement can be double checked by the presence of
>>>>>> the returned data, how can I confirm that statements such as 'insert' ,
>>>>>> 'update' or 'delete' are successful ?
>>>>>>
>>>>>> For instance, using SQL::Abstract and some helpers
>>>>>>
>>>>>> helper insertOne => sub {
>>>>>> my ($c,$table) = @_;
>>>>>> $c->sqlite->db->insert($table, $c->element);
>>>>>> };
>>>>>>
>>>>>>
>>>>>>
>>>>>> I've seen in the documentation that one could *eval* and look into
>>>>>> $@ , but is there a more "inline" way to do this ?
>>>>>>
>>>>>> Cheers !
>>>>>>
>>>>>> Luc
>>>>>>
>>>>>> --
>>>>>> You received this message because you are subscribed to the Google
>>>>

Re: [Mojolicious] Mojo::SQLite && foreign keys support ?

2019-05-08 Thread Dan Book
This is the correct way to set the pragma for each connection. However your
helper is not set up right. You are creating a new Mojo::SQLite object each
time it is called and so the on-connection handler is no longer applied.
You need to declare 'my $sqlite;' outside and only set it in the helper if
it's not defined yet.

my $sqlite;
helper sqlite => sub { $sqlite //= Mojo::SQLite->new... };

Alternatively you can use 'state $sqlite = ' inside the helper but this
approach breaks the ability to run multiple separate apps in the same
process, because it will make one $sqlite per whole process.

-Dan

On Wed, May 8, 2019 at 10:47 AM Luc Larochelle 
wrote:

> Hello everyone,
>
> I've been struggling with this one for a while, so I decided to post here.
>
> I built a crud web application to manage hosts configuration for a backend
> backup application.
>
> There is a parent table (Devices) , which relates to child tables by name
> (authName , promptName ...). I defined foreign keys constraint where delete
> of a child is restricted (if the child is used in the parent table).
>
> Problem is, foreign keys do not seem to be effective from the web app. If
> I open a connection to the db from the cli and enable PRAGMA foreign_keys =
> ON; before attempting a delete, I received the appropriate response
>
> sqlite> delete from Auths where authName = "myAuth";
> Error: foreign key constraint failed
>
> Even if it's being defined in my schema, it's not working.
>
> So I searched the forums for an answer. One good solution was to have the
> PRAGMA defined in ~/.sqliterc, but this is working only for the user.
>
> Finally someone said it had to be applied at each connection, so I added
> the call " on connection " to send the command every time, still no luck.
>
> Below is the relevant piece of code for discussion, can someone please
> point out what's wrong with my approach ?
>
>
>
>
> helper sqlite => sub {my $sql = Mojo::SQLite->new('sqlite:mynewdb2.db')};
>
>
> app->sqlite->on(connection => sub {
> my ($sql, $dbh) = @_;
> $dbh->do('PRAGMA foreign_keys = ON');
> });
>
>
>
> app->sqlite->auto_migrate(1)->migrations->name('ConfigMgt')->from_string(< -- 1 up
> PRAGMA foreign_keys = ON;
>
> create  table  if not exists  Devices
> (
>   hostname  text  ,
>   ipaddress  text  ,
>   groupName  text  ,
>   authName  text  ,
>   connectionName  text  ,
>   promptName  text  ,
>   ignoreStatus  int  default 0,
>   dateAdd  datetime  ,
>   dateMod  datetime  ,
>   primary key (hostname, ipaddress),
>   constraint deviceAuth foreign key (authName)references Auths(authName)
> on delete restrict  on update no action ,
>   constraint deviceScript foreign key (groupName)references
> Scripts(scriptName) on delete restrict  on update no action ,
>   constraint devicePrompt foreign key (promptName)references
> Prompts(promptName) on delete restrict  on update no action ,
>   constraint deviceConnection foreign key (connectionName)references
> Connections(connectionName) on delete restrict  on update no action
> );
>
>
>
>
> --
> 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 post to this group, send email to mojolicious@googlegroups.com.
> Visit this group at https://groups.google.com/group/mojolicious.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/mojolicious/f8d536f2-4ea7-4447-9b8e-04cc639bb287%40googlegroups.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 post to this group, send email to mojolicious@googlegroups.com.
Visit this group at https://groups.google.com/group/mojolicious.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/mojolicious/CABMkAVX2g1rX5vf9-QCrs-X0GH5h%3D-GNFHrJ1BpGp59KQsHnVg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Mojolicious] Using Mojolicious::Lite Syntax in Modules to Add Routes

2019-04-29 Thread Dan Book
Another option is to make separate self contained lite apps and mount/embed
them together. See
https://metacpan.org/pod/Mojolicious::Guides::Routing#Mount-applications and
the below embedding section.

-Dan

On Mon, Apr 29, 2019 at 6:16 PM Dan Book  wrote:

> No, the Lite DSL can only be imported into one "app" script for the "app".
> However, you could call a function and pass it `app` or `app->routes` to
> add routes to like a full app would.
>
> -Dan
>
> On Mon, Apr 29, 2019 at 2:15 PM Viktor Nacht 
> wrote:
>
>> I have a fairly simple Mojo app where I just want to spin off the admin
>> routes into a module but still use the Mojolicious::Lite syntax. I
>> understand I could "grow" the app, but that would add a lot of extra files
>> where I really just need to add one file.
>>
>> Is something like this possible? I tried the "obvious" approach but no
>> luck.
>>
>> use Mojolicious::Lite;
>> use MyApp::Admin;
>>
>> get '/public'
>>
>> app->start;
>>
>> package MyApp::Admin;
>>
>> use Mojolicious::Lite;
>>
>> get '/admin';
>>
>> The route /admin isn't added even though the module is found and
>> processed (using FindBin). Any thoughts?
>>
>> Thank you!
>>
>> V
>>
>> --
>> 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 post to this group, send email to mojolicious@googlegroups.com.
>> Visit this group at https://groups.google.com/group/mojolicious.
>> For more options, visit https://groups.google.com/d/optout.
>>
>

-- 
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 post to this group, send email to mojolicious@googlegroups.com.
Visit this group at https://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.


Re: [Mojolicious] Using Mojolicious::Lite Syntax in Modules to Add Routes

2019-04-29 Thread Dan Book
No, the Lite DSL can only be imported into one "app" script for the "app".
However, you could call a function and pass it `app` or `app->routes` to
add routes to like a full app would.

-Dan

On Mon, Apr 29, 2019 at 2:15 PM Viktor Nacht  wrote:

> I have a fairly simple Mojo app where I just want to spin off the admin
> routes into a module but still use the Mojolicious::Lite syntax. I
> understand I could "grow" the app, but that would add a lot of extra files
> where I really just need to add one file.
>
> Is something like this possible? I tried the "obvious" approach but no
> luck.
>
> use Mojolicious::Lite;
> use MyApp::Admin;
>
> get '/public'
>
> app->start;
>
> package MyApp::Admin;
>
> use Mojolicious::Lite;
>
> get '/admin';
>
> The route /admin isn't added even though the module is found and processed
> (using FindBin). Any thoughts?
>
> Thank you!
>
> V
>
> --
> 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 post to this group, send email to mojolicious@googlegroups.com.
> Visit this group at https://groups.google.com/group/mojolicious.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 post to this group, send email to mojolicious@googlegroups.com.
Visit this group at https://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.


Re: [Mojolicious] struggling with OAuth(2) from google

2019-04-15 Thread Dan Book
This looks like a bug in the module. The is_success method returns a
boolean value, not the result (which is returned by $tx->result).

-Dan

On Mon, Apr 15, 2019 at 8:48 PM  wrote:

>
> dear M experts.  I am again struggling with the OAuth module.  this is
> perhaps because I installed a new ubuntu 18.04.2 machine, and then updated
> Mojolicious to the current version.
>
> first, for anyone else struggling, Mojolicious::Plugin::Web::Auth depends
> on Net::SSLeay, which fails installing.  I believe I fixed this by
> installing `apt install libssl-dev libz-dev`.  I know this is not M's
> fault, but I would suggest that the Auth author stop the install with a
> good instructive error message when these two libraries are not detected.
> grrr
>
>
> second, my M code is still the same as before, but now it is dying with a
> non-informative error message at the point where I had hoped to get my
> Google authentication callback:
>
> *Can't locate object method "headers" via package "1" (perhaps you forgot
> to load "1"?) at
> /usr/local/share/perl/5.26.1/Mojolicious/Plugin/Web/Auth/OAuth2.pm line
> 122.*
>
> I believe the callback I am getting from google is:
>
> *http://auth.syllabus.space/auth/google/callback?state=hashcode=hashcode=email+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.email+openid=0=g.ucla.edu_state=hashcodes=none
> *
>
> I am guessing that google encodes the email address in one of the hash
> codes (which I have blanked here).
>
> my relevant (I think) code excerpt that should be called is
>
> package SylSpace::Controller::AuthAuthenticator;
> use Mojolicious::Lite;
>
> sub google {
>   my ( $self, $access_token, $userinfo ) = @_;
>   my $name = $userinfo->{displayName} || $userinfo->{name};
>   my $email= $userinfo->{email};
>
>   (defined($email)) or die "no good email.";
>
>   return logandreturn( $self, $email, $name, 'google' );
> }
>
> looking at the code, the error comes from
>
> (my $res = $tx->result->is_success ) or do {
> return $callback->{on_error}->( $tx->res->body );
> };
>
> my $dat = $self->_response_to_hash($res);
>
> ...
>
> my $exts = $types->detect( $res->headers->content_type );
>
> could someone please help me?  what could have gone wrong here?
>
>
> --
> 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 post to this group, send email to mojolicious@googlegroups.com.
> Visit this group at https://groups.google.com/group/mojolicious.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 post to this group, send email to mojolicious@googlegroups.com.
Visit this group at https://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.


Re: [Mojolicious] WebSocket Ping Frames

2019-03-18 Thread Dan Book
Perhaps you may want the websocket to time out when idle. I believe this
feature has been discussed in the past but I can't find an issue about it.

-Dan

On Mon, Mar 18, 2019 at 5:15 PM Veesh Goldman  wrote:

> Why doesn't Mojo::UserAgent automatically send pings when connected to a
> websocket? Under what circumstances would I not want to ping to show the
> connection is alive?
>
> --
> 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 post to this group, send email to mojolicious@googlegroups.com.
> Visit this group at https://groups.google.com/group/mojolicious.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 post to this group, send email to mojolicious@googlegroups.com.
Visit this group at https://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.


Re: [Mojolicious] Error handling with Mojo::SQLite

2019-03-18 Thread Dan Book
Also note that *not* catching the error and allowing it to render an
exception page and log the error message is often exactly what you want.

-Dan

On Mon, Mar 18, 2019 at 12:35 PM Dan Book  wrote:

> As mentioned in the documentation: "Any database errors will throw an
> exception as RaiseError is automatically enabled, so use eval or Try::Tiny
> <https://metacpan.org/pod/Try::Tiny> to catch them. "
>
> This is the standard way to handle errors in Perl. Syntax::Keyword::Try is
> also a nicer interface if you can use keyword plugins (perl 5.14+).
>
> -Dan
>
> On Mon, Mar 18, 2019 at 10:00 AM Luc Larochelle 
> wrote:
>
>> Hello Veesh, well to me that looks like "eval" , right ? I meant is there
>> a way with Mojo::SQLite to check errors ?
>>
>> On Saturday, 16 March 2019 15:12:11 UTC-4, Veesh Goldman wrote:
>>>
>>> Does Try::Tiny strike your fancy? It'll put the error into $_ in the
>>> catch block.
>>>
>>> Short of that, I'm fairly certain it'll crash your thread if it fails.
>>>
>>> On Fri, Mar 15, 2019, 10:22 PM Luc Larochelle 
>>> wrote:
>>>
>>>> Hello everyone,
>>>>
>>>> While a 'select' statement can be double checked by the presence of the
>>>> returned data, how can I confirm that statements such as 'insert' ,
>>>> 'update' or 'delete' are successful ?
>>>>
>>>> For instance, using SQL::Abstract and some helpers
>>>>
>>>> helper insertOne => sub {
>>>> my ($c,$table) = @_;
>>>> $c->sqlite->db->insert($table, $c->element);
>>>> };
>>>>
>>>>
>>>>
>>>> I've seen in the documentation that one could *eval* and look into $@
>>>> , but is there a more "inline" way to do this ?
>>>>
>>>> Cheers !
>>>>
>>>> Luc
>>>>
>>>> --
>>>> 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...@googlegroups.com.
>>>> To post to this group, send email to mojol...@googlegroups.com.
>>>> Visit this group at https://groups.google.com/group/mojolicious.
>>>> For more options, visit https://groups.google.com/d/optout.
>>>>
>>> --
>> 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 post to this group, send email to mojolicious@googlegroups.com.
>> Visit this group at https://groups.google.com/group/mojolicious.
>> For more options, visit https://groups.google.com/d/optout.
>>
>

-- 
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 post to this group, send email to mojolicious@googlegroups.com.
Visit this group at https://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.


Re: [Mojolicious] Error handling with Mojo::SQLite

2019-03-18 Thread Dan Book
As mentioned in the documentation: "Any database errors will throw an
exception as RaiseError is automatically enabled, so use eval or Try::Tiny
 to catch them. "

This is the standard way to handle errors in Perl. Syntax::Keyword::Try is
also a nicer interface if you can use keyword plugins (perl 5.14+).

-Dan

On Mon, Mar 18, 2019 at 10:00 AM Luc Larochelle 
wrote:

> Hello Veesh, well to me that looks like "eval" , right ? I meant is there
> a way with Mojo::SQLite to check errors ?
>
> On Saturday, 16 March 2019 15:12:11 UTC-4, Veesh Goldman wrote:
>>
>> Does Try::Tiny strike your fancy? It'll put the error into $_ in the
>> catch block.
>>
>> Short of that, I'm fairly certain it'll crash your thread if it fails.
>>
>> On Fri, Mar 15, 2019, 10:22 PM Luc Larochelle  wrote:
>>
>>> Hello everyone,
>>>
>>> While a 'select' statement can be double checked by the presence of the
>>> returned data, how can I confirm that statements such as 'insert' ,
>>> 'update' or 'delete' are successful ?
>>>
>>> For instance, using SQL::Abstract and some helpers
>>>
>>> helper insertOne => sub {
>>> my ($c,$table) = @_;
>>> $c->sqlite->db->insert($table, $c->element);
>>> };
>>>
>>>
>>>
>>> I've seen in the documentation that one could *eval* and look into $@ ,
>>> but is there a more "inline" way to do this ?
>>>
>>> Cheers !
>>>
>>> Luc
>>>
>>> --
>>> 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...@googlegroups.com.
>>> To post to this group, send email to mojol...@googlegroups.com.
>>> Visit this group at https://groups.google.com/group/mojolicious.
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>> --
> 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 post to this group, send email to mojolicious@googlegroups.com.
> Visit this group at https://groups.google.com/group/mojolicious.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 post to this group, send email to mojolicious@googlegroups.com.
Visit this group at https://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.


Re: [Mojolicious] MUA::Transactor::add_generator

2019-03-12 Thread Dan Book
That seems like the appropriate mechanism to me. If you want to provide a
convenience method, I would instead provide one that takes the $ua object
and an optional generator name, and calls ->add_generator itself. It would
also be subclassable since it could call a method on $self instead of
__PACKAGE__.
-Dan

On Tue, Mar 12, 2019 at 5:22 PM Stefan Adams  wrote:

> I built a generator for AWS Signature4 requests
> .
> This generator calculates a signed Authorization header for the request.
> Is this a good use of the Transactor generator feature?
>
> As you can see from L13
> 
> of the supplied test, I make my generator available this way:
>
> $ua->transactor->add_generator(Mojo::AWS::Signature4::generator);
>
>
> Is this the best mechanism available to share this generator, or is there
> a recommended standard convention?  When I go to document it for
> publishing, is that what I should have in the synopsis section?  It almost
> feels like there should be a plugin mechanism for Mojo::UserAgent.
>
> Thanks for any advice and comments you have!
>
> Stefan
>
> --
> 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 post to this group, send email to mojolicious@googlegroups.com.
> Visit this group at https://groups.google.com/group/mojolicious.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 post to this group, send email to mojolicious@googlegroups.com.
Visit this group at https://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.


Re: [Mojolicious] Match all routes under path to same action

2019-03-10 Thread Dan Book
Actually your first one does not cover /app/ because the placeholder is not
optional. To make it optional you can give it a default (see
https://metacpan.org/pod/Mojolicious::Guides::Routing#Optional-placeholders)

-Dan

On Sun, Mar 10, 2019 at 2:58 PM Adam Hopkins 
wrote:

> So that makes sense that under routes need to have routes under them to be
> the final destination. I guess I thought that
>
> $session_auth_route->get('/*')->to(controller => 'app', action => 'index'
> );
>
> Would cover both /app/ and /app/*.
>
> I tried what I think you meant:
>
>
> $session_auth_route->get()->to(controller => 'app', action => 'index');
>
>
> And that only seemed to match /app, but nothing after /app/.
>
> On Sunday, March 10, 2019 at 1:42:00 PM UTC-5, Dan Book wrote:
>>
>> Under routes do not match on their own. They must have routes under them
>> to be the final destination of the route. If you don't have any routes
>> under /app, then just make it a regular ->get.
>>
>> -Dan
>>
>> On Sun, Mar 10, 2019 at 2:03 PM Adam Hopkins 
>> wrote:
>>
>>> I have an authenticated part of my app, where I want all paths under
>>> "/app*" to go to the same action. I thought I could do this with only one
>>> route, but I seem to need two:
>>>
>>> my $session_auth_route = $app->routes->under('/app' => sub ($c) {
>>> return 1 if $c->is_session_authenticated;
>>>
>>>
>>> $c->redirect_to('/');
>>> return;
>>> });
>>>
>>>
>>> # without this, /app alone will not match
>>> $session_auth_route->get('/')->to(controller => 'app', action => 'index'
>>> );
>>>
>>>
>>> # I thought this would cover /app and /app/whatever, but it only works
>>> when there is more after /app in the path
>>> $session_auth_route->get('/*')->to(controller => 'app', action =>
>>> 'index');
>>>
>>> Is there a better way to get this working with only one route that will
>>> match everything under /app and including /app?
>>>
>>> --
>>> 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...@googlegroups.com.
>>> To post to this group, send email to mojol...@googlegroups.com.
>>> Visit this group at https://groups.google.com/group/mojolicious.
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>> --
> 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 post to this group, send email to mojolicious@googlegroups.com.
> Visit this group at https://groups.google.com/group/mojolicious.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 post to this group, send email to mojolicious@googlegroups.com.
Visit this group at https://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.


Re: [Mojolicious] Match all routes under path to same action

2019-03-10 Thread Dan Book
Under routes do not match on their own. They must have routes under them to
be the final destination of the route. If you don't have any routes under
/app, then just make it a regular ->get.

-Dan

On Sun, Mar 10, 2019 at 2:03 PM Adam Hopkins 
wrote:

> I have an authenticated part of my app, where I want all paths under
> "/app*" to go to the same action. I thought I could do this with only one
> route, but I seem to need two:
>
> my $session_auth_route = $app->routes->under('/app' => sub ($c) {
> return 1 if $c->is_session_authenticated;
>
>
> $c->redirect_to('/');
> return;
> });
>
>
> # without this, /app alone will not match
> $session_auth_route->get('/')->to(controller => 'app', action => 'index');
>
>
> # I thought this would cover /app and /app/whatever, but it only works
> when there is more after /app in the path
> $session_auth_route->get('/*')->to(controller => 'app', action => 'index'
> );
>
> Is there a better way to get this working with only one route that will
> match everything under /app and including /app?
>
> --
> 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 post to this group, send email to mojolicious@googlegroups.com.
> Visit this group at https://groups.google.com/group/mojolicious.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 post to this group, send email to mojolicious@googlegroups.com.
Visit this group at https://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.


Re: [Mojolicious] Re: Convert XML to Perl data structure with Mojo::DOM

2019-02-24 Thread Dan Book
You could of course implement it with Mojo::DOM, but the thing about
converting XML to Perl data structures is it has to be specific to the XML
you're getting. Which is why you can do it with SOAP. Trying to just
convert arbitrary XML to Perl data structures leads to XML::Simple nonsense
nightmares, because XML can contain text nodes anywhere, and any tag can
have attributes and multiple ordered contents. But with a specific
structure in mind, you can go through it with Mojo::DOM and manually map it
to the data structure you want.

-Dan

On Sun, Feb 24, 2019 at 5:19 PM Stefan Adams  wrote:

> I'm dealing with SOAP data and found that this meets my needs:
>
> $self->ua->post_p(@_)->then(sub {
>   *SOAP::Deserializer->deserialize(shift->result->dom)->result*
> });
>
>
> That generates a complex Perl data structure -- exactly what I want.  I
> reckon there's a way to re-implement this with Mojo?
>
> On Sun, Feb 24, 2019 at 11:47 AM Stefan Adams  wrote:
>
>> Is it possible to recursively convert an XML string into a Perl data
>> structure with Mojo::DOM?
>>
>> Something like:
>>
>> 
>> M1N1
>> M2N2
>> M3N3
>> 
>>
>> Into:
>>
>> {a => {x => [{m => 'M1', n => 'N1'}, {m => 'M2', n => 'N2'}], y => [{m =>
>> 'M3', n => 'N3'}]}
>>
>>
>> --
> 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 post to this group, send email to mojolicious@googlegroups.com.
> Visit this group at https://groups.google.com/group/mojolicious.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 post to this group, send email to mojolicious@googlegroups.com.
Visit this group at https://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.


Re: [Mojolicious] Re: Need help with stashing data and retrieving it in the template

2019-02-07 Thread Dan Book
For error handling in this case, keep in mind that there are multiple kinds
of errors. Transport errors (connection failure, etc) will result in the
promise being rejected, which for `all` will cause the whole promise to be
rejected and the `catch` callback to be called, rendering an exception page
(in my example). If you don't want that to happen, add a `catch` handler to
each `get_p` promise that doesn't die to turn it into a resolved promise
(this example one will just pass the rejection reason along):

my @promises = map { $ua->get_p($_)->catch(sub { @_ }) } @urls;

Then when iterating over the results, you will get the string error instead
of the $tx if the get_p originally failed.

HTTP errors on the other hand you have to check for yourself, they don't
affect the resolution of the promise.

-Dan

On Thu, Feb 7, 2019 at 2:34 PM Ron Bergin  wrote:

> Stefan, Thanks for the link.  I've previously read that post but will need
> to read it again.
>
> Dan, I figured out what was causing that last error.  I forgot to load
> use Mojo::Util 'trim';
>
> The script is now working correctly.  Now I need to work on adding error
> checking/handling for cases where the url is unreachable.
>
> --
> 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 post to this group, send email to mojolicious@googlegroups.com.
> Visit this group at https://groups.google.com/group/mojolicious.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 post to this group, send email to mojolicious@googlegroups.com.
Visit this group at https://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.


Re: [Mojolicious] Re: Need help with stashing data and retrieving it in the template

2019-02-07 Thread Dan Book
Regarding delays, promises actually came later and are now considered the
preferred approach as they are much more composable, error handling is
easier, and they are the same concept used in many other languages.

-Dan

On Thu, Feb 7, 2019 at 2:24 PM Ron Bergin  wrote:

> Dan, thank you for your input.  I haven't looked at promises much but I
> was under the impression (based on some of Joel Berger's examples as well
> as one or two other key mojolicious developers) that delays were supposed
> to be cleaner and more desirable.
>
> I knew about the issue with the for loop initialization.  Using the
> correct loop gave me a 500 error so I temporarily "broke" that while
> troubleshooting the passing of the data via the dumper helper.  I corrected
> that loop and swapped in your code but it is giving a "Premature connection
> close" error.
> $ morbo ./titles_promise.pl
> Server available at http://127.0.0.1:3000
>
> [Thu Feb  7 11:02:35 2019] [debug] GET "/titles" (604f6be1)
> [Thu Feb  7 11:02:35 2019] [debug] Routing to a callback
> [Thu Feb  7 11:02:35 2019] [error] Premature connection close
> [Thu Feb  7 11:02:35 2019] [debug] Template
> "exception.development.html.ep" not found
> [Thu Feb  7 11:02:35 2019] [debug] Template "exception.html.ep" not found
> [Thu Feb  7 11:02:35 2019] [debug] Rendering template "mojo/debug.html.ep"
> [Thu Feb  7 11:02:35 2019] [debug] Rendering template
> "mojo/menubar.html.ep"
> [Thu Feb  7 11:02:35 2019] [debug] Your secret passphrase needs to be
> changed
> [Thu Feb  7 11:02:35 2019] [debug] 500 Internal Server Error (0.028391s,
> 35.222/s)
>
>
> Thinking that it might be due to a scoping issue with $ua, I moved that
> out to have file scope, but then it produced this error:
> Use of inherited AUTOLOAD for non-method Mojo::Server::Sandbox::
> b205866ab9c46b3f8105929c8a269a25::trim() is deprecated. This will be
> fatal in Perl 5.28 at /home/rkb/test/titles_promise.pl line 23.
> [Thu Feb  7 11:19:23 2019] [error] Undefined subroutine ::Server::
> Sandbox::b205866ab9c46b3f8105929c8a269a25::trim called at /usr/local/share
> /perl/5.26.1/Mojo/Promise.pm line 123.
>
>
>
> On Thursday, February 7, 2019 at 9:48:20 AM UTC-8, Ron Bergin wrote:
>>
>> I'm brand new to Mojolicious and working on a lite script that goes to 75
>> urls and retrieves text in an h3 tag. I've worked up a working test script
>> that outputs to console and now I'm working on adjusting it to be a web app
>> but I can't seem to get the correct syntax to store/retrieve the data.
>> What am I doing wrong?
>>
>> #!/usr/bin/perl
>>
>> use Mojolicious::Lite;
>>
>> my @urls  = (
>> 'https://mojolicious.org',
>> 'https://metacpan.org',
>> 'https://perlmonks.org',
>> 'http://www.google.com',
>> );
>>
>> get '/titles' => sub {
>> my $ua= Mojo::UserAgent->new;
>> my $async = Mojo::IOLoop::Delay->new;
>>
>> $async->steps(
>> sub {
>> my $self = shift;
>> $ua->get($_, $self->begin) for @urls;
>> },
>> sub {
>> my ($self, @tx) = @_;
>> my $titles  = [];
>>
>> foreach (@tx) {
>> my $title  = '';
>> my $status = $_->res->is_success ? 'Connected' : $_->
>> error->{message};
>>
>> if ( $_->res->is_success ) {
>> $title = $_->res->dom->at('title')->text;
>> $title =~ s/^\s+|\s+$//g; # couldn't get Mojo::Util
>> trim function to work
>> }
>>
>> push @$titles, {host => $_->req->url->host, status =>
>> $status, title => $title};
>> }
>> $self->stash(titles => $titles);
>> }
>> );
>> } => 'titles';
>>
>> app->start;
>>
>> __DATA__
>>
>> @@ titles.html.ep
>> % layout 'titles';
>>
>> %= dumper stash('titles')
>>
>> 
>> 
>>   Host
>>   Status
>>   Title
>> 
>>
>> 
>> % for my $server ( stash('titles') ) {
>>   
>> <%= $server->{host} %>
>> <%= $server->{status} %>
>> <%= $server->{title} =%>
>>   
>> % }
>> 
>>
>> @@ layouts/titles.html.ep
>> 
>>
>> 
>>
>> 
>>   Titles
>> 
>>
>> 
>> Titles
>> <%= content =%>
>> 
>>
>> 
>>
>>
>> Here's the output:
>>
>>> $ ./titles_web.pl get /titles
>>> [Thu Feb  7 09:45:54 2019] [debug] GET "/titles" (fcf21ce8)
>>> [Thu Feb  7 09:45:54 2019] [debug] Routing to a callback
>>> [Thu Feb  7 09:45:54 2019] [debug] Rendering template "titles.html.ep"
>>> from DATA section
>>> [Thu Feb  7 09:45:54 2019] [debug] Rendering template
>>> "layouts/titles.html.ep" from DATA section
>>> [Thu Feb  7 09:45:54 2019] [debug] 200 OK (0.00267s, 374.532/s)
>>> 
>>>
>>> 
>>>
>>> 
>>>   Titles
>>> 
>>>
>>> 
>>> Titles
>>>
>>> undef
>>>
>>>
>>> 
>>> 
>>>   Host
>>>   Status
>>>   Title
>>> 
>>>
>>> 
>>>   
>>> 
>>> 
>>> 
>>> 
>>> 
>>> 
>>>
>>> 
>>>
>>
>> --
> 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

Re: [Mojolicious] Re: Need help with stashing data and retrieving it in the template

2019-02-07 Thread Dan Book
I used trim(), this needs to be imported from Mojo::Util.

-Dan

On Thu, Feb 7, 2019 at 2:24 PM Ron Bergin  wrote:

> Dan, thank you for your input.  I haven't looked at promises much but I
> was under the impression (based on some of Joel Berger's examples as well
> as one or two other key mojolicious developers) that delays were supposed
> to be cleaner and more desirable.
>
> I knew about the issue with the for loop initialization.  Using the
> correct loop gave me a 500 error so I temporarily "broke" that while
> troubleshooting the passing of the data via the dumper helper.  I corrected
> that loop and swapped in your code but it is giving a "Premature connection
> close" error.
> $ morbo ./titles_promise.pl
> Server available at http://127.0.0.1:3000
>
> [Thu Feb  7 11:02:35 2019] [debug] GET "/titles" (604f6be1)
> [Thu Feb  7 11:02:35 2019] [debug] Routing to a callback
> [Thu Feb  7 11:02:35 2019] [error] Premature connection close
> [Thu Feb  7 11:02:35 2019] [debug] Template
> "exception.development.html.ep" not found
> [Thu Feb  7 11:02:35 2019] [debug] Template "exception.html.ep" not found
> [Thu Feb  7 11:02:35 2019] [debug] Rendering template "mojo/debug.html.ep"
> [Thu Feb  7 11:02:35 2019] [debug] Rendering template
> "mojo/menubar.html.ep"
> [Thu Feb  7 11:02:35 2019] [debug] Your secret passphrase needs to be
> changed
> [Thu Feb  7 11:02:35 2019] [debug] 500 Internal Server Error (0.028391s,
> 35.222/s)
>
>
> Thinking that it might be due to a scoping issue with $ua, I moved that
> out to have file scope, but then it produced this error:
> Use of inherited AUTOLOAD for non-method Mojo::Server::Sandbox::
> b205866ab9c46b3f8105929c8a269a25::trim() is deprecated. This will be
> fatal in Perl 5.28 at /home/rkb/test/titles_promise.pl line 23.
> [Thu Feb  7 11:19:23 2019] [error] Undefined subroutine ::Server::
> Sandbox::b205866ab9c46b3f8105929c8a269a25::trim called at /usr/local/share
> /perl/5.26.1/Mojo/Promise.pm line 123.
>
>
>
> On Thursday, February 7, 2019 at 9:48:20 AM UTC-8, Ron Bergin wrote:
>>
>> I'm brand new to Mojolicious and working on a lite script that goes to 75
>> urls and retrieves text in an h3 tag. I've worked up a working test script
>> that outputs to console and now I'm working on adjusting it to be a web app
>> but I can't seem to get the correct syntax to store/retrieve the data.
>> What am I doing wrong?
>>
>> #!/usr/bin/perl
>>
>> use Mojolicious::Lite;
>>
>> my @urls  = (
>> 'https://mojolicious.org',
>> 'https://metacpan.org',
>> 'https://perlmonks.org',
>> 'http://www.google.com',
>> );
>>
>> get '/titles' => sub {
>> my $ua= Mojo::UserAgent->new;
>> my $async = Mojo::IOLoop::Delay->new;
>>
>> $async->steps(
>> sub {
>> my $self = shift;
>> $ua->get($_, $self->begin) for @urls;
>> },
>> sub {
>> my ($self, @tx) = @_;
>> my $titles  = [];
>>
>> foreach (@tx) {
>> my $title  = '';
>> my $status = $_->res->is_success ? 'Connected' : $_->
>> error->{message};
>>
>> if ( $_->res->is_success ) {
>> $title = $_->res->dom->at('title')->text;
>> $title =~ s/^\s+|\s+$//g; # couldn't get Mojo::Util
>> trim function to work
>> }
>>
>> push @$titles, {host => $_->req->url->host, status =>
>> $status, title => $title};
>> }
>> $self->stash(titles => $titles);
>> }
>> );
>> } => 'titles';
>>
>> app->start;
>>
>> __DATA__
>>
>> @@ titles.html.ep
>> % layout 'titles';
>>
>> %= dumper stash('titles')
>>
>> 
>> 
>>   Host
>>   Status
>>   Title
>> 
>>
>> 
>> % for my $server ( stash('titles') ) {
>>   
>> <%= $server->{host} %>
>> <%= $server->{status} %>
>> <%= $server->{title} =%>
>>   
>> % }
>> 
>>
>> @@ layouts/titles.html.ep
>> 
>>
>> 
>>
>> 
>>   Titles
>> 
>>
>> 
>> Titles
>> <%= content =%>
>> 
>>
>> 
>>
>>
>> Here's the output:
>>
>>> $ ./titles_web.pl get /titles
>>> [Thu Feb  7 09:45:54 2019] [debug] GET "/titles" (fcf21ce8)
>>> [Thu Feb  7 09:45:54 2019] [debug] Routing to a callback
>>> [Thu Feb  7 09:45:54 2019] [debug] Rendering template "titles.html.ep"
>>> from DATA section
>>> [Thu Feb  7 09:45:54 2019] [debug] Rendering template
>>> "layouts/titles.html.ep" from DATA section
>>> [Thu Feb  7 09:45:54 2019] [debug] 200 OK (0.00267s, 374.532/s)
>>> 
>>>
>>> 
>>>
>>> 
>>>   Titles
>>> 
>>>
>>> 
>>> Titles
>>>
>>> undef
>>>
>>>
>>> 
>>> 
>>>   Host
>>>   Status
>>>   Title
>>> 
>>>
>>> 
>>>   
>>> 
>>> 
>>> 
>>> 
>>> 
>>> 
>>>
>>> 
>>>
>>
>> --
> 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 post to this group, send email to mojolicious@googlegroups.com.
> Visit this group at 

Re: [Mojolicious] Re: Need help with stashing data and retrieving it in the template

2019-02-07 Thread Dan Book
One more thing: you need to keep a strong reference to the Mojo::UserAgent
object until it completes, so you should define $ua outside of the action
method which will end before the async code occurs.

-Dan

On Thu, Feb 7, 2019 at 1:23 PM Dan Book  wrote:

> Your commented 'for' loop is correct; you need to dereference
> stash('titles') to pass the list of hashrefs to the loop. The other problem
> is that you need to prevent auto-rendering until your async code has
> completed. You can do this by calling `$c->render_later` at the beginning
> of the action (`$c` is the first argument passed to the action, which you
> need to retrieve), and then `$c->render` after you've set the stash value.
> You can even include the stash update in the render call:
> `$c->render(titles => $titles);`
>
> I would additionally recommend to use promises rather than delays as it
> will lead to much more concise code with the promise methods available from
> Mojo::UserAgent. Also, you want to hold a reference to the transaction, and
> add exception handling, as described here:
> https://github.com/mojolicious/mojo/wiki/Upgrading#delay-helper-removed
>
> Here is how it might look as a start:
>
> get '/titles' => sub {
> my $c = shift;
> $c->render_later;
> my $tx = $c->tx;
> my $ua= Mojo::UserAgent->new;
> my @promises = map { $ua->get_p($_) } @urls;
> Mojo::Promise->all(@promises)->then(sub {
> my @results = @_;
> my $titles = [];
> foreach my $result (@results) {
> my $tx = $result->[0];
> my $title = trim($tx->res->dom->at('title')->text);
> push @$titles, {host => $tx->req->url->host, title => $title};
> }
> $c->render(titles => $titles);
> })->catch(sub { $c->reply->exception(pop); undef $tx });
> } => 'titles';
>
> -Dan
>
> On Thu, Feb 7, 2019 at 12:57 PM Ron Bergin  wrote:
>
>> Note: I cross posted this question on perlmonks
>> https://perlmonks.org/?node_id=1229558
>>
>> On Thursday, February 7, 2019 at 9:48:20 AM UTC-8, Ron Bergin wrote:
>>>
>>> I'm brand new to Mojolicious and working on a lite script that goes to
>>> 75 urls and retrieves text in an h3 tag. I've worked up a working test
>>> script that outputs to console and now I'm working on adjusting it to be a
>>> web app but I can't seem to get the correct syntax to store/retrieve the
>>> data.  What am I doing wrong?
>>>
>>> #!/usr/bin/perl
>>>
>>> use Mojolicious::Lite;
>>>
>>> my @urls  = (
>>> 'https://mojolicious.org',
>>> 'https://metacpan.org',
>>> 'https://perlmonks.org',
>>> 'http://www.google.com',
>>> );
>>>
>>> get '/titles' => sub {
>>> my $ua= Mojo::UserAgent->new;
>>> my $async = Mojo::IOLoop::Delay->new;
>>>
>>> $async->steps(
>>> sub {
>>> my $self = shift;
>>> $ua->get($_, $self->begin) for @urls;
>>> },
>>> sub {
>>> my ($self, @tx) = @_;
>>> my $titles  = [];
>>>
>>> foreach (@tx) {
>>> my $title  = '';
>>> my $status = $_->res->is_success ? 'Connected' : $_->
>>> error->{message};
>>>
>>> if ( $_->res->is_success ) {
>>> $title = $_->res->dom->at('title')->text;
>>> $title =~ s/^\s+|\s+$//g; # couldn't get Mojo::Util
>>> trim function to work
>>> }
>>>
>>> push @$titles, {host => $_->req->url->host, status =>
>>> $status, title => $title};
>>> }
>>> $self->stash(titles => $titles);
>>> }
>>> );
>>> } => 'titles';
>>>
>>> app->start;
>>>
>>> __DATA__
>>>
>>> @@ titles.html.ep
>>> % layout 'titles';
>>>
>>> %= dumper stash('titles')
>>>
>>> 
>>> 
>>>   Host
>>>   Status
>>>   Title
>>> 
>>>
>>> 
>>> % for my $server ( stash('titles') ) {
>>>   
>>> <%= $server->{host} %>
>>> <%= $server->{status} %>
>>> <%= $server->{title} =%>
>>>   
>>> % }
>>> 
>>>
>>

Re: [Mojolicious] Re: Need help with stashing data and retrieving it in the template

2019-02-07 Thread Dan Book
Your commented 'for' loop is correct; you need to dereference
stash('titles') to pass the list of hashrefs to the loop. The other problem
is that you need to prevent auto-rendering until your async code has
completed. You can do this by calling `$c->render_later` at the beginning
of the action (`$c` is the first argument passed to the action, which you
need to retrieve), and then `$c->render` after you've set the stash value.
You can even include the stash update in the render call:
`$c->render(titles => $titles);`

I would additionally recommend to use promises rather than delays as it
will lead to much more concise code with the promise methods available from
Mojo::UserAgent. Also, you want to hold a reference to the transaction, and
add exception handling, as described here:
https://github.com/mojolicious/mojo/wiki/Upgrading#delay-helper-removed

Here is how it might look as a start:

get '/titles' => sub {
my $c = shift;
$c->render_later;
my $tx = $c->tx;
my $ua= Mojo::UserAgent->new;
my @promises = map { $ua->get_p($_) } @urls;
Mojo::Promise->all(@promises)->then(sub {
my @results = @_;
my $titles = [];
foreach my $result (@results) {
my $tx = $result->[0];
my $title = trim($tx->res->dom->at('title')->text);
push @$titles, {host => $tx->req->url->host, title => $title};
}
$c->render(titles => $titles);
})->catch(sub { $c->reply->exception(pop); undef $tx });
} => 'titles';

-Dan

On Thu, Feb 7, 2019 at 12:57 PM Ron Bergin  wrote:

> Note: I cross posted this question on perlmonks
> https://perlmonks.org/?node_id=1229558
>
> On Thursday, February 7, 2019 at 9:48:20 AM UTC-8, Ron Bergin wrote:
>>
>> I'm brand new to Mojolicious and working on a lite script that goes to 75
>> urls and retrieves text in an h3 tag. I've worked up a working test script
>> that outputs to console and now I'm working on adjusting it to be a web app
>> but I can't seem to get the correct syntax to store/retrieve the data.
>> What am I doing wrong?
>>
>> #!/usr/bin/perl
>>
>> use Mojolicious::Lite;
>>
>> my @urls  = (
>> 'https://mojolicious.org',
>> 'https://metacpan.org',
>> 'https://perlmonks.org',
>> 'http://www.google.com',
>> );
>>
>> get '/titles' => sub {
>> my $ua= Mojo::UserAgent->new;
>> my $async = Mojo::IOLoop::Delay->new;
>>
>> $async->steps(
>> sub {
>> my $self = shift;
>> $ua->get($_, $self->begin) for @urls;
>> },
>> sub {
>> my ($self, @tx) = @_;
>> my $titles  = [];
>>
>> foreach (@tx) {
>> my $title  = '';
>> my $status = $_->res->is_success ? 'Connected' : $_->
>> error->{message};
>>
>> if ( $_->res->is_success ) {
>> $title = $_->res->dom->at('title')->text;
>> $title =~ s/^\s+|\s+$//g; # couldn't get Mojo::Util
>> trim function to work
>> }
>>
>> push @$titles, {host => $_->req->url->host, status =>
>> $status, title => $title};
>> }
>> $self->stash(titles => $titles);
>> }
>> );
>> } => 'titles';
>>
>> app->start;
>>
>> __DATA__
>>
>> @@ titles.html.ep
>> % layout 'titles';
>>
>> %= dumper stash('titles')
>>
>> 
>> 
>>   Host
>>   Status
>>   Title
>> 
>>
>> 
>> % for my $server ( stash('titles') ) {
>>   
>> <%= $server->{host} %>
>> <%= $server->{status} %>
>> <%= $server->{title} =%>
>>   
>> % }
>> 
>>
>> @@ layouts/titles.html.ep
>> 
>>
>> 
>>
>> 
>>   Titles
>> 
>>
>> 
>> Titles
>> <%= content =%>
>> 
>>
>> 
>>
>>
>> Here's the output:
>>
>>> $ ./titles_web.pl get /titles
>>> [Thu Feb  7 09:45:54 2019] [debug] GET "/titles" (fcf21ce8)
>>> [Thu Feb  7 09:45:54 2019] [debug] Routing to a callback
>>> [Thu Feb  7 09:45:54 2019] [debug] Rendering template "titles.html.ep"
>>> from DATA section
>>> [Thu Feb  7 09:45:54 2019] [debug] Rendering template
>>> "layouts/titles.html.ep" from DATA section
>>> [Thu Feb  7 09:45:54 2019] [debug] 200 OK (0.00267s, 374.532/s)
>>> 
>>>
>>> 
>>>
>>> 
>>>   Titles
>>> 
>>>
>>> 
>>> Titles
>>>
>>> undef
>>>
>>>
>>> 
>>> 
>>>   Host
>>>   Status
>>>   Title
>>> 
>>>
>>> 
>>>   
>>> 
>>> 
>>> 
>>> 
>>> 
>>> 
>>>
>>> 
>>>
>>
>> --
> 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 post to this group, send email to mojolicious@googlegroups.com.
> Visit this group at https://groups.google.com/group/mojolicious.
> For more options, visit https://groups.google.com/d/optout.
>

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

Re: [Mojolicious] render utf8

2019-01-28 Thread Dan Book
The 'data' parameter expects bytes. Bytes cannot include wide characters,
they must either be binary data or already encoded text. If you want to
pass unencoded characters, use the 'text' parameter. See
https://metacpan.org/pod/Mojolicious::Guides::Rendering#Rendering-text

-Dan

On Mon, Jan 28, 2019 at 4:45 AM Boyd Duffee  wrote:

> Tracked down a bug in my code and found the reason for it wasn't
> explicitly covered in the docs.  I don't know if this is obvious or
> expected behaviour, so I'm posting for comment and for the next unfortunate
> soul STFW for this answer.
>
> I created a Data::ICal object as $calendar and added a bunch of events
> which I sent to the browser using
>
> $self->render( data => $calendar->as_string(),
> format => 'ics', status => 200 );
>
> It worked fine until I started including a unicode character in the events
> (  \x{1f4f9} ) and then I started getting this error on STDERR
>
> Mojo::Reactor::Poll: I/O watcher failed: Wide character in subroutine
> entry at /usr/local/share/perl5/Mojo/IOLoop/Stream.pm line 86.
>
> and it refused to send the response.  The failure was hidden by some
> caching code and my lack of understanding of the render lifecycle.  Of
> course, the solution was to properly encode the datastream
>
> use Encode qw/encode_utf8/;
> ...
> $self->render( data => encode_utf8( $calendar->as_string() ),
> format => 'ics', status => 200 );
>
> I guess I was expecting render to simply push out whatever garbage that I
> was passing off as data or maybe to emit a a more informative warning on
> development.log to realize the true impact it had on my app rather than
> puzzling over a HTTP 502 error.
>
> thoughts?
> --
> Boyd Duffee
>   They're good dogs, Brent.  Oh, h*ck. - We Rate Dogs
>
> --
> 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 post to this group, send email to mojolicious@googlegroups.com.
> Visit this group at https://groups.google.com/group/mojolicious.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 post to this group, send email to mojolicious@googlegroups.com.
Visit this group at https://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.


Re: [Mojolicious] Re: Test Existence of Key in Session Hash Without Creating Element

2019-01-10 Thread Dan Book
It is just a hash at that point so none of those things should cause that.
But if you accessed $c->session->{order}{anything} it would create a hash
due to autovivification.

-Dan

On Thu, Jan 10, 2019 at 10:23 PM Viktor Nacht 
wrote:

> *sigh* I meant:
>
> {"expires":1547178562,"order":{}}
>
> --
> 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 post to this group, send email to mojolicious@googlegroups.com.
> Visit this group at https://groups.google.com/group/mojolicious.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 post to this group, send email to mojolicious@googlegroups.com.
Visit this group at https://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.


Re: [Mojolicious] Understanding shift->

2018-11-24 Thread Dan Book
The shift function removes and returns the first argument from @_ (since
there's no array passed for it to shift from) in a sub. It's used this way
because the first argument to these subs is the invocant/object. You can
replace it with $_[0] to get the first argument without removing it. You
should not use $self from outside unless necessary because that may create
a circular reference and leak memory.

-Dan

On Sat, Nov 24, 2018 at 3:40 PM john  wrote:

> This probably a perl question so if I should ask elsewhere let me know...
>
> In looking at the Mojo::Pg blog example and in recent addition of db
> method to Mojo::Pg::PubSub I see use of shift->.
>
>
>  From Mojo::Pg::PubSub documentation:
>
> # Reconnect immediately
> $pubsub->unsubscribe('disconnect')->on(disconnect => sub { shift->db });
>
> Or from the blog example:
>
> $self->helper(pg => sub { state $pg = Mojo::Pg->new(shift->config('pg'))
> });
>
> This doesn't work in my code and I replace "shift" with "$self".   That
> appears to be working.   Also, I can't reconcile using shift in this way
> and what the perl documentation says about it but could get over this if
> it worked.
>
> What am I missing here?
>
> Thanks,
>
> John
>
>
> --
> 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 post to this group, send email to mojolicious@googlegroups.com.
> Visit this group at https://groups.google.com/group/mojolicious.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 post to this group, send email to mojolicious@googlegroups.com.
Visit this group at https://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.


Re: [Mojolicious] What about an after_server_start hook?

2018-11-23 Thread Dan Book
You can set up code to be run whenever the ioloop is started, which happens
in each worker process when it starts in a prefork server, by adding a
next_tick callback as indicated here:
https://metacpan.org/pod/Mojolicious::Guides::Cookbook#Pre-forking

-Dan

On Fri, Nov 23, 2018 at 6:24 PM Stefan Adams  wrote:

> Sometimes it would be nice to have an event / hook for after the server
> has started.  Specifically, I'd want to kick off an automated process with
> Mojo::IOLoop->timer|recurring but only after the web server has started.
>
> Is this possible?  And if not, is it a Pull Request that would be
> considered?
>
> --
> 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 post to this group, send email to mojolicious@googlegroups.com.
> Visit this group at https://groups.google.com/group/mojolicious.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 post to this group, send email to mojolicious@googlegroups.com.
Visit this group at https://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.


Re: [Mojolicious] LWP::UserAgent::Cached substitute?

2018-11-20 Thread Dan Book
I'm not sure why you say it wouldn't be usable with Mojolicious.
Mojolicious doesn't care what other modules you use. LWP won't be capable
of non-blocking queries like Mojo::UserAgent will of course, but that's
usually not important for the command line. If you want to do it with
Mojo::UserAgent try https://metacpan.org/pod/Mojo::UserAgent::Role::Cache.

-Dan

On Tue, Nov 20, 2018 at 8:44 PM  wrote:

> Hi folks,
>
> First time poster.
>
> I have some command line apps that use LWP with LWP::UserAgent::Cached
> for the local file-based cache to get() and later parse pages.  I need to
> use this local page cache so that I don't hit the web server repeatedly for
> unchanged pages.  I was hoping to use Mojolicious, but prefer not to try
> to re-implement this caching.
>
> It doesn't appear that LWP::UserAgent::Cached would be usable with
> Mojolicious, and don't see anything readily available as an alternative.
>
> Any advice?
>
> --
> 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 post to this group, send email to mojolicious@googlegroups.com.
> Visit this group at https://groups.google.com/group/mojolicious.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 post to this group, send email to mojolicious@googlegroups.com.
Visit this group at https://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.


Re: [Mojolicious] Apache Config for Mojo CGI setup - opinions?

2018-11-19 Thread Dan Book
Even simpler, I think, is to alias everything to your one script, so you
don't have to worry about what else might be in that directory.

ScriptAlias "/cgi-bin/" "/opt/mysite/cgi-bin/my_app.pl"

https://httpd.apache.org/docs/2.4/mod/mod_alias.html#scriptalias talks
about some strategies for this.

-Dan

On Mon, Nov 19, 2018 at 11:22 PM Alexander Karelas 
wrote:

> I have made some webapps that I use internally. I use them so rarely (just
> a couple of page views per week each) that I thought it wasn't worth having
> a hypnotoad running for each and waste resources (RAM mainly), especially
> since the number of these webapps might increase a lot in the future, and I
> don't care about response time (2 seconds is fine) so I thought I'd set
> them up as CGI sites.
>
> With some experimentation, I ended up with this Apache conf file the
> VirtualServer (for Apache v2.4). It routes arbitrary URLs to the right
> route handler.
>
> What do you think of it? Is it secure (suppose an evil user has access to
> it)? Can it be improved? Can it be simplified, maybe? Is this useful
> material for the mojo Wiki / POD?
>
> I'm interested in your opinions, because my experience with Apache is not
> that big.
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
> *  DocumentRoot /opt/mysite/html   ScriptAlias /cgi-bin/
> /opt/mysite/cgi-bin/  RewriteEngine
> On   RewriteBase /   RewriteRule (.*) /cgi-bin/my_app.pl/$1
>  [L]   Require all granted  # for
> the case when the user types manually /cgi-bin/local/bin/some-command.pl
>    # i.e. the only CGI script that's allowed to run
> is my_app.pl )">   Require all denied   
>Require all granted   Options
> ExecCGI   SetHandler cgi-script*
>
> --
> 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 post to this group, send email to mojolicious@googlegroups.com.
> Visit this group at https://groups.google.com/group/mojolicious.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 post to this group, send email to mojolicious@googlegroups.com.
Visit this group at https://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.


Re: [Mojolicious] Using 'state' in a helper

2018-11-19 Thread Dan Book
A 'state' variable lasts for the rest of that process, but is only
available to the scope it's declared in. If you want per-connection (or
more precisely per request), I recommend storing it in the stash, like:

helper foo => sub {
  my $c = shift;
  return $c->stash->{'myapp.foo'} //= ...;
};

-Dan

On Mon, Nov 19, 2018 at 8:18 PM Viktor Nacht  wrote:

> Does using state inside a helper last for the duration of the connection,
> or something longer lasting like a process, worker, etc?
>
> I want to create (and return) a current DateTime object and make it
> accessible to multiple helpers and templates during a connection.
>
> I saw this Gist, but I'm not sure it pertains to per-connection:
>
> https://gist.github.com/s1037989/179d53b86e46ae788f62
>
> V
>
> --
> 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 post to this group, send email to mojolicious@googlegroups.com.
> Visit this group at https://groups.google.com/group/mojolicious.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 post to this group, send email to mojolicious@googlegroups.com.
Visit this group at https://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.


Re: [Mojolicious] Mojolicious-8.04

2018-10-28 Thread Dan Book
This error comes from passing extra options to a 'has' attribute
declaration. Previously it took two arguments and ignored the rest. Now it
uses the rest as options and only the 'weak' option is allowed.

-Dan

On Sun, Oct 28, 2018 at 3:45 PM Jan Eskilsson 
wrote:

> Hi All
>
> Today we upgraded our test system from Mojolicious-8 to Mojolicious-8.04
> and we got a bit of a problem.
>
> When we try to start Morbo we get this error
> Odd number of elements in hash assignment at
> /opt/ActivePerl-5.24/site/lib/Mojo/Base.pm line 27.
> Can't load application from file
> "/home/jan/Project/mateorit_microservice/script/mateorit_microservice":
> Unsupported attribute option at
> /home/jan/Project/mateorit_microservice/script/../lib/MateoritMicroservice.pm
> line 6.
> Compilation failed in require at
> /home/jan/Project/mateorit_microservice/script/../lib/MateoritMicroservice.pm
> line 6.
>
> ./lib/MateoritMicroservice.pm line 6.  looks like this,
>  use MateoritMicroservice::Model::Messages;
>
> and in MateoritMicroservice::Model::Messages,
>
> package MateoritMicroservice::Model::Messages;
> use Mojo::Base -base;
>
> and the error seems to originate from this line in Mojo::Base::attr
>   Carp::croak 'Unsupported attribute option' if grep { $_ ne 'weak' } keys
> %kv;
>
> What are we doing wrong here ? adding use Mojo::Base -base, -weak;  does
> not seem to change anything.
>
> everything worked fine using Mojolicious-8 before the upgrade so i guess
> we are missing something here.
>
>
> Thank you in advance.
>
> Best Regards
> Jan
>
>
> --
> Titles mean nothing.  The one with a servant's heart is the leader.
>
> Please consider the environment before you print this email.
>
> All incoming and outgoing emails and any attachments are subjected to a
> virus scanner and are believed to be free of any virus, or any other defect
> which might affect any computer or IT system into which they are received
> and opened. Therefore, it is the responsibility of the recipient to ensure
> that they are virus free and no responsibility is accepted by Jan Eskilsson
>  for any loss or damage arising in any way from receipt or use thereof.
>
> --
> 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 post to this group, send email to mojolicious@googlegroups.com.
> Visit this group at https://groups.google.com/group/mojolicious.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 post to this group, send email to mojolicious@googlegroups.com.
Visit this group at https://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.


Re: [Mojolicious] Stable version to upgrade to

2018-10-24 Thread Dan Book
Yes, there is no reason to run an older release. Yes, there is a danger to
blindly updating, it's recommended to manage all your CPAN dependencies
(not just Mojolicious) with Carton to pin versions if this is a concern.

-Dan

On Tue, Oct 23, 2018 at 11:58 PM Stefan Adams  wrote:

>
>
> On Tue, Oct 23, 2018, 10:44 PM Ganesh Udupa  wrote:
>
>> Thanks for the quick response. I appreciate. The reason I asked is that I
>> saw multiple minor updates in 8.x in a short period. ( I dont know if this
>> is how it was in older major versions )
>>
>
> In my experience this is very normal, and IMO exciting!
>
> Is the last release of 7.x a better option  (thanks for that comment) or
>> should I use 8.04?
>>
>
> IMO and based on the feedback that I see frequently from the core Dev
> team: always run the latest release. However, maybe I've drawn that
> conclusion too far. Perhaps they only expect that with respect to
> submitting bug reports. i.e. if you are running the latest 7.x and want to
> report a bug, first validate that it is still a bug in the latest 8.x
> release, because if it isn't, the bug has already been identified and
> patched.
>
> The last 7.x release is super stable, but it doesn't have and won't get
> some of the awesome new features going into 8.x. But if you want "stable"
> you won't want to use them yet anyway. However, security fixes and bug
> fixes go into the current major release. There is no parallel code base
> maintenance, it's just a continuous singular stream. Therefore, a "solid"
> strategy to stand still at the last prior major version is probably a bad
> idea: bugs won't get patched and worse security holes will forever be
> security holes.
>
> TL;DR I *think* everyone would agree to always use the most current
> release of the current major. Just "follow the rules" and avoid
> experimental.
>
> I would like to get clarification tho on mid-major deprecation removals.
> If you keep your production systems always running the latest release and
> then deprecations occur before your production code has had a chance to
> pass through your org's process, that could be bad news.
>
> On Wed, Oct 24, 2018 at 8:54 AM Stefan Adams  wrote:
>>
>>> Define "stable". The latest release is stable in that it works well and
>>> passes all tests (thousands of them). It's not "stable" in the sense that
>>> the 8.0 release is constantly changing and improving from minor release to
>>> minor release, but that should be expected.
>>>
>>> The core team works very hard to not include any breaking changes within
>>> a major version code base, and their excellent tests help validate that.
>>> Watch the change log. They label new things that aren't "stable" in terms
>>> of API or even longevity as experimental and production deployments are
>>> encouraged to avoid those features. Things that will be removed in a future
>>> major version are labeled as deprecated.
>>>
>>> Hmm... One thing: I think I recall that deprecations can occur within a
>>> time frame (3 months IIRC) as opposed to being limited to at the next major
>>> release. Don't quote me on that. If that were the case, using the last
>>> release of the prior major release might be the most stable? If I made that
>>> up, you should absolutely always be able to use the most recent release of
>>> the current major -- just avoid experimental.
>>>
>>> Core team: my apologies if I added any unacceptable confusion.
>>>
>>> On Tue, Oct 23, 2018, 9:54 PM Ganesh Udupa  wrote:
>>>
 Hi,
 We are currently at 5.28.  Can someone recommend a stable latest
 version to upgrade to?. Is 8.04 stable?

 --
 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 post to this group, send email to mojolicious@googlegroups.com.
 Visit this group at https://groups.google.com/group/mojolicious.
 For more options, visit https://groups.google.com/d/optout.

>>> --
>>> 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 post to this group, send email to mojolicious@googlegroups.com.
>>> Visit this group at https://groups.google.com/group/mojolicious.
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>> --
>> 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 post to this group, send email to mojolicious@googlegroups.com.
>> Visit this group at https://groups.google.com/group/mojolicious.
>> For more options, visit https://groups.google.com/d/optout.
>>
> --
> You received this 

Re: [Mojolicious] Getting File Extension of Mojo::Upload Object

2018-10-12 Thread Dan Book
The original filename is available from $upload->filename, you can parse
the extension from that. Note that this filename can be literally anything
the browser sends, some may even send a full Windows file path for example,
or it's possible a client will not send a filename.

-Dan

On Fri, Oct 12, 2018 at 2:11 PM Viktor Nacht  wrote:

> Just wondering if I'm missing anything for getting the file extension of
> an uploaded file before it's been moved or slurped. Right now my approach
> is to create Mojo::File object about the filename from Mojo::Upload and
> extract it from there. Is there a more direct method I'm unaware of?
>
> Thanks!
>
> V
>
> --
> 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 post to this group, send email to mojolicious@googlegroups.com.
> Visit this group at https://groups.google.com/group/mojolicious.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 post to this group, send email to mojolicious@googlegroups.com.
Visit this group at https://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.


Re: [Mojolicious] How do I force Mojo::UserAgent to close connection?

2018-10-10 Thread Dan Book
$ua->max_connections(0);

https://metacpan.org/pod/Mojo::UserAgent#max_connections

-Dan

On Wed, Oct 10, 2018 at 5:53 PM Alex Povolotsky  wrote:

> Hello
>
> Reusing connections as it does Mojo::UserAgent is nice, but sometimes I
> have to change source IP of all next requests for given UA. Just changing
> local_address for tx seems to be pointless and ignored by Mojo::UserAgent.
> What should I do to perform the trick correctly?
>
> Alex
>
> --
> 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 post to this group, send email to mojolicious@googlegroups.com.
> Visit this group at https://groups.google.com/group/mojolicious.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 post to this group, send email to mojolicious@googlegroups.com.
Visit this group at https://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.


Re: [Mojolicious] Re: Mojo::Log and UTF-8

2018-10-10 Thread Dan Book
Mojo::Log already encodes data by default. Anything you send to stderr
outside of that should be encoded if necessary.

-Dan

On Wed, Oct 10, 2018 at 11:53 AM Alex Povolotsky  wrote:

> So I should not binmode STDERR, ':utf8' if I'm using Mojo::Log and always
> explicitly encode() data?
>
> суббота, 6 октября 2018 г., 20:30:12 UTC+3 пользователь Dan Book написал:
>>
>> The script is not quite correct. I suspect if you add "use warnings" you
>> will see a "Wide character in print" warning, because you are not encoding
>> your unicode characters to UTF-8 before printing them. However, on the
>> server where you are seeing the double encoding, perhaps you have a
>> PERL5OPT environment variable which is setting something like "-CSAD" and
>> thus encoding all output handles by default (this should not be globally
>> set, because it can mess with modules that don't expect it like this).
>>
>> -Dan
>>
>> On Sat, Oct 6, 2018 at 10:15 AM Alex Povolotsky  wrote:
>>
>>> Quite interesting. The simple script
>>>
>>> === cut mojolog ===
>>>
>>> #!/usr/bin/env perl
>>> use strict;
>>> use utf8;
>>> use Mojo::Log;
>>> my $log = new Mojo::Log;
>>> print "Просто принт\n";
>>> $log->info('тест лога');
>>> === cut mojolog ===
>>>
>>> yields fine results on all my servers but one.
>>>
>>> On it, I'm getting
>>>
>>> % perl mojolog
>>> Просто принт
>>> [Sat Oct  6 15:22:43 2018] [info] �е�� лога
>>>
>>> The second line is clearly wrong and seems to be badly encoded. Same
>>> version of OS, Perl, Mojolicious, same set of environment variables. What
>>> else could influence unicode processing?
>>>
>>> суббота, 6 октября 2018 г., 13:35:48 UTC+3 пользователь Alex Povolotsky
>>> написал:
>>>>
>>>> Hello
>>>>
>>>> How do I send UTF-8 constants to Mojo::Log? It forcefully encodes
>>>> everything so UTF-8 goes with double encoding and unreadable. Trying to
>>>> decode UTF-8 cat
>>>>
>>>> $log->info(decode('UTF-8', 'тест лога'));
>>>>
>>>> results in
>>>>
>>>> Use of uninitialized value $_[0] in join or string at
>>>> /usr/local/lib/perl5/site_perl/Mojo/Log.pm line 55.
>>>>
>>>> Looks like something is wrong...
>>>>
>>> --
>>> 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...@googlegroups.com.
>>> To post to this group, send email to mojol...@googlegroups.com.
>>> Visit this group at https://groups.google.com/group/mojolicious.
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>> --
> 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 post to this group, send email to mojolicious@googlegroups.com.
> Visit this group at https://groups.google.com/group/mojolicious.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 post to this group, send email to mojolicious@googlegroups.com.
Visit this group at https://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.


Re: [Mojolicious] Mojolicious::Plugin::AccessLog and x-real-ip behind reverse proxy

2018-10-03 Thread Dan Book
You need to set the 'proxy' configuration for hypnotoad, or if you're not
using hypnotoad, the MOJO_REVERSE_PROXY environment variable. See
https://metacpan.org/pod/Mojolicious::Guides::Cookbook#Reverse-proxy

-Dan

On Wed, Oct 3, 2018 at 6:16 PM Dan Harris  wrote:

> I have a new Mojolicous::Lite application behind an nginx reverse proxy.
> With the AccessLog plugin, the IP address of the reverse proxy is logged
> every time.  The nginx config seems to be OK and it was just working with a
> previous (not-mojolicious) application.  As a test I dumped the Request
> headers in the app and the correct IP address is stored both in 'x-real-ip'
> and in 'x-forwarded-for'.  I am using the "combined" log format for the
> plugin.  It seems like the plugin is not respecting the x-forwarded-for
> header.  Any guidance for me?
>
> Thank you!
>
> --
> 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 post to this group, send email to mojolicious@googlegroups.com.
> Visit this group at https://groups.google.com/group/mojolicious.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 post to this group, send email to mojolicious@googlegroups.com.
Visit this group at https://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.


Re: [Mojolicious] How do you generate a "Content-Length" header in a multipart request?

2018-09-18 Thread Dan Book
I think you missed something in my post. You should not need to add any
content length headers yourself.

-Dan

On Tue, Sep 18, 2018 at 1:28 PM Steve Dondley  wrote:

> Thanks. It doesn't look like adding the content-length helped. Still
> getting 400 errors. And I just noticed that in Google's example there is no
> content-length header for a GET request. Don't know what else to try now.
>
> On Tuesday, September 18, 2018 at 1:06:23 PM UTC-4, Dan Book wrote:
>>
>> These "parts" are essentially embedded HTTP requests; the lines under
>> each listed GET/PUT/etc are headers for that embedded request. Here is the
>> structure of their example annotated:
>>
>> POST /batch/farm/v1 HTTP/1.1 # actual request and headers
>> Authorization: Bearer your_auth_token
>> Host: www.googleapis.com
>> Content-Type: multipart/mixed; boundary=batch_foobarbaz
>> Content-Length: total_content_length
>> # rest is actual request content
>> --batch_foobarbaz # first multipart segment
>> Content-Type: application/http # multipart segment headers
>> Content-ID: 
>>
>> GET /farm/v1/animals/pony # multipart segment *content*
>>
>> --batch_foobarbaz # second multipart segment
>> Content-Type: application/http # multipart segment headers
>> Content-ID: 
>>
>> PUT /farm/v1/animals/sheep # multipart segment *content*
>> Content-Type: application/json
>> Content-Length: part_content_length
>> If-Match: "etag/sheep"
>>
>> {
>>   "animalName": "sheep",
>>   "animalAge": "5"
>>   "peltColor": "green",
>> }
>>
>> --batch_foobarbaz # third multipart segment
>> Content-Type: application/http # multipart segment headers
>> Content-ID: 
>>
>> GET /farm/v1/animals # multipart segment *content*
>> If-None-Match: "etag/animals"
>>
>> --batch_foobarbaz--
>>
>> As noted the part where the part_content_length is is inside the content
>> for one of the multipart segments. Mojolicious doesn't have anything to
>> deal with the content of multipart segments of this type, so you need to
>> construct them yourself, but you could maybe leverage Mojolicious's
>> existing ability to construct such HTTP requests.
>>
>> my $embedded_tx = $ua->build_tx(PUT => '/farm/v1/animals/sheep',
>> {'If-Match' => 'etag/sheep'}, json => $sheep_data);
>> ...
>> my $multipart_tx = $ua->post('/batch/farm/v1' => $headers => multipart =>
>> [
>>   {content => $embedded_tx->req->to_string, 'Content-Type' =>
>> 'application/http'},
>>   ...
>> ]);
>>
>> Hope that helps,
>> -Dan
>>
>> On Tue, Sep 18, 2018 at 12:50 PM Steve Dondley  wrote:
>>
>>> I'm starting a new thread related to the previous one regarding making a
>>> batch api request to Google's API. I keep getting "Bad Reqeust" responses
>>> from Google after making a batch API call (other calls work fine).
>>>
>>> Looking at the api documentation for batch api requests
>>> <https://developers.google.com/gmail/api/guides/batch> it says each
>>> part of the multipart request should have a content length. Here is the
>>> example Google supplies:
>>>
>>> POST /batch/farm/v1 HTTP/1.1
>>> Authorization: Bearer your_auth_token
>>> Host: www.googleapis.com
>>> Content-Type: multipart/mixed; boundary=batch_foobarbaz
>>> Content-Length: total_content_length
>>>
>>> --batch_foobarbaz
>>> Content-Type: application/http
>>> Content-ID: 
>>>
>>> GET /farm/v1/animals/pony
>>>
>>> --batch_foobarbaz
>>> Content-Type: application/http
>>> Content-ID: 
>>>
>>> PUT /farm/v1/animals/sheep
>>> Content-Type: application/json
>>> Content-Length: part_content_length
>>> If-Match: "etag/sheep"
>>>
>>> {
>>>   "animalName": "sheep",
>>>   "animalAge": "5"
>>>   "peltColor": "green",
>>> }
>>>
>>> --batch_foobarbaz
>>> Content-Type: application/http
>>> Content-ID: 
>>>
>>> GET /farm/v1/animals
>>> If-None-Match: "etag/animals"
>>>
>>> --batch_foobarbaz--
>>>
>>>
>>>
>>> The requests I'm generating with mojolicious do not have the
>>> "part_content_length." Here's mine:
>>>
>>> POST /batch/g

Re: [Mojolicious] How do you generate a "Content-Length" header in a multipart request?

2018-09-18 Thread Dan Book
These "parts" are essentially embedded HTTP requests; the lines under each
listed GET/PUT/etc are headers for that embedded request. Here is the
structure of their example annotated:

POST /batch/farm/v1 HTTP/1.1 # actual request and headers
Authorization: Bearer your_auth_token
Host: www.googleapis.com
Content-Type: multipart/mixed; boundary=batch_foobarbaz
Content-Length: total_content_length
# rest is actual request content
--batch_foobarbaz # first multipart segment
Content-Type: application/http # multipart segment headers
Content-ID: 

GET /farm/v1/animals/pony # multipart segment *content*

--batch_foobarbaz # second multipart segment
Content-Type: application/http # multipart segment headers
Content-ID: 

PUT /farm/v1/animals/sheep # multipart segment *content*
Content-Type: application/json
Content-Length: part_content_length
If-Match: "etag/sheep"

{
  "animalName": "sheep",
  "animalAge": "5"
  "peltColor": "green",
}

--batch_foobarbaz # third multipart segment
Content-Type: application/http # multipart segment headers
Content-ID: 

GET /farm/v1/animals # multipart segment *content*
If-None-Match: "etag/animals"

--batch_foobarbaz--

As noted the part where the part_content_length is is inside the content
for one of the multipart segments. Mojolicious doesn't have anything to
deal with the content of multipart segments of this type, so you need to
construct them yourself, but you could maybe leverage Mojolicious's
existing ability to construct such HTTP requests.

my $embedded_tx = $ua->build_tx(PUT => '/farm/v1/animals/sheep',
{'If-Match' => 'etag/sheep'}, json => $sheep_data);
...
my $multipart_tx = $ua->post('/batch/farm/v1' => $headers => multipart => [
  {content => $embedded_tx->req->to_string, 'Content-Type' =>
'application/http'},
  ...
]);

Hope that helps,
-Dan

On Tue, Sep 18, 2018 at 12:50 PM Steve Dondley  wrote:

> I'm starting a new thread related to the previous one regarding making a
> batch api request to Google's API. I keep getting "Bad Reqeust" responses
> from Google after making a batch API call (other calls work fine).
>
> Looking at the api documentation for batch api requests
>  it says each part
> of the multipart request should have a content length. Here is the example
> Google supplies:
>
> POST /batch/farm/v1 HTTP/1.1
> Authorization: Bearer your_auth_token
> Host: www.googleapis.com
> Content-Type: multipart/mixed; boundary=batch_foobarbaz
> Content-Length: total_content_length
>
> --batch_foobarbaz
> Content-Type: application/http
> Content-ID: 
>
> GET /farm/v1/animals/pony
>
> --batch_foobarbaz
> Content-Type: application/http
> Content-ID: 
>
> PUT /farm/v1/animals/sheep
> Content-Type: application/json
> Content-Length: part_content_length
> If-Match: "etag/sheep"
>
> {
>   "animalName": "sheep",
>   "animalAge": "5"
>   "peltColor": "green",
> }
>
> --batch_foobarbaz
> Content-Type: application/http
> Content-ID: 
>
> GET /farm/v1/animals
> If-None-Match: "etag/animals"
>
> --batch_foobarbaz--
>
>
>
> The requests I'm generating with mojolicious do not have the
> "part_content_length." Here's mine:
>
> POST /batch/gmail/v1 HTTP/1.1
> Authorization: Bearer A_REAL_TOKEN_GOES_HERE
> Host: www.googleapis.com
> Accept-Encoding: gzip
> Content-Length: 120
> User-Agent: Mojolicious (Perl)
> Content-Type: multipart/mixed; boundary=nS2CX
>
>
> --nS2CX
> Content-Type: application/http
>
>
> GET /gmail/v1/users/sdond...@gmail.com/messages/165eb111fcf21503
> --nS2CX--
>
>
>
> My question is, does Mojolicious provide a way to automatically generate a
> content length header for these parts? If not, which parts of the message
> get counted toward this length and how do I calculate it (assuming UTF-8)?
>
> --
> 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 post to this group, send email to mojolicious@googlegroups.com.
> Visit this group at https://groups.google.com/group/mojolicious.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 post to this group, send email to mojolicious@googlegroups.com.
Visit this group at https://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.


Re: [Mojolicious] using mojolicious to make a batch request to google api

2018-09-17 Thread Dan Book
You want the multipart content generator. Scroll down to the very last
example in https://metacpan.org/pod/Mojo::UserAgent::Transactor#tx

-Dan

On Mon, Sep 17, 2018 at 10:22 PM Steve Dondley  wrote:

> I'm trying to hack a perl module that uses mojolicious to make api calls
> to google's api so that it can make batch api call as documented here:
> https://developers.google.com/gmail/api/guides/batch
>
> I've made various attempts but no calls are resulting in a successful
> response. Here's what I'm currently trying.
>
>   my $options =
>   [
> {
>   content => 'GET /gmail/v1/users/
> m...@gmail.com/messages/165e91c27e4af0be',
>   'Content-Type' => 'application/http',
> },
> {
>   content => 'GET /gmail/v1/users/
> m...@gmail.com/messages/165e94ce49900df2',
>   'Content-Type' => 'application/http',
> }
>   ];
>
>
>   my $path = 'https://www.googleapis.com/batch/' . $s->api . '/' . $s
> ->version;
>
>
>   my $headers = {'Authorization' => 'Bearer TOKEN_HERE'};
>
>
>
>
>   $tx = $self->ua->build_tx(
> uc $http_method => $path => $headers => json =>
> $optional_data );
>
>
>
>
> This results in a tranaction object that looks like this:
>
>
> $VAR1 = bless( {
>  'req' => bless( {
>'content' => bless( {
>  'headers' =>
> bless( {
>
>  'headers' => {
>
> 'content-type' => [
>
> 'application/json'
>
>   ],
>
> 'authorization' => [
>
>  'Bearer TOKEN_HERE'
>
>],
>
> 'accept-encoding' => [
>
>'gzip'
>
>  ],
>
> 'user-agent' => [
>
>   'Mojolicious (Perl)'
>
> ]
>
>   }
>
>}, 'Mojo::Headers' ),
>  'events' => {
>
> 'read' => [
>
>  sub { "DUMMY" }
>
>]
>  },
>  'read' => $VAR1
> ->{'req'}{'content'}{'events'}{'read'}[0],
>  'asset' => bless(
> {
>
>'content' => '[{"Content-Type":"application\\/http","content":"GET
> \\/gmail\\/v1\\/u
> sers\\/m...@gmail.com\\/messages\\/165e91c27e4af0be"},{"Content-Type":"application\\/http","content":"GET
> \\/gmail\\/v1\\/users\\/m...@gmail.com\\/messag
> es\\/165e94ce49900df2"}]'
>
> }, 'Mojo::Asset::Memory' )
>},
> 'Mojo::Content::Single' ),
>'url' => bless( {
>  'scheme' => 'https',
>  'host' => '
> www.googleapis.com',
>  'path' => bless( {
>
> 'path' => '/batch/gmail/v1'
>   },
> 'Mojo::Path' )
>}, 'Mojo::URL' ),
>'method' => 'POST'
>  }, 'Mojo::Message::Request' )
>}, 'Mojo::Transaction::HTTP' );
>
>
>
> Trying anything other than json for the generator results in an error:
>  Use of uninitialized value $cb in method lookup
>
> Fiddling with the content type settings doesn't help make this go away.
>
> --
> 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 post to this group, send email to mojolicious@googlegroups.com.
> Visit this group at https://groups.google.com/group/mojolicious.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 post to this group, send email to mojolicious@googlegroups.com.
Visit this group at https://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.


Re: [Mojolicious] Re: Mojolicious not completing large requests from Google Contacts API

2018-09-12 Thread Dan Book
There should be no visible difference if you are retrieving the content
with methods like ->body ->text or ->json.

-Dan

On Wed, Sep 12, 2018 at 6:07 PM Steve Dondley  wrote:

> So I took a closer look at the response object returned. Looks like for
> smaller queries the response is stored in memory and for larger queries the
> response is stuffed into a temporary file, as far as I can tell. How do I
> get access to this file and where is it?
>
> On Wednesday, September 12, 2018 at 5:57:43 PM UTC-4, Steve Dondley wrote:
>>
>> I'm using Google's Contact API to download all my contacts. There are
>> probably several thousand contacts. I'm using the  Google::Moo
>>  perl module which uses the
>> Mojolicious user agent.
>>
>> I can successfully download up to about 200 contacts with one shot but
>> after that, I get a response with no content even though the response code
>> is "200." I set the $ENV variable to lift max_line_size, max_buffer_size,
>> etc. but it did not work.
>>
>> The limitation is not on Google's side as I can successfully get all
>> contacts via their web based Oauth 2.0 playground service.
>>
>> Any ideas on what I can try to coerce Mojolicious to get the content of
>> the api call with a large response?
>>
> --
> 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 post to this group, send email to mojolicious@googlegroups.com.
> Visit this group at https://groups.google.com/group/mojolicious.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 post to this group, send email to mojolicious@googlegroups.com.
Visit this group at https://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.


Re: [Mojolicious] Re: Using Mojo::DOM to update

2018-08-24 Thread Dan Book
Absolutely, that's what tap is for.

-Dan

On Fri, Aug 24, 2018 at 9:48 PM Stefan Adams  wrote:

> Sorry, I knew I should know better.
>
> I was using the ojo#x  example and
> I just added on to it:
>
> $ perl -Mojo -E 'say x(f("test.html")->slurp)->at("title")->content("NEW 
> TEXT")'
>
> I've lost access to the dom!  I needed to store the dom object in a
> variable so I could get back to the dom after looping thru find:
>
> $ perl -Mojo -E 'my $dom = x(f("test.html")->slurp); 
> $dom->at("title")->content("NEW TEXT"); say $dom'
>
> There was a discussion recently about tap.  Is this a good use for tap?
>
> $ perl -Mojo -E 'say 
> x(f("index.html")->slurp)->tap(sub{$_->at("title")->content("NEW TEXT")})'
>
> Now I have the full dom with my updated information!
>
> On Fri, Aug 24, 2018 at 8:24 PM Stefan Adams  wrote:
>
>> Can Mojo::DOM be used to update information in a tree? For example, if I
>> want to strip the host from all links, I might ->find('a[href]') and then
>> loop through the collection to do some updates. But unless I'm missing
>> something, I can't then update the original dom with these changes.
>>
> --
> 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 post to this group, send email to mojolicious@googlegroups.com.
> Visit this group at https://groups.google.com/group/mojolicious.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 post to this group, send email to mojolicious@googlegroups.com.
Visit this group at https://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.


Re: [Mojolicious] Re: Mojo::UserAgent and large files

2018-08-17 Thread Dan Book
Though the other problem in this case is that you are not keeping the
Mojo::UserAgent object alive because it's scoped inside the action:
https://mojolicious.org/perldoc/Mojolicious/Guides/FAQ#What-does-Premature-connection-close-mean

On Fri, Aug 17, 2018 at 1:39 PM Dan Book  wrote:

> You don't need to keep a reference to the controller but to the
> transaction. See
> https://mojolicious.org/perldoc/Mojolicious/Guides/FAQ#What-does-Transaction-already-destroyed-mean
>
> On Fri, Aug 17, 2018 at 1:22 PM Heiko Jansen 
> wrote:
>
>> Hmm, there's no access to the controller ($c) and no reference to it kept
>> in the fullfillment or rejection callbacks.
>> I'd guess it is therefore garbage collected once you leave "welcome" and
>> the client connection thus closed immediately.
>>
>> hth,
>> heiko
>>
>> --
>> 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 post to this group, send email to mojolicious@googlegroups.com.
>> Visit this group at https://groups.google.com/group/mojolicious.
>> For more options, visit https://groups.google.com/d/optout.
>>
>

-- 
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 post to this group, send email to mojolicious@googlegroups.com.
Visit this group at https://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.


Re: [Mojolicious] Re: Mojo::UserAgent and large files

2018-08-17 Thread Dan Book
You don't need to keep a reference to the controller but to the
transaction. See
https://mojolicious.org/perldoc/Mojolicious/Guides/FAQ#What-does-Transaction-already-destroyed-mean

On Fri, Aug 17, 2018 at 1:22 PM Heiko Jansen 
wrote:

> Hmm, there's no access to the controller ($c) and no reference to it kept
> in the fullfillment or rejection callbacks.
> I'd guess it is therefore garbage collected once you leave "welcome" and
> the client connection thus closed immediately.
>
> hth,
> heiko
>
> --
> 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 post to this group, send email to mojolicious@googlegroups.com.
> Visit this group at https://groups.google.com/group/mojolicious.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 post to this group, send email to mojolicious@googlegroups.com.
Visit this group at https://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.


Re: [Mojolicious] Re: Grouping Mojo::Collection of hashes

2018-08-03 Thread Dan Book
An alternative using Mojo::Collection::Role::UtilsBy:

use Mojo::Collection 'c';
use Mojo::Util 'dumper';

my $start = c({name => 'name1', total => 2}, {name => 'name1', total => 3},
{name => 'name2', total => 7})->with_roles('+UtilsBy');
my $end = c(map { $_->reduce(sub { $a->{total} += $b->{total}; $a }) }
values %{$start->partition_by(sub { $_->{name} })});
print dumper $end->to_array;

-Dan

On Fri, Aug 3, 2018 at 11:27 AM Jason Cooper  wrote:

> You'd probably need to reduce it to a hash of name to total and then map
> that back to a Mojo::Collection, e.g.:
>
> #!/usr/bin/env perl
>
> use strict;
> use warnings;
>
> use Mojo::Collection;
> use Data::Dumper;
>
> my $collection= Mojo::Collection->new({name=>"name1", total=>2},
> {name=>"name1",total=>3}, {name=>"name2", total=>7});
>
>
> my $firstPass = $collection->reduce( sub {
> $a->{$b->{name}} += $b->{total};
>
> return $a;
> }, {});
>
> my $newCollection = Mojo::Collection->new(
> map {
> { name => $_, total => $firstPass->{$_} }
> } keys %{$firstPass}
> );
>
> print Dumper($collection);
> print Dumper($newCollection);
>
>
>
>
> On Friday, 3 August 2018 13:50:19 UTC+1, Stefan Adams wrote:
>>
>> I have a Mojo::Collection of hashes and I'd like to reduce the collection
>> similar to an SQL GROUP BY.
>>
>> Mojo::Collection->new({name=>"name1", total=>2},
>> {name=>"name1",total=>3}, {name=>"name2", total=>7})
>>
>>
>> This collection has three elements and the collection I'm looking for
>> would have two:
>>
>> {name=>"name1", total=>*5*}, {name=>"name2",total=>7}
>>
>>
>> I'm trying to group by name and then sum the totals within that group.
>>
>> It seems like I should use the reduce method of Mojo::Collection; if
>> that's appropriate, how could I accomplish that?
>>
> --
> 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 post to this group, send email to mojolicious@googlegroups.com.
> Visit this group at https://groups.google.com/group/mojolicious.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 post to this group, send email to mojolicious@googlegroups.com.
Visit this group at https://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.


Re: [Mojolicious] Minion args

2018-04-26 Thread Dan Book
What backend are you using?

Note that the args have to be decoded from JSON whenever accessed and when
starting the job, which for pure-perl parsers can be very slow. Perhaps try
loading Mojo::JSON::MaybeXS in your app. Otherwise I'd suggest storing it
in a separate table in a way that doesn't require encoding or decoding, or
using Sereal to serialize it for storage.

-Dan

On Fri, Apr 27, 2018 at 12:05 AM, Stefan Adams  wrote:

> Is there a maximum length that I should respect for the args being passed
> to a Minion task?
>
> I have a job that has an arg of 2MB and the state is failed with a result
> of "Worker went away".  Using the Minion Admin UI, I clicked on the
> "failed" tasks and it hangs my entire Ubuntu 16.04.3 system!  I've had to
> reboot three times now.  I have since manually removed that specific job
> from the database and now, so far, all seems to be well, and I can also
> browse failed tasks (there are now 0).
>
> If I shouldn't be passing 2MB via args, should I instead save the 2MB to
> disk and let the job remove the file from disk when the job has finished
> successfully?
>
> --
> 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 post to this group, send email to mojolicious@googlegroups.com.
> Visit this group at https://groups.google.com/group/mojolicious.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 post to this group, send email to mojolicious@googlegroups.com.
Visit this group at https://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.


Re: [Mojolicious] Accessing SQLite database from two different modules

2018-04-24 Thread Dan Book
Even with write-ahead logging, committing a transaction or running a data
update outside a transaction should be immediately reflected in any other
readers -- as long as they run the read query after the commit/update has
completed. The ability to read while another connection is writing (and see
the state unaffected by the transaction) is the primary purpose of WAL mode.

I don't see any issue with what you presented so far, but more important
would be to see how you are running updates or transactions.

-Dan

On Tue, Apr 24, 2018 at 6:48 PM, mimosinnet  wrote:

> After writing a Mojolicious application
>  in Mojo::SQLite,
> some transactions doesn't seem to be immediately committed to the database.
> I wonder if this is related to SQLite Write-Ahead Logging
>  or how I have defined Mojo::SQLite (I am
> afraid it is the latter  :(  ). This is the logic I have followed:
>
> --> As some modules need to access the database, I have defined a module
> that loads the database
> 
> :
>
> *package GestioMaster::Obj::DB;*
> use Mojo::Base -base;
>
> use Mojo::SQLite;
> use GestioMaster::Model::DB;
>
> has sqlite => sub { Mojo::SQLite->new('sqlite:db/master.db') };
>
> has model  => sub {
> my $self = shift;
> return GestioMaster::Model::DB->new( sqlite =>  $self->sqlite );
> };
>
> --> This module is used when loading the application
> 
> :
>
> package GestioMaster;
> use Mojo::Base 'Mojolicious';
> *use GestioMaster::Obj::DB;*
>
> sub startup {
>   my $self = shift;
>   my $config = $self->plugin('Config');
>   $self->helper( model => sub {
> state $model = GestioMaster::Obj::DB->new->model;
>});
> ...
>
> --> Accessing the database is defined in the Model
> 
> :
>
> package GestioMaster::Model::DB;
> use Mojo::Base -base;
> has 'sqlite';
> ...
> sub un_modul {
> my ($self, $modul) = @_;
> return $self->sqlite->db->select('moduls',undef,{ modul => $modul})->hash;
> }
> ...
>
> --> The same module is also used to define registers from the database
> 
> :
>
> package *GestioMaster::Obj::Modul*;
> use Mojo::Base -base;
> # Object that makes database available
> *use GestioMaster::Obj::DB;*
>
> has _model => sub { GestioMaster::Obj::DB->new->model  };
> has modul => "";
>
> has un_modul => sub {
> my $self = shift;
> return $self->_model->un_modul( $self->modul );
> };
>
> has ident => sub { shift->un_modul->{'ident'} };
> has coord => sub { shift->un_modul->{'coord'} };
> has nom_modul => sub { shift->un_modul->{'nom_modul'}; };
> ...
>
>
> --> This builds an array-ref of registers
> 
> :
>
> package GestioMaster::Controller::Moduls::Modul;
> use Mojo::Base -base;
> use *GestioMaster::Obj::Modul*;
>
> has moduls => sub {
> my $self = shift;
> my @moduls = qw/M1 M2a M2b M3a M3b M3d M3e M4 M5a M5b M5c M5d M6/;
> my $mod_obj = [];
> foreach my $mod ( @moduls  ) {
> push @{$mod_obj}, *GestioMaster::Obj::Modul*->new( modul => $mod );
> }
> return $mod_obj;
> };
>
> d) Used in the controller
> 
> :
>
> package GestioMaster::Controller::Public;
> use GestioMaster::Controller::Moduls::Modul;
> state $moduls = GestioMaster::Controller::Moduls::Modul->new->moduls;
>
> sub inici  { shift->render( moduls => $moduls ) }
>
>
> e) That promised straightforward templates
> 
> :
>
> % foreach my $mod ( @{ $moduls } ) {
> <%= $mod->modul . ": " .
> $mod->nom_modul %>
> % }
>
>
> So far so good, till the application started to write to the database and
> noticed some transactions were not immediately committed :O
>
>
> My questions:
>
> a) Opening the database in two different modules has an effect on how
> transactions are committed?
> b) Could this be solved by "Application-Initiated Checkpoints
> "?
> c) If the application has to be rewritten, how can the database defined
> in package *GestioMaster* be accessed from *GestioMaster::Obj::Modul*?
>
> Thanks!
>
> --
> 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 post to this group, send email to mojolicious@googlegroups.com.
> Visit this group at 

Re: [Mojolicious] Last try

2018-04-12 Thread Dan Book
The wait method will only block until the promise completes if the event
loop is not currently running. To be portable, anything that relies on the
results of the promise should only occur in further promise callbacks. And
note also that you can resolve promises using values by returning them from
the callbacks, and those values will be passed to the next callback, for
example:

$self->stockitems->search_p('*')->then(sub {
  ...
  return 'Test Test Test';
})->catch(sub {
  ...
  return 'ERROR';
})->then(sub {
  my $mytest = shift;
  $self->render(template => 'stockitems/search', mytest => $mytest);
})->wait;

-Dan

On Thu, Apr 12, 2018 at 2:03 PM, Jan Eskilsson 
wrote:

>
> Hi All
>
> The piece of code below always render "Test" indicating to me that the
> $mytest variable is never touched in the anonymous sub in the then or the
> catch. I cant understand what i do wrong ?
>
> sub search {
> my $self = shift;
>
> my $mytest = 'Test';
> $self->stockitems->search_p('*')->then(sub {
>   my $results = shift;
>
>   $mytest = 'Test Test Test';
> })->catch (sub {
>   my $err = shift;
>
>   $mytest = 'ERROR';
> })->wait;;
>
> $self->render(template => 'stockitems/search',  mytest => $mytest);
> }
>
> Any feedback or ideas are much apreciated
>
> Thank you in advance !
>
>
> Best Regards
> Jan
>
> --
> Titles mean nothing.  The one with a servant's heart is the leader.
>
> Please consider the environment before you print this email.
>
> All incoming and outgoing emails and any attachments are subjected to a
> virus scanner and are believed to be free of any virus, or any other defect
> which might affect any computer or IT system into which they are received
> and opened. Therefore, it is the responsibility of the recipient to ensure
> that they are virus free and no responsibility is accepted by Jan Eskilsson
>  for any loss or damage arising in any way from receipt or use thereof.
>
> --
> 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 post to this group, send email to mojolicious@googlegroups.com.
> Visit this group at https://groups.google.com/group/mojolicious.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 post to this group, send email to mojolicious@googlegroups.com.
Visit this group at https://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.


Re: [Mojolicious] rendering images located outside of public directory

2018-04-05 Thread Dan Book
Sorry, your issue is in routing: your showimg route is POST-only, but
browsers will always use GET to request an image.

On Thu, Apr 5, 2018 at 2:32 PM, Dan Book <gri...@gmail.com> wrote:

> Try this: https://metacpan.org/pod/Mojolicious::Guides::
> Rendering#Custom-responses
>
> On Thu, Apr 5, 2018 at 2:26 PM, Caveman Pl <caveman...@gmail.com> wrote:
>
>> Hi group,
>>
>> I have no idea how to export images located outside of public directory.
>> Forgive me to disturbing groups such a lame questions but cant find
>> working example with google...
>>
>> I have a route
>>
>> $r->get('/pdataexport_qc')->to('Pdataexport#showQC');
>> $r->post('/showqcshowimg')->to('Pdataexport#showQCshowIMG');
>>
>> in my Pdataexport.pm
>>
>> sub showQC{
>> my $self = shift;
>> my $pDataPath = $self->config('phenotypeDataFromResoraDbFilesPath');
>> my $dir = $self->param('dir');
>> $self->stash( dirToQC => $dir);
>> $self->render('phenotypeExport/showDataQC');
>> }
>>
>> my template phenotypeExport/showDataQC.html.ep
>>
>>
>> % layout 'all';
>> 
>> https://192.168.11.11:1777/showqcshowimg?dir=<%=$dirToQ
>> C%>=AH1vsAGE.png">
>> 
>> 
>> 
>>
>> which generates me nice url
>> 
>> https://192.168.11.11:1777/showqcshowimg?dir=2018-04-
>> 03-18-32-46_G=AH1vsAGE.png">
>> 
>> 
>>
>>
>> but in log output I can see that was not routed to showqcshowimg
>> sub showQCshowIMG {
>> my $self = shift;
>> my $img = $self->param('img');
>> my $dir = $self->param('dir');
>> my $pDataPath = $self->config('phenotypeDataFromResoraDbFilesPath');
>> $self->render_file(filepath => $pDataPath.$dir."/".$img, 'filename'
>> => $img );
>> }
>>
>> Can you give a simpe example how it should be done?
>> or maybe you know page or open project which can play as example?
>>
>> Thank you,
>> tj
>>
>>
>>
>>
>> --
>> 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 post to this group, send email to mojolicious@googlegroups.com.
>> Visit this group at https://groups.google.com/group/mojolicious.
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>

-- 
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 post to this group, send email to mojolicious@googlegroups.com.
Visit this group at https://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.


Re: [Mojolicious] rendering images located outside of public directory

2018-04-05 Thread Dan Book
Try this:
https://metacpan.org/pod/Mojolicious::Guides::Rendering#Custom-responses

On Thu, Apr 5, 2018 at 2:26 PM, Caveman Pl  wrote:

> Hi group,
>
> I have no idea how to export images located outside of public directory.
> Forgive me to disturbing groups such a lame questions but cant find
> working example with google...
>
> I have a route
>
> $r->get('/pdataexport_qc')->to('Pdataexport#showQC');
> $r->post('/showqcshowimg')->to('Pdataexport#showQCshowIMG');
>
> in my Pdataexport.pm
>
> sub showQC{
> my $self = shift;
> my $pDataPath = $self->config('phenotypeDataFromResoraDbFilesPath');
> my $dir = $self->param('dir');
> $self->stash( dirToQC => $dir);
> $self->render('phenotypeExport/showDataQC');
> }
>
> my template phenotypeExport/showDataQC.html.ep
>
>
> % layout 'all';
> 
> https://192.168.11.11:1777/showqcshowimg?dir=<%=$
> dirToQC%>=AH1vsAGE.png">
> 
> 
> 
>
> which generates me nice url
> 
> https://192.168.11.11:1777/showqcshowimg?dir=2018-
> 04-03-18-32-46_G=AH1vsAGE.png">
> 
> 
>
>
> but in log output I can see that was not routed to showqcshowimg
> sub showQCshowIMG {
> my $self = shift;
> my $img = $self->param('img');
> my $dir = $self->param('dir');
> my $pDataPath = $self->config('phenotypeDataFromResoraDbFilesPath');
> $self->render_file(filepath => $pDataPath.$dir."/".$img, 'filename' =>
> $img );
> }
>
> Can you give a simpe example how it should be done?
> or maybe you know page or open project which can play as example?
>
> Thank you,
> tj
>
>
>
>
> --
> 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 post to this group, send email to mojolicious@googlegroups.com.
> Visit this group at https://groups.google.com/group/mojolicious.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 post to this group, send email to mojolicious@googlegroups.com.
Visit this group at https://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.


Re: [Mojolicious] Re: Structured helpers

2018-03-29 Thread Dan Book
The template is rendered within its own namespace unique to that
compilation, so you cannot inject subs directly. You can however pass
coderefs in the stash and then do $foobar->() in the template. But
namespacing the helpers seems reasonable to me.

-Dan

On Thu, Mar 29, 2018 at 9:47 AM, Leo Cacciari 
wrote:

> On Wed, Mar 28, 2018 at 2:39 PM, sri  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
> ::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
>
>
> --
> Leo Cacciari
>
> Aliae nationes servitutem pati possunt. Populi Romani est propria libertas.
>
> --
> 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 post to this group, send email to mojolicious@googlegroups.com.
> Visit this group at https://groups.google.com/group/mojolicious.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 post to this group, send email to mojolicious@googlegroups.com.
Visit this group at https://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.


Re: [Mojolicious] Mojolicious::Lite how to refresh table only

2018-03-21 Thread Dan Book
Refreshing the page and refreshing the table are two different things. The
latter you would need to do in javascript, ideally with a framework like
vue or react that can handle the ugly details. If you refresh the page, you
only need to have the route provide the subset of the data instead of the
full set when it receives the search term.

-Dan

On Wed, Mar 21, 2018 at 11:43 AM, Luc Larochelle 
wrote:

> Hi everyone,
>
> I built a single page application to display content in a table with
> Mojolicious Lite. This works fine, the first time the data is rendered.
>
> I pass the values through the stash and in my template, I use a for loop
> to go through the structure and display in the web page.
>
> The problem is selecting a subset of the data (a search box for example).
> I don't understand how to pass the values to the stash and refresh the page.
>
> The stash changes with the desired data after a call to a get sub (for
> example get '/search/:expr' ) but it will never render. As if it gets
> rendered twice, since the final result is the whole table being displayed.
>
> What would be the best way to achieve this ?
>
> Please help ...
>
> --
> 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 post to this group, send email to mojolicious@googlegroups.com.
> Visit this group at https://groups.google.com/group/mojolicious.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 post to this group, send email to mojolicious@googlegroups.com.
Visit this group at https://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.


  1   2   >