2

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

user2348668
  • 768
  • 7
  • 19

2 Answers2

5

You can pass a anonymous function which calls object method,

sub{ $self->handle_connection }
mpapec
  • 50,217
  • 8
  • 67
  • 127
1

The curry module was built for this sort of thing

use curry;

tcp_server undef, $self->port, $self->curry::handle_connection
LeoNerd
  • 8,344
  • 1
  • 29
  • 36