AnyEvent-Tickit

 view release on metacpan or  search on metacpan

lib/AnyEvent/Tickit.pm  view on Meta::CPAN

# ABSTRACT: Use L<AnyEvent> with L<Tickit> user interface.

use strict;
use warnings;
package AnyEvent::Tickit;
BEGIN {
  $AnyEvent::Tickit::AUTHORITY = 'cpan:AJGB';
}
$AnyEvent::Tickit::VERSION = '0.01';
use AnyEvent;
use base qw( Tickit );

sub _capture_weakself {
    my ($self, $method) = @_;

    Scalar::Util::weaken $self;

    my $cb = $self->can($method);

    return $cb->( $self, @_ );
}

sub new {
    my ($class, %args) = @_;

    my $cv = delete $args{cv};

    my $self = $class->Tickit::new( %args );

    $self->{ae_loop} = $cv || AE::cv;

    $self->{ae_sigwinch} = AE::signal WINCH => sub {
        $self->_SIGWINCH;
    };

    $self->{ae_io} = AE::io $self->term->get_input_handle, 0, sub {
        $self->_input_readready();
    };

    $self->{ae_timer} = AE::timer 0, 0, sub {
        $self->_timeout();
    };

    return $self;
}

sub get_loop {
    return $_[0]->{ae_loop};
}

sub _make_writer {
    my ($self, $out) = @_;

    $self->{ae_writer} = AnyEvent::Tickit::Handle->new(
        fh => $out,
        no_delay => 1,
    );

    return $self->{ae_writer};
}

sub _input_readready {
    my $self = shift;

    my $term = $self->term;

    undef $self->{timer};

    $term->input_readable();

    $self->_timeout;
}

sub _timeout {
    my $self = shift;



( run in 1.784 second using v1.01-cache-2.11-cpan-39bf76dae61 )