DBGp-Client-AnyEvent
view release on metacpan or search on metacpan
lib/DBGp/Client/AnyEvent/Connection.pm view on Meta::CPAN
package DBGp::Client::AnyEvent::Connection;
use strict;
use warnings;
use AnyEvent::Handle;
use DBGp::Client::AsyncConnection;
use Scalar::Util qw(weaken blessed);
sub new {
my ($class, %args) = @_;
my $self = bless {
handle => undef,
on_stream => undef,
on_notify => undef,
connection => DBGp::Client::AsyncConnection->new(socket => $args{socket}),
}, $class;
my $weak_self = $self;
weaken($weak_self);
my $handle = AnyEvent::Handle->new(
fh => $args{socket},
on_error => sub {
my ($handle, $fatal, $message) = @_;
$weak_self->{handle} = undef;
$handle->destroy;
$weak_self->{connection}->closed;
},
on_read => sub {
lib/DBGp/Client/AnyEvent/Listener.pm view on Meta::CPAN
package DBGp::Client::AnyEvent::Listener;
use strict;
use warnings;
use AnyEvent::Socket qw(tcp_server);
use DBGp::Client::AnyEvent::Connection;
use Scalar::Util qw(weaken);
sub new {
my ($class, %args) = @_;
my $self = bless {
port => $args{port},
path => $args{path},
mode => $args{mode},
on_connection => $args{on_connection},
tcp_guard => undef,
}, $class;
die "Specify either 'port' or 'path'" unless $self->{port} || $self->{path};
return $self;
}
sub listen {
my ($self) = @_;
my $weak_self = $self;
weaken($weak_self);
my $cb = sub { $weak_self->_new_connection($_[0]) };
my $prepare = ($self->{path} && defined $self->{mode}) ? sub {
chmod $weak_self->{mode}, $weak_self->{path}
or die "Unable to change file mode for socket: $!";
} : undef;
if ($self->{port}) {
$self->{guard} = tcp_server('127.0.0.1', $self->{port}, $cb);
} elsif ($self->{path}) {
$self->{guard} = tcp_server('unix/', $self->{path}, $cb, $prepare);
}
( run in 0.733 second using v1.01-cache-2.11-cpan-65fba6d93b7 )