Blob Blame History Raw
From 8fec0161383143419d4cc957e001b0b2fc9fa304 Mon Sep 17 00:00:00 2001
From: Iain Arnell <iarnell@gmail.com>
Date: Thu, 20 May 2010 19:22:35 +0200
Subject: [PATCH] apply fixes for rhbz#591215

cherry-picked 4f46c29376359b3d7c5b5cd400115103fdef9ca8
cherry-picked 675f55cd40ceebbc1bd2f309311a066bed41d869
cherry-picked 9e2a01af6a908f9c1c97431bcbc5f483a7a99e2f
---
 lib/POE/Component/IRC.pm   |   19 +++++++------------
 t/02_behavior/14_newline.t |   16 +++++++++-------
 xt/perlcriticrc_t          |    1 +
 3 files changed, 17 insertions(+), 19 deletions(-)

diff --git a/lib/POE/Component/IRC.pm b/lib/POE/Component/IRC.pm
index 4fe23da..ecaa50c 100644
--- a/lib/POE/Component/IRC.pm
+++ b/lib/POE/Component/IRC.pm
@@ -1038,9 +1038,7 @@ sub onlytwoargs {
 
 # Handler for privmsg or notice events.
 sub privandnotice {
-    my ($kernel, $state, $to) = @_[KERNEL, STATE, ARG0];
-    my $message = join ' ', @_[ARG1 .. $#_];
-    my @messages = split /\n/, $message;
+    my ($kernel, $state, $to, $msg) = @_[KERNEL, STATE, ARG0, ARG1];
     my $pri = $_[OBJECT]->{IRC_CMDS}->{$state}->[CMD_PRI];
 
     $state =~ s/privmsglo/privmsg/;
@@ -1048,7 +1046,7 @@ sub privandnotice {
     $state =~ s/noticelo/notice/;
     $state =~ s/noticehi/notice/;
 
-    if (!defined $to || !defined $message) {
+    if (!defined $to || !defined $msg) {
         warn "The '$state' event requires two arguments\n";
         return;
     }
@@ -1056,9 +1054,7 @@ sub privandnotice {
     $to = join ',', @$to if ref $to eq 'ARRAY';
     $state = uc $state;
 
-    for my $msg (@messages) {
-        $kernel->yield(sl_prioritized => $pri, "$state $to :$msg");
-    }
+    $kernel->yield(sl_prioritized => $pri, "$state $to :$msg");
     return;
 }
 
@@ -1214,14 +1210,14 @@ sub sl_prioritized {
 
     my $now = time();
     $self->{send_time} = $now if $self->{send_time} < $now;
+
+    # if we find a newline in the message, take that to be the end of it
+    $msg =~ s/[\015\012].*//s;
     
     if (bytes::length($msg) > $self->{msg_length} - bytes::length($self->nick_name())) {
         $msg = bytes::substr($msg, 0, $self->{msg_length} - bytes::length($self->nick_name()));
     }
 
-    # if we find a newline in the message, take that to be the end of it
-    $msg =~ s/\n.*//gm;
-    
     if (@{ $self->{send_queue} }) {
         my $i = @{ $self->{send_queue} };
         $i-- while ($i && $priority < $self->{send_queue}->[$i-1]->[MSG_PRI]);
@@ -2188,8 +2184,7 @@ it will be treated as a PART message and dealt with accordingly.
 Sends a public or private message to the nick(s) or channel(s) which
 you specify. Takes 2 arguments: the nick or channel to send a message
 to (use an array reference here to specify multiple recipients), and
-the text of the message to send. If the message contains newlines, it
-will be split up into multiple messages.
+the text of the message to send.
 
 Have a look at the constants in
 L<POE::Component::IRC::Common|POE::Component::IRC::Common> if you would
diff --git a/t/02_behavior/14_newline.t b/t/02_behavior/14_newline.t
index efad9f3..e59998d 100644
--- a/t/02_behavior/14_newline.t
+++ b/t/02_behavior/14_newline.t
@@ -3,16 +3,15 @@ use warnings;
 use lib 't/inc';
 use POE qw(Wheel::SocketFactory);
 use Socket;
-use POE::Component::IRC::State;
-use POE::Component::IRC::Plugin::AutoJoin;
+use POE::Component::IRC;
 use POE::Component::Server::IRC;
 use Test::More tests => 9;
 
-my $bot1 = POE::Component::IRC::State->spawn(
+my $bot1 = POE::Component::IRC->spawn(
     Flood        => 1,
     plugin_debug => 1,
 );
-my $bot2 = POE::Component::IRC::State->spawn(
+my $bot2 = POE::Component::IRC->spawn(
     Flood        => 1,
     plugin_debug => 1,
 );
@@ -89,7 +88,7 @@ sub irc_join {
     my ($sender, $heap, $who, $where) = @_[SENDER, HEAP, ARG0, ARG1];
     my $nick = ( split /!/, $who )[0];
     my $irc = $sender->get_heap();
-    
+
     return if $nick ne $irc->nick_name();
     is($where, '#testchannel', 'Joined Channel Test');
 
@@ -98,10 +97,13 @@ sub irc_join {
 
     $irc->yield(quote => "PRIVMSG $where :one\nPRIVMSG $where :two");
     $irc->yield(privmsg => $where, "foo\nbar");
+    $irc->yield(privmsg => $where, "baz\rquux");
 }
 
 sub irc_public {
-    my ($heap, $msg) = @_[HEAP, ARG2];
+    my ($sender, $heap, $where, $msg) = @_[SENDER, HEAP, ARG1, ARG2];
+    my $irc = $sender->get_heap();
+    my $chan = $where->[0];
 
     $heap->{got_msg}++;
     if ($heap->{got_msg} == 1) {
@@ -111,7 +113,7 @@ sub irc_public {
         is($msg, 'foo', 'Second message');
     }
     elsif ($heap->{got_msg} == 3) {
-        is($msg, 'bar', 'Third message');
+        is($msg, 'baz', 'Third message');
         $bot1->yield('quit');
         $bot2->yield('quit');
     }
diff --git a/xt/perlcriticrc_t b/xt/perlcriticrc_t
index 3bd1ed9..9b1b549 100644
--- a/xt/perlcriticrc_t
+++ b/xt/perlcriticrc_t
@@ -25,3 +25,4 @@ verbose  = 3
 [-Modules::RequireExplicitPackage]
 [-Modules::RequireFilenameMatchesPackage]
 [-Subroutines::RequireFinalReturn]
+[-ControlStructures::ProhibitCascadingIfElse]
-- 
1.7.0.1