Subject: | IO::File::WithPath vs object interface to File::Temp |
File::Temp provides in object-oriented interface access to filename of
temporary file, similar to how IO::File::WithPath provides access to
filename of opened file.
I wonder why IO::File::WithPath uses different API: the method returning
filename is called filename() in File::Temp, and path() in
IO::File::WithPath.
There is nice feature of File::Temp related to pathname of file, which
IO::File::WithPath doesn't support. OO interface of File::Temp make
File::Temp object stringify to filename; it would be nice to have the
same for IO::File::WithPath.
<code>
use overload '""' => "STRINGIFY", fallback => 1;
#...
sub STRINGIFY {
my $self = shift;
return $self->filename;
}
</code>
The code dealing with storing filename in an object itself is also
slightly different. IO::File::WithPath uses
<code>
# symboltable hack
${*$io}{+__PACKAGE__} = $path;
</code>
while File::Temp uses
<code>
# Store the filename in the scalar slot
${*$fh} = $path;
</code>