This file is indexed.

/usr/lib/perl5/AnyEvent/Impl/Irssi.pm is in libanyevent-perl 7.010-1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
=head1 NAME

AnyEvent::Impl::Irssi - AnyEvent adaptor for Irssi

=head1 SYNOPSIS

   use AnyEvent;
  
   # this module gets loaded automatically when running under irssi

=head1 DESCRIPTION

This module provides transparent support for AnyEvent. You don't have to
do anything to make Irssi scripts work with AnyEvent.

Limitations of this backend and implementation details:

=over 4

=item * This backend does not support blocking waits.

That means you must set a callback on any condvars, or otherwise make sure
to never call C<recv> on a condvar that hasn't been signalled yet.

=item * Child exits will be handled by AnyEvent.

AnyEvent will take over child handling, as Irssi only polls for children
once/second and cannot handle unspecific child watchers.

This I<should> have no negative effect, as AnyEvent will emit a pidwait
signal just like irssi itself would.

=item * Artificial timer delays.

Irssi artificially enforces timers to have at least a 10ms delay (by
croaking, even).

This means that some applications will be limited to a rate of 100Hz (for
example, L<Coro::AnyEvent> thread scheduling).

=item * Irssi leaks memory like hell.

Yeah.

=back

Apart from that, documentation is notoriously wrong (e.g. file handles
are not supported by C<input_add>, contrary to documentation), hooking
into irssi has to be done in... weird... ways, but otherwise, Irssi is
surprisingly full-featured (for basically being a hack).

=cut

package AnyEvent::Impl::Irssi;

use AnyEvent (); BEGIN { AnyEvent::common_sense }
use Carp ();
use Irssi ();

our @ISA;

# irssi works only from certain namespaces, so we
# create one and use it.
sub init {
   my $pkg = caller;

   push @ISA, $pkg;

   local $/;
   eval "package $pkg; " . <DATA>;
   print "AnyEvent::Impl::Irssi fatal compilation error: $@" if $@;

   close DATA;
}

Irssi::command "/script exec -permanent AnyEvent::Impl::Irssi::init 'AnyEvent adaptor'";

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