1# This is useful with irssiproxy, to monitor irc on a separate terminal,
2# or if you just want to sit back and watch conversations. It just
3# lets Irssi go to the active window whenever there's any activity.
4#
5# It was made to demonstrate Irssi's new Perl capabilities...
6#
7# Juerd <juerd@juerd.nl>
8
9use strict;
10use vars qw($VERSION %IRSSI);
11
12use Irssi qw(command_bind active_win);
13$VERSION = '1.10';
14%IRSSI = (
15    authors     => 'Juerd',
16    contact     => 'juerd@juerd.nl',
17    name        => 'Follower',
18    description => 'Automatically switch to active windows',
19    license     => 'Public Domain',
20    url         => 'http://juerd.nl/irssi/',
21    changed     => 'Thu Mar 19 11:00 CET 2002',
22);
23
24use Irssi 20011211 qw(signal_add command);
25
26sub sig_own {
27    my ($server, $msg, $target, $orig_target) = @_;
28    $server->print($target, 'Chatting with follow.pl loaded is very foolish.');
29}
30
31signal_add {
32	    'window hilight'         => sub { command 'window goto active' },
33	    'message own_public'     => \&sig_own,
34	    'message own_private'    => \&sig_own,
35	    'message irc own_action' => \&sig_own
36};
37
38
39
40=comment
41
42    >> use Irssi 20011211 qw(signal_add command);
43
44    Loads the Irssi module, requiring at least version 20011211 and telling
45    it to export signal_add() and command() into our package.
46    This kind of version checking came available in the 20011208-snapshot.
47    Having te Irssi:: subs exported came available in the 20011211-snapshot.
48
49    >> sub sig_own
50
51    Warns the user: chatting while having windows switch all the time is
52    foolish, because your text gets sent to whatever window has the focus
53    when you press enter.
54
55    >> signal_add
56
57    This was exported into our package, so we can use signal_add() without the
58    "Irssi::" prefix. Since the 20011207 snapshot, you can add multiple signals
59    using a single add_signal(). If you want to do so, use a hash reference
60    (either { foo => bar, foo2 => bar2 } or \%hash).
61
62    >> sub { ... }
63    >> \&subname
64
65    These are references to subs(code). The first one is a reference to an
66    anonymous sub, the second one refers to a named one. Anonymous code
67    references allow for easy placement of oneliners :)
68    Irssi understands codereferences since the 20011207 snapshot.
69    Using references is better than having a string with the function name,
70    imho.
71
72=cut
73