perlanyevent

Pass a class subroutine as a callback


I am using a module that takes callbacks (AnyEvent::Socket). I am trying to pass a class subroutine as a callback but nothing is working example:

tcp_server undef, $self->port,\$self->handle_connection

It just does not work, it complaints about undefined variables. if I pass the function as a anonymous subroutine it works


Solution

  • You can pass a anonymous function which calls object method,

    sub{ $self->handle_connection }