Skip to content

Commit

Permalink
Changed the connection to use the updated IO::Socket::INET I wrote. I…
Browse files Browse the repository at this point in the history
…f the new module isnt accepted into rakudo I'll just add it to /lib.
  • Loading branch information
Jarrod committed Mar 14, 2011
1 parent b3d1d18 commit 49b8703
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 26 deletions.
8 changes: 4 additions & 4 deletions lib/Net/IRC/Bot.pm
Expand Up @@ -4,7 +4,7 @@ use Net::IRC::DefaultHandlers;
use Net::IRC::Event; use Net::IRC::Event;


class Net::IRC::Bot { class Net::IRC::Bot {
has $conn = Net::IRC::Connection.new(); has $conn is rw;


#Set some sensible defaults for the bot. #Set some sensible defaults for the bot.
#These are not stored as state, they are just used for the bot's "start state" #These are not stored as state, they are just used for the bot's "start state"
Expand Down Expand Up @@ -48,8 +48,8 @@ class Net::IRC::Bot {
#Establish connection to server #Establish connection to server
self!resetstate; self!resetstate;
say "Connecting to $server on port $port"; say "Connecting to $server on port $port";
my $r = $conn.open($server, $port) $conn = Net::IRC::Connection.new(peeraddr => $server, peerport => $port);
or die $r;
#Send PASS if needed #Send PASS if needed
$conn.sendln("PASS $password") if $password; $conn.sendln("PASS $password") if $password;


Expand Down Expand Up @@ -103,7 +103,7 @@ class Net::IRC::Bot {
self!connect; self!connect;
loop { loop {
#XXX: Support for timed events? #XXX: Support for timed events?
my $line = $conn.get my $line = $conn.get.chomp
or die "Connection error."; or die "Connection error.";


my $event = RawEvent.parse($line) my $event = RawEvent.parse($line)
Expand Down
22 changes: 0 additions & 22 deletions lib/Net/IRC/Connection.pm
Expand Up @@ -2,29 +2,7 @@ use v6;


class Net::IRC::Connection is IO::Socket::INET { class Net::IRC::Connection is IO::Socket::INET {
#State variables. #State variables.
has Bool $connected = False;

#Perl IO uses 'get' for getting a single line..
has Str $buf = "";
method get {
loop {
my ($line, $tail) = $buf.split("\c13\c10", 2);
if defined $tail {
$buf := $tail;
#Fix for Buf returning strings with broken encoding.
return $line.encode('UTF-8').decode('UTF-8');
}

$buf ~= $.recvp;
}
}

method sendln(Str $string) { method sendln(Str $string) {
self.send($string~"\c13\c10"); self.send($string~"\c13\c10");
} }

method recvp () {
die("Not connected!") unless $!PIO;
return $!PIO.recv();
}
} }

0 comments on commit 49b8703

Please sign in to comment.