Skip Menu |

This queue is for tickets about the File-Temp CPAN distribution.

Report information
The Basics
Id: 47397
Status: resolved
Priority: 0/
Queue: File-Temp

People
Owner: Nobody in particular
Requestors: user42 [...] zip.com.au
Cc:
AdminCc:

Bug Information
Severity: Wishlist
Broken in: (no value)
Fixed in: (no value)



Subject: handle overloaded "==" and numify
Date: Sun, 28 Jun 2009 11:47:11 +1000
To: bug-File-Temp [...] rt.cpan.org
From: Kevin Ryde <user42 [...] zip.com.au>
With File::Temp 0.21 and recent debian i386 perl 5.10.0, the program foo.pl below gets a warning Argument "/tmp/0zfMwjrR4B" isn't numeric in numeric eq (==) at foo.pl line 9. where I hoped it would compare the two handles by refaddr or whatnot as usual for references. Attempting a numize "0+$fh1" gets a similar warning. I struck this with Perl6::Slurp. It tests $fh==\*ARGV to do something or other special on ARGV. If the $fh you supply is a File::Temp object it gets the warning above. Perhaps the overload fallbacks in File::Temp are falling back a bit too far, using stringize for numize too, or something.
use strict; use warnings; use File::Temp; print File::Temp->VERSION,"\n"; my $fh1 = File::Temp->new; my $fh2 = \*STDOUT; if ($fh1 == $fh2) { print "equal\n"; } else { print "not equal\n"; } exit 0;
File::Temp objects are overloaded to act as strings. If you need the reference address, use Scalar::Util::refaddr instead.
Subject: Re: [rt.cpan.org #47397] handle overloaded "==" and numify
Date: Sat, 09 Feb 2013 06:54:33 +1100
To: bug-File-Temp [...] rt.cpan.org
From: Kevin Ryde <user42 [...] zip.com.au>
"David Golden via RT" <bug-File-Temp@rt.cpan.org> writes: Show quoted text
> > If you need the > reference address, use Scalar::Util::refaddr instead.
But a numize $fh+0 should make a number. I don't know what sort of number, but for compatibility with ordinary handles it would be helpful if it was the refaddr. I don't know why overload.pm doesn't already do that. Too much in its fallback perhaps, as I mentioned.
Subject: Re: [rt.cpan.org #47397] handle overloaded "==" and numify
Date: Fri, 8 Feb 2013 15:16:55 -0500
To: bug-File-Temp [...] rt.cpan.org
From: David Golden <dagolden [...] cpan.org>
On Fri, Feb 8, 2013 at 2:54 PM, Kevin Ryde via RT <bug-File-Temp@rt.cpan.org> wrote: Show quoted text
> But a numize $fh+0 should make a number. > > I don't know what sort of number, but for compatibility with ordinary > handles it would be helpful if it was the refaddr. I don't know why > overload.pm doesn't already do that. Too much in its fallback perhaps, > as I mentioned.
I think that could be surprising, because then there's no correspondence between the string form and the number form and usually Perl lets people ignore the difference between numbers and strings. -- David Golden <dagolden@cpan.org> Take back your inbox! → http://www.bunchmail.com/ Twitter/IRC: @xdg
On Fri Feb 08 14:54:33 2013, user42@zip.com.au wrote: Show quoted text
> "David Golden via RT" <bug-File-Temp@rt.cpan.org> writes:
> > > > If you need the > > reference address, use Scalar::Util::refaddr instead.
> > But a numize $fh+0 should make a number. > > I don't know what sort of number, but for compatibility with ordinary > handles it would be helpful if it was the refaddr. I don't know why > overload.pm doesn't already do that. Too much in its fallback perhaps, > as I mentioned.
I'm not against it returning the refaddr in numeric context, especially if that lets a File::Temp object be used in more places that expect file handles. This is what an IO::File does and what an IO::Handle does so it is probably a bug that File::Temp doesn't do that given that it is meant to act like an IO::Handle when being used as a file handle. The intent is for File::Temp objects to act like file handles wherever possible except when they are needed as strings. I think I probably assumed that overloads higher up the class hierarchy would kick in. Stringifying to the file name is a feature. Can you come up with a quick patch?
Subject: Re: [rt.cpan.org #47397] handle overloaded "==" and numify
Date: Sat, 09 Feb 2013 08:51:29 +1100
To: bug-File-Temp [...] rt.cpan.org
From: Kevin Ryde <user42 [...] zip.com.au>
"TJENNESS via RT" <bug-File-Temp@rt.cpan.org> writes: Show quoted text
> > Stringifying to the file name is a feature.
Yes. For the numize I usually reckon it a bit doubtful if numizing doesn't make a number. Some objects might have no numize and so croak, but if it has a numize it should be a number :-). I think version.pm suffered for a while, making a non-number when numized for "alpha" version numbers, or some such. Show quoted text
> Can you come up with a quick patch?
Diff and expanded cmp.t below. Does the doc bit justify the behaviour reasonably? Mention that IO::File compares numerically this way too if you like.

Message body is not shown because sender requested not to inline it.

Message body is not shown because sender requested not to inline it.

Fixed in V0.23. Thanks for the patch.