Skip to content
Browse files

Changed the connection to use the updated IO::Socket::INET I wrote. I…

…f the new module isnt accepted into rakudo I'll just add it to /lib.
  • Loading branch information...
1 parent b3d1d18 commit 49b8703350bf238f518b6611f47a24c99021e42f Jarrod committed Mar 14, 2011
Showing with 4 additions and 26 deletions.
  1. +4 −4 lib/Net/IRC/Bot.pm
  2. +0 −22 lib/Net/IRC/Connection.pm
View
8 lib/Net/IRC/Bot.pm
@@ -4,7 +4,7 @@ use Net::IRC::DefaultHandlers;
use Net::IRC::Event;
class Net::IRC::Bot {
- has $conn = Net::IRC::Connection.new();
+ has $conn is rw;
#Set some sensible defaults for the bot.
#These are not stored as state, they are just used for the bot's "start state"
@@ -48,8 +48,8 @@ class Net::IRC::Bot {
#Establish connection to server
self!resetstate;
say "Connecting to $server on port $port";
- my $r = $conn.open($server, $port)
- or die $r;
+ $conn = Net::IRC::Connection.new(peeraddr => $server, peerport => $port);
+
#Send PASS if needed
$conn.sendln("PASS $password") if $password;
@@ -103,7 +103,7 @@ class Net::IRC::Bot {
self!connect;
loop {
#XXX: Support for timed events?
- my $line = $conn.get
+ my $line = $conn.get.chomp
or die "Connection error.";
my $event = RawEvent.parse($line)
View
22 lib/Net/IRC/Connection.pm
@@ -2,29 +2,7 @@ use v6;
class Net::IRC::Connection is IO::Socket::INET {
#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) {
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.
Something went wrong with that request. Please try again.