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