develooper Front page | perl.perl5.porters | Postings from January 2010

5.11.3 or later: File handles are not tied to FileHandle anymore

Thread Next
From:
Tatsuhiko Miyagawa
Date:
January 30, 2010 01:35
Subject:
5.11.3 or later: File handles are not tied to FileHandle anymore
Message ID:
693254b91001300134j1d1d93c6m868fea0b3d1592ca@mail.gmail.com
Hi,

http://search.cpan.org/~rjbs/perl-5.11.4/pod/perl5113delta.pod#Incompatible_Changes
http://perl5.git.perl.org/perl.git/commitdiff/31c9a3ace4f559b7
Filehandles are blessed directly into IO::Handle, as FileHandle is
merely a wrapper around IO::Handle.

This breaks a lot of my code, notably Plack, that assumes plain file
handles are blessed into FileHandle. The problem is that FileHandle.pm
is not "merely" a wrapper around IO::Handle but it adds methods from
IO::Seekable: seek, tell, getpos, setpos. More background:
http://blog.woobling.org/2009/10/are-filehandles-objects.html

Here's a test script that reproduces the problem: passes with 5.8,
5.10 and 5.11.2 but fails with 5.11.3 and .4.

use strict;
use Test::More tests => 4;
use FileHandle;

my $str = "foo";
open my $fh, "<", \$str;
is <$fh>, "foo";

eval {
    $fh->seek(0, 0);
    is $fh->tell, 0;
    is <$fh>, "foo";
};

is $@, '';




-- 
Tatsuhiko Miyagawa

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About