Re: [Mojolicious] Understanding shift->

2018-11-24 Thread john



On 11/24/18 2:51 PM, Dan Book wrote:
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.

Thanks.  I totally missed that it was being used in a sub in those cases.

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


[Mojolicious] Understanding shift->

2018-11-24 Thread john

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.


Re: [Mojolicious] Re: Pg::PubSub in full application

2018-11-24 Thread Stefan Adams
On Sat, Nov 24, 2018 at 11:09 AM sri  wrote:

> This might now be resolved with the 4.12 release.
>>
>
> https://metacpan.org/release/SRI/Mojo-Pg-4.12
>

Yay!!  I'm so glad this didn't get deprecated!!

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


[Mojolicious] Re: Pg::PubSub in full application

2018-11-24 Thread sri

>
> ... like in the blog example...
>

Forgot the link.

https://github.com/mojolicious/mojo-pg/tree/master/examples/blog

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


[Mojolicious] Re: Pg::PubSub in full application

2018-11-24 Thread sri

>
> I have previously used lite based applications and am starting to get 
> familiar with full applications.   I have been struggling to understand 
> how to implement Pg::PubSub across different parts of my application. 
>

You don't implement anything. Just use Mojo::Pg like in the blog example
and then in your controllers "$c->pg->pubsub->...". That's the whole
reason it exists.

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


[Mojolicious] Re: Pg::PubSub in full application

2018-11-24 Thread sri

>
> Please avoid using Mojo::Pg::PubSub for now. It is broken and on the
> verge of getting deprecated.
>
> https://github.com/mojolicious/mojo-pg/issues/50
>
> I've been meaning to do it two weeks ago, but members of the
> community have asked me to wait and give them a chance to fix it.
> Unfortunately that has not happened, so it's likely going away soon.
>

This might now be resolved with the 4.12 release.

https://metacpan.org/release/SRI/Mojo-Pg-4.12

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