Skip Menu |

This queue is for tickets about the IO-Moose CPAN distribution.

Report information
The Basics
Id: 42239
Status: rejected
Priority: 0/
Queue: IO-Moose

People
Owner: piotr.roszatycki [...] gmail.com
Requestors: perl [...] evancarroll.com
Cc:
AdminCc:

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



I'd like to see some state added to a IO::File object. something that permits you tell if the file existed when you opened it, and what its original name is. Here is an old subclass of IO::File that does it. I was thinking about subclasses IO::Moose::File and adding this, if you don't want to add to core. use strict; use warnings; use base 'IO::File'; use feature ':5.10'; my %data; sub previouslyCreated { $data{+shift}->{existed_when_opened} } sub originalLoc { $data{+shift}->{original_location} } sub new { my ( $class, @args ) = @_; my $exists = -e $args[0] ? 1 : 0; my $self = $class->SUPER::new( @args ); $data{$self} = { existed_when_opened => $exists , original_location => $args[0] }; $self; };
What is purpose of "original_location" attribute? I think it is the same attribute as "file". $io = IO::Moose::File->new( file => "/etc/passwd" ); print $io->file; # prints "/etc/passwd" I think that "existed_when_opened" attribute has meaning only for "w" mode, because the exception is thrown if file doesn't exist when opening with "r" mode. Even that, the stat()-ing file before open doesn't guarantee that file really existed or not before open. I mean following scenario: 1. The file exists. 2. First thread checks if file exists. 3. Second thread removes a file. 4. First thread opens the file. So first thread thinks that the file exists even if it was created a new. It is the reason that I don't want to implement broken feature in IO::Moose::File. If you want to have this feature, you can extends IO::Moose::File. I.e.: package IO::Moose::FileExists; use Moose; extends 'IO::Moose::File'; has 'existed_when_opened' => ( is => 'ro', isa => 'Bool' ); arround 'open' => sub { my $orig = shift; my $self = shift; my ($file) = @_; my $hashref = ${*$self}; $hashref->{existed_when_opened} = -e $file if not ref $file; $orig->(@_); };
Subject: Re: existed_when_opened attribute
This won't go to distribution but it is easy way to extends IO::Moose::File by your own. It would probably good idea to implement IO::Moose::Atomic or similar class which guarantee that file is or isn't exists before opening.