THRIFT-5050 Fix MemoryBuffer.pm to raise a proper exception if no data is available
Client: perl
Patch: Kengo Seki

This closes #1967
diff --git a/lib/perl/Makefile.PL b/lib/perl/Makefile.PL
index 5e60ab4..b72a23e 100644
--- a/lib/perl/Makefile.PL
+++ b/lib/perl/Makefile.PL
@@ -34,6 +34,9 @@
                    'Class::Accessor' => 0
                },
 #              SIGN => 1,
+               TEST_REQUIRES => {
+                   'Test::Exception' => 0,
+               },
                VERSION_FROM => 'lib/Thrift.pm' );
 
 # THRIFT-4691
diff --git a/lib/perl/README.md b/lib/perl/README.md
index bd1e5b2..6958510 100644
--- a/lib/perl/README.md
+++ b/lib/perl/README.md
@@ -61,6 +61,12 @@
   * Bit::Vector
   * Class::Accessor
 
+## Test
+
+This is only required when running tests:
+
+  * Test::Exception
+
 ### HttpClient Transport
 
 These are only required if using Thrift::HttpClient:
diff --git a/lib/perl/lib/Thrift/MemoryBuffer.pm b/lib/perl/lib/Thrift/MemoryBuffer.pm
index be97ce4..5192cfb 100644
--- a/lib/perl/lib/Thrift/MemoryBuffer.pm
+++ b/lib/perl/lib/Thrift/MemoryBuffer.pm
@@ -117,7 +117,7 @@
 
     my $avail = ($self->{wPos} - $self->{rPos});
     if ($avail < $len) {
-        die TTransportException->new("Attempt to readAll($len) found only $avail available",
+        die Thrift::TTransportException->new("Attempt to readAll($len) found only $avail available",
                                     Thrift::TTransportException::END_OF_FILE);
     }
 
diff --git a/lib/perl/t/memory_buffer.t b/lib/perl/t/memory_buffer.t
index 8fa9fd7..4a4ba0f 100644
--- a/lib/perl/t/memory_buffer.t
+++ b/lib/perl/t/memory_buffer.t
@@ -17,7 +17,8 @@
 # under the License.
 #
 
-use Test::More tests => 6;
+use Test::More tests => 7;
+use Test::Exception;
 
 use strict;
 use warnings;
@@ -33,6 +34,8 @@
 my $transport = Thrift::MemoryBuffer->new();
 my $protocol = Thrift::BinaryProtocol->new($transport);
 
+throws_ok { $protocol->readByte } 'Thrift::TTransportException';
+
 my $a = ThriftTest::Xtruct->new();
 $a->i32_thing(10);
 $a->i64_thing(30);