[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index][Thread Index][Top&Search][Original]

Re: [perl #32135] File::Copy module



On Fri, Jan 26, 2007 at 12:56:18PM -0200, Adriano Ferreira wrote:

> Unlike the requestor thought, the problem is not triggered because
> IO::Scalar is a tied string, but because IO::Scalar is a package which
> provides an overloading for stringification. (IO::Scalar does some
> tricky things with overloading and ties at the same time, but the
> issue here is due to stringification.)
> 
> The problem can be demonstrated with:
> 
> $ perl -e 'package foo; use overload q{""} => sub { "x" };
>   package main;
>   $foo = bless {}, "foo";
>   print ($foo eq "a")'
> Operation "eq": no method found,
>        left argument in overloaded package foo,
>        right argument has no overloaded magic at -e line 2.
> 
> The problem with the offending code
> 
> >File/Copy.pm:76 (version 2.07)
> >
> >     if ($from eq $to) { # works for references, too
> >        croak("'$from' and '$to' are identical (not copied)");
> >     }
> 
> is that it tries to be too clever with a short expression to test

No, it's not being too clever. Anything here should be able to compare with
eq without croaking.

> equality both for filenames as well as references. And it works as
> long as the blessed references doesn't overload stringification, when
> Perl tries to determine an overload for 'eq'.

That means that the reference is semantically broken. If it wants to play at
being a string, by providing stringification overloading, then it needs to
play fully at being a string, by providing all the string overloading
operators.

File::Copy is documented as taking a file handle, or a file name. The latter
is a string. If it's being passed something that is a half-baked string, then
it's the fault of the half-baking, not the string.

The more I look at this, the more I think that we're piling hack on hack to
work round a bug in IO::Scalar, and that the bug should be fixed *there*.

(Although arguably the IO::Scalar bug would also be side-stepped by comparing
files after feeding them to File::Spec->canonpath())

Nicholas Clark


[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index][Thread Index][Top&Search][Original]