Hello,

In my test application (https://github.com/john-/mojo_inotifier) I am able to have a websocket client receive notifications when a file is added to a directory.

In order to get this to work I had to define my callback (n the route) with "our":

    our $cb = $watcher->watch(
        sub {
            my $payload = shift;
            $payload->{url} = $c->app->defaults->{audio_url};
            $c = $c->send( { json => encode_json($payload) } );
        }
    );


If I define it with "my" then scope rules cause the variable (and therefore callback) to be lost.

What confuses me is that I was previously using Mojo::Pg::PubSub and this works:

    my $cb = $c->pubsub->listen(msg => sub {
        my ($pubsub, $payload) = @_;
        my $msg = decode_json($payload);
        $c = $c->send( { json => $msg } );
        app->log->debug("item to let client know about (pubsub): $msg->{type}");
    });

Why does "my" work in this case but not in the other? It is not clear to me in reviewing Pg::PubSub code that there is anything different that would explain this.

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.

Reply via email to