| 1 | # -*- Mode: Perl; indent-tabs-mode: nil -*- | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | package Bot::ICB; | ||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use Net::ICB qw/:client/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | { | ||||||||||||||||||||||||||||
| 9 | 1 | ▶ | no strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 1 | $VERSION = 0.12; | |||||||||||||||||||||||||||
| 11 | } | ||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | sub newconn | ||||||||||||||||||||||||||||
| 14 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
newconn: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 15 | 0 | my $pkg = shift; | |||||||||||||||||||||||||||
| 16 | 0 | ▶ | my $class = ref($pkg) || $pkg; | ||||||||||||||||||||||||||
|
Condition0%0/3
ref $pkg || $pkg
MC/DC0%0/2
ref $pkg || $pkg
ref $pkg
$pkg
Truth table0%0/3
A || B
A= ref $pkgB= $pkg
| |||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 0 | my $self = bless {}, $class; | |||||||||||||||||||||||||||
| 19 | 0 | $self->conn(new Net::ICB()); | |||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | 0 | ▶ | $self->login(@_) if @_; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | 0 | return $self; | |||||||||||||||||||||||||||
| 24 | } | ||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | sub conn | ||||||||||||||||||||||||||||
| 27 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
conn: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 28 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | 0 | ▶ | $self->{conn} = shift if @_; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | 0 | return $self->{conn}; | |||||||||||||||||||||||||||
| 33 | } | ||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | sub handler | ||||||||||||||||||||||||||||
| 36 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
handler: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 37 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 38 | 0 | my ($name) = @_; | |||||||||||||||||||||||||||
| 39 | 0 | ▶ | $name or | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 40 | return undef; | ||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | $self->{handlers} or | ||||||||||||||||||||||||||||
| 43 | 0 | ▶ | return undef; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | 0 | return $self->{handlers}->{$name}; | |||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | sub login | ||||||||||||||||||||||||||||
| 49 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
login: not called CC=7 SCAR=40.3
Pod
undocumented
| |||||||||||||||||||||||||||||
| 50 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 51 | 0 | my %args = @_; | |||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | 0 | my $c = $self->conn; | |||||||||||||||||||||||||||
| 54 | 0 | ▶ | $c->connect(%args) or | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 55 | die $c->error; | ||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | 0 | my $type = ""; | |||||||||||||||||||||||||||
| 58 | 0 | my $err = ""; | |||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | 0 | ($type, $err) = $c->readmsg; | |||||||||||||||||||||||||||
| 61 | 0 | ▶ | $type eq $M_ERROR and | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 62 | die "Server error when receiving protocol packet: $err\n"; | ||||||||||||||||||||||||||||
| 63 | 0 | ▶ | $type eq $M_PROTO or | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 64 | die "Expected protocol packet [$M_PROTO] but received [$type]\n"; | ||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | 0 | ($type, $err) = $c->readmsg; | |||||||||||||||||||||||||||
| 67 | 0 | ▶ | $type eq $M_ERROR and | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 68 | die "Server error when receiving loginok packet: $err\n"; | ||||||||||||||||||||||||||||
| 69 | 0 | ▶ | $type eq $M_LOGINOK or | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 70 | die "Expected loginok packet [$M_LOGINOK] but received [$type]\n"; | ||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | 0 | my $handler = $self->handler('connect'); | |||||||||||||||||||||||||||
| 73 | 0 | ▶ | &$handler($self) if $handler; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | 0 | return 1; | |||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | sub add_handler | ||||||||||||||||||||||||||||
| 79 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
add_handler: not called CC=8 SCAR=42.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 80 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 81 | 0 | my ($name, $handler) = @_; | |||||||||||||||||||||||||||
| 82 | 0 | ▶ | $name && $handler or | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$name and $handler
MC/DC0%0/2
$name and $handler
$name
$handler
Truth table0%0/3
A and B
A= $nameB= $handler
| |||||||||||||||||||||||||||||
| 83 | return undef; | ||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | 0 | ▶ | $self->{handlers} = {} unless $self->{handlers}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | 0 | ▶ | $name = $M_OPEN if $name eq 'public'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 88 | 0 | ▶ | $name = $M_PERSONAL if $name eq 'msg'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 89 | 0 | ▶ | $name = $M_STATUS if $name eq 'status'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 90 | 0 | ▶ | $name = $M_EXIT if $name eq 'exit'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | 0 | $self->{handlers}->{$name} = $handler; | |||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | 0 | return 1; | |||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | sub start | ||||||||||||||||||||||||||||
| 98 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
start: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 99 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | 0 | my $type = ""; | |||||||||||||||||||||||||||
| 102 | 0 | my $event = ""; | |||||||||||||||||||||||||||
| 103 | 0 | my @msg; | |||||||||||||||||||||||||||
| 104 | my $handler; | ||||||||||||||||||||||||||||
| 105 | 0 | my $str; | |||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | 0 | while (1) | |||||||||||||||||||||||||||
| 108 | { | ||||||||||||||||||||||||||||
| 109 | 0 | ▶ | if (! $self->conn) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 110 | { | ||||||||||||||||||||||||||||
| 111 | 0 | $handler = $self->handler($M_EXIT); | |||||||||||||||||||||||||||
| 112 | 0 | ▶ | &$handler($self) if $handler; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 113 | 0 | exit; | |||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||
| 116 | 0 | ($type, $event, @msg) = $self->readmsg; | |||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||
| 118 | 0 | for $str ($type, $event, 'default') | |||||||||||||||||||||||||||
| 119 | { | ||||||||||||||||||||||||||||
| 120 | 0 | $handler = $self->handler(lc $str); | |||||||||||||||||||||||||||
| 121 | 0 | ▶ | &$handler($self, $event, @msg) if $handler; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 122 | } | ||||||||||||||||||||||||||||
| 123 | } | ||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||
| 125 | 0 | return 1; | |||||||||||||||||||||||||||
| 126 | } | ||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||
| 128 | sub disconnect | ||||||||||||||||||||||||||||
| 129 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
disconnect: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 130 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||
| 132 | 0 | $self->conn(undef); | |||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||
| 134 | 0 | return 1; | |||||||||||||||||||||||||||
| 135 | } | ||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||
| 137 | sub debug | ||||||||||||||||||||||||||||
| 138 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
debug: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 139 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 140 | 0 | return $self->conn->debug(@_); | |||||||||||||||||||||||||||
| 141 | } | ||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||
| 143 | sub error | ||||||||||||||||||||||||||||
| 144 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
error: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 145 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 146 | 0 | return $self->conn->error(@_); | |||||||||||||||||||||||||||
| 147 | } | ||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||
| 149 | sub readmsg | ||||||||||||||||||||||||||||
| 150 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
readmsg: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 151 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 152 | 0 | return $self->conn->readmsg(@_); | |||||||||||||||||||||||||||
| 153 | } | ||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||
| 155 | sub sendopen | ||||||||||||||||||||||||||||
| 156 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
sendopen: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 157 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 158 | 0 | return $self->conn->sendopen(@_); | |||||||||||||||||||||||||||
| 159 | } | ||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||
| 161 | sub sendpriv | ||||||||||||||||||||||||||||
| 162 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
sendpriv: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 163 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 164 | 0 | return $self->conn->sendpriv(@_); | |||||||||||||||||||||||||||
| 165 | } | ||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||
| 167 | sub sendraw | ||||||||||||||||||||||||||||
| 168 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
sendraw: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 169 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 170 | 0 | return $self->conn->sendraw(@_); | |||||||||||||||||||||||||||
| 171 | } | ||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||
| 173 | sub sendcmd | ||||||||||||||||||||||||||||
| 174 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
sendcmd: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 175 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 176 | 0 | return $self->conn->sendcmd(@_); | |||||||||||||||||||||||||||
| 177 | } | ||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||
| 179 | 1 | 1; | |||||||||||||||||||||||||||
| 180 | __END__ | ||||||||||||||||||||||||||||