AnyEvent

 view release on metacpan or  search on metacpan

lib/AnyEvent/Impl/Irssi.pm  view on Meta::CPAN

1;

__DATA__

BEGIN { AnyEvent::common_sense }
use base "AnyEvent::Base";

sub io {
   my ($class, %arg) = @_;
   
   my $cb = $arg{cb};
   my $fd = fileno $arg{fh};
   defined $fd or $fd = $arg{fh};

   my $source = Irssi::input_add
      $fd,
      $arg{poll} eq "r" ? Irssi::INPUT_READ : Irssi::INPUT_WRITE,
      $cb,
      undef;

   bless \\$source, "AnyEvent::Impl::Irssi::io"
}

sub AnyEvent::Impl::Irssi::io::DESTROY {
   Irssi::input_remove $${$_[0]};
}

sub timer {
   my ($class, %arg) = @_;
   
   my $cb    = $arg{cb};
   my $ival  = $arg{interval} * 1000;
   my $after = $arg{after} * 1000;

   my $source; $source = Irssi::timeout_add_once $after > 10 ? $after : 10,
      ($ival ? sub {
                 $source = Irssi::timeout_add $ival > 10 ? $ival : 10, $cb, undef;
                 &$cb;
                 0
               }
             : $cb),
      undef;

   bless \\$source, "AnyEvent::Impl::Irssi::timer"
}

sub AnyEvent::Impl::Irssi::timer::DESTROY {
   Irssi::timeout_remove $${$_[0]};
}

my $_pidwait = sub {
   my ($rpid, $rstatus) = @_;

   AnyEvent::Base->_emit_childstatus ($rpid, $rstatus);
};

Irssi::signal_add pidwait => $_pidwait;

sub _emit_childstatus {
   my ($self, $rpid, $rstatus) = @_;
   $self->SUPER::_emit_childstatus ($rpid, $rstatus);

   Irssi::signal_remove pidwait => $_pidwait;
   Irssi::signal_emit   pidwait => $rpid+0, $rstatus+0;
   Irssi::signal_add    pidwait => $_pidwait;
}

#sub loop {
#   Carp::croak "Irssi does not support blocking waits";
#}

=head1 SEE ALSO

L<AnyEvent>, L<Irssi>.

=head1 AUTHOR

 Marc Lehmann <schmorp@schmorp.de>
 http://anyevent.schmorp.de

=cut

1



( run in 0.555 second using v1.01-cache-2.11-cpan-0bb4e1dffa6 )