Subject: | [PATCH] handle() untested + calling seek() as a method on result |
handle() appears to have no tests.
Also, calling the seek() method on the result of handle() causes a method not found error.
Attached, three patches appliable with git am:
0001-test-the-handle-method.patch
- basic tests for handle()
0002-TODO-test-for-calling-the-seek-method-on-handle-s-re.patch
- a TODO test for calling seek() on the result of handle()
0003-make-the-result-of-handle-an-IO-File-instead-of-IO-H.patch
- fix handle() to retutn an IO::File object
If preferred, I can open github pull requests instead.
Tony
Subject: | 0002-TODO-test-for-calling-the-seek-method-on-handle-s-re.patch |
From 638d03b36e5769508a74ed32cea2d6f95d1d5dcc Mon Sep 17 00:00:00 2001
From: Tony Cook <tony@develop-help.com>
Date: Mon, 6 May 2013 10:27:49 +1000
Subject: [PATCH 2/3] TODO test for calling the seek method on handle()'s
result
---
t/upload.t | 3 +++
1 file changed, 3 insertions(+)
diff --git a/t/upload.t b/t/upload.t
index e6c22f9..4c43457 100644
--- a/t/upload.t
+++ b/t/upload.t
@@ -129,6 +129,9 @@ ok( defined $q->upload('300x300_gif') , 'upload_basic_4' );
# check it acts like a handle
seek($rawhandle, 0, 2);
is(tell($rawhandle), 1656, "check it acts like a handle");
+
+ local $TODO = "the handle points at a file it should have file methods";
+ ok(eval { $rawhandle->seek(0, 2); 1 }, "can call seek() on handle result");
}
my $q2 = CGI->new;
--
1.7.10.4
Subject: | 0003-make-the-result-of-handle-an-IO-File-instead-of-IO-H.patch |
From e099bc127502e8544445c46ccb4bb02fb1a0cd3a Mon Sep 17 00:00:00 2001
From: Tony Cook <tony@develop-help.com>
Date: Mon, 6 May 2013 10:29:07 +1000
Subject: [PATCH 3/3] make the result of handle() an IO::File instead of
IO::Handle
---
lib/CGI.pm | 4 ++--
t/upload.t | 2 --
2 files changed, 2 insertions(+), 4 deletions(-)
diff --git a/lib/CGI.pm b/lib/CGI.pm
index df63490..20c7cfb 100644
--- a/lib/CGI.pm
+++ b/lib/CGI.pm
@@ -3894,8 +3894,8 @@ END_OF_FUNC
'handle' => <<'END_OF_FUNC',
sub handle {
my $self = shift;
- eval "require IO::Handle" unless IO::Handle->can('new_from_fd');
- return IO::Handle->new_from_fd(fileno $self,"<");
+ eval "require IO::File" unless IO::Handle->can('new_from_fd');
+ return IO::File->new_from_fd(fileno $self,"<");
}
END_OF_FUNC
diff --git a/t/upload.t b/t/upload.t
index 4c43457..31f7664 100644
--- a/t/upload.t
+++ b/t/upload.t
@@ -129,8 +129,6 @@ ok( defined $q->upload('300x300_gif') , 'upload_basic_4' );
# check it acts like a handle
seek($rawhandle, 0, 2);
is(tell($rawhandle), 1656, "check it acts like a handle");
-
- local $TODO = "the handle points at a file it should have file methods";
ok(eval { $rawhandle->seek(0, 2); 1 }, "can call seek() on handle result");
}
--
1.7.10.4
Subject: | 0001-test-the-handle-method.patch |
From 74c703894960af45abf3f4ed11e1ac8f5169cd21 Mon Sep 17 00:00:00 2001
From: Tony Cook <tony@develop-help.com>
Date: Mon, 6 May 2013 10:26:44 +1000
Subject: [PATCH 1/3] test the handle method
---
t/upload.t | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/t/upload.t b/t/upload.t
index 8be37db..e6c22f9 100644
--- a/t/upload.t
+++ b/t/upload.t
@@ -121,6 +121,16 @@ ok( defined $q->upload('300x300_gif') , 'upload_basic_4' );
is(tell($fh1), 1656, $test);
}
+{ # test handle() method
+ my $fh1 = $q->upload("300x300_gif");
+ my $rawhandle = $fh1->handle;
+ ok($rawhandle, "check handle()");
+ isnt($rawhandle, "300x300_gif", "no string overload");
+ # check it acts like a handle
+ seek($rawhandle, 0, 2);
+ is(tell($rawhandle), 1656, "check it acts like a handle");
+}
+
my $q2 = CGI->new;
{
--
1.7.10.4