AnyEvent-Lingr
view release on metacpan or search on metacpan
lib/AnyEvent/Lingr.pm view on Meta::CPAN
$self->session( $res->{session} );
$self->_get_channels;
}
else {
debugf "session create failed: %s", ddf($res || $hdr);
$self->_on_error($res, $hdr);
}
});
}
Scalar::Util::weaken($self);
}
sub update_room_info {
my ($self) = @_;
$self->_get_channels;
}
sub _get_channels {
my ($self) = @_;
lib/AnyEvent/Lingr.pm view on Meta::CPAN
return unless $self;
if ($res and $res->{status} eq 'ok') {
debugf "got rooms: %s", ddf($res->{rooms});
$self->_update_room_info( $res->{rooms} );
}
else {
$self->_on_error($res, $hdr);
}
});
Scalar::Util::weaken($self);
}
sub _update_room_info {
my ($self, $rooms) = @_;
$self->get('room/show', { session => $self->session, room => join ',', @{ $rooms } }, sub {
my ($res, $hdr) = @_;
return unless $self;
if ($res and $res->{status} eq 'ok') {
lib/AnyEvent/Lingr.pm view on Meta::CPAN
else {
debugf "no room info callback";
}
$self->_start_observe($rooms);
}
else {
$self->_on_error($res, $hdr);
}
});
Scalar::Util::weaken($self);
}
sub _start_observe {
my ($self, $rooms) = @_;
$self->post('room/subscribe', {
session => $self->session,
rooms => join(',', @$rooms),
reset => 1,
}, sub {
lib/AnyEvent/Lingr.pm view on Meta::CPAN
return unless $self;
if ($res and $res->{status} eq 'ok') {
$self->counter( $res->{counter} );
$self->_polling;
}
else {
$self->_on_error($res, $hdr);
}
});
Scalar::Util::weaken($self);
}
sub _polling {
my ($self) = @_;
if ($self->_polling_guard) {
debugf 'polling session is still active, ignoring this request';
return;
}
lib/AnyEvent/Lingr.pm view on Meta::CPAN
}
}
$self->_clear_polling_guard;
$self->_polling;
}
else {
$self->_on_error($res, $hdr);
}
};
Scalar::Util::weaken($self);
$self->_polling_guard( $guard );
}
sub say {
my ($self, $room, $msg, $cb) = @_;
$self->post('room/say', { session => $self->session, room => $room, text => $msg }, sub {
my ($res, $hdr) = @_;
return unless $self;
if ($res and $res->{status} eq 'ok') {
$cb->($res) if $cb;
}
else {
$self->_on_error($res, $hdr);
}
});
Scalar::Util::weaken($self);
}
1;
__END__
=head1 NAME
AnyEvent::Lingr - Asynchronous Lingr client.
( run in 0.358 second using v1.01-cache-2.11-cpan-65fba6d93b7 )