line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# $Id: Object.pm,v 1.3 2002/07/02 14:36:39 matt Exp $ |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
package POE::Component::IRC::Object; |
4
|
1
|
|
|
1
|
|
6928
|
use strict; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
49
|
|
5
|
1
|
|
|
1
|
|
1516
|
use POE; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
use POE::Component::IRC; |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
use vars qw($VERSION $AUTOLOAD); |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
$VERSION = '0.02'; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub new { |
13
|
|
|
|
|
|
|
my $class = shift; |
14
|
|
|
|
|
|
|
die __PACKAGE__ . "->new() params must be a hash" if @_ % 2; |
15
|
|
|
|
|
|
|
my %params = @_; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
my $self = bless \%params, $class; |
18
|
|
|
|
|
|
|
$self->init(); |
19
|
|
|
|
|
|
|
return $self; |
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
my $id = 0; |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub init { |
25
|
|
|
|
|
|
|
my ($self) = @_; |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
my $name = sprintf("pocoirc_irc_%06d", ++$id); |
28
|
|
|
|
|
|
|
# warn("Creating IRC object $name\n"); |
29
|
|
|
|
|
|
|
$self->{__IRC} = $name; |
30
|
|
|
|
|
|
|
POE::Component::IRC->new($name); |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
POE::Session->create( |
33
|
|
|
|
|
|
|
object_states => [ |
34
|
|
|
|
|
|
|
$self => [ '_start', '_stop', '_default' ], |
35
|
|
|
|
|
|
|
], |
36
|
|
|
|
|
|
|
); |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
sub _start { |
40
|
|
|
|
|
|
|
my ($self, $kernel) = @_[OBJECT, KERNEL]; |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
# warn("_start - registering all\n"); |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
$kernel->post($self->{__IRC}, "register", "all"); |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
my $hash = {}; |
47
|
|
|
|
|
|
|
$hash->{Nick} = $self->{Nick} if $self->{Nick}; |
48
|
|
|
|
|
|
|
$hash->{Server} = $self->{Server} if $self->{Server}; |
49
|
|
|
|
|
|
|
$hash->{Port} = $self->{Port} if $self->{Port}; |
50
|
|
|
|
|
|
|
$hash->{Username} = $self->{Username} if $self->{Username}; |
51
|
|
|
|
|
|
|
$hash->{Ircname} = $self->{Ircname} if $self->{Ircname}; |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
$kernel->post($self->{__IRC}, "connect", $hash); |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
sub _stop { |
57
|
|
|
|
|
|
|
my ($self, $kernel) = @_[OBJECT, KERNEL]; |
58
|
|
|
|
|
|
|
# warn("stopping\n"); |
59
|
|
|
|
|
|
|
$self->{__Quitting} = 1; |
60
|
|
|
|
|
|
|
$kernel->post($self->{__IRC}, "quit"); |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
sub _default { |
64
|
|
|
|
|
|
|
my ($self, $kernel, $state, $args) = @_[OBJECT, KERNEL, ARG0, ARG1]; |
65
|
|
|
|
|
|
|
my @new_ = @_[ 1 .. (ARG0-1) ]; |
66
|
|
|
|
|
|
|
push @new_, @$args; |
67
|
|
|
|
|
|
|
$self->$state(@new_); |
68
|
|
|
|
|
|
|
return 0; |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
sub irc_socketerr { |
72
|
|
|
|
|
|
|
warn("irc_socket error: ", $_[ARG0], "\n"); |
73
|
|
|
|
|
|
|
warn("Perhaps your server name or port is incorrect, or your net access is down\n"); |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
sub AUTOLOAD { |
77
|
|
|
|
|
|
|
my $self = shift; |
78
|
|
|
|
|
|
|
my $method = $AUTOLOAD; |
79
|
|
|
|
|
|
|
$method =~ s/^.*://; |
80
|
|
|
|
|
|
|
$poe_kernel->post($self->{__IRC}, $method, @_); |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
sub irc_error { |
84
|
|
|
|
|
|
|
my ($self, $kernel, $server) = @_[OBJECT, KERNEL, ARG0]; |
85
|
|
|
|
|
|
|
$self->{__irc_connected} = 0; |
86
|
|
|
|
|
|
|
$kernel->yield('reconnect'); |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
sub reconnect { |
90
|
|
|
|
|
|
|
my ($self, $kernel, $heap) = @_[OBJECT, KERNEL, HEAP]; |
91
|
|
|
|
|
|
|
return if $heap->{__irc_connected}; |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
my $hash = {}; |
94
|
|
|
|
|
|
|
$hash->{Nick} = $self->{Nick} if $self->{Nick}; |
95
|
|
|
|
|
|
|
$hash->{Server} = $self->{Server} if $self->{Server}; |
96
|
|
|
|
|
|
|
$hash->{Port} = $self->{Port} if $self->{Port}; |
97
|
|
|
|
|
|
|
$hash->{Username} = $self->{Username} if $self->{Username}; |
98
|
|
|
|
|
|
|
$hash->{Ircname} = $self->{Ircname} if $self->{Ircname}; |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
$kernel->post($self->{__IRC}, "connect", $hash); |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
# try again in 2 seconds (may have succeeded, but we test that at the top |
103
|
|
|
|
|
|
|
$kernel->delay_set( 'reconnect', 2 ); |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
sub irc_connected { |
107
|
|
|
|
|
|
|
$_[OBJECT]->{__irc_connected} = 1; |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
1; |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
__END__ |