in reply to RFC:: FileSystemObjects::File
Quick-off, $f->stat() doesn't work because it ends up calling itself. Also, in stath you're checking for file existence after the call to stat, which seems wrong.
Update: Oops, diffed the wrong way around, corrected:
--- FileSystemObjects/File-orig.pm 2006-01-19 12:50:28.000000000 ++0100 +++ FileSystemObjects/File.pm 2006-01-19 13:29:06.000000000 +0100 @@ -60,17 +60,18 @@ croak "Can't stat a non existant file" unless -e $self->full_path +; - return &stat($self->full_path); + return CORE::stat($self->full_path); } #documented: synopsis sub stath { my $self = shift; - my @stat = &stat($self->full_path); croak "Can't stat a non existant file" unless -e $self->full_path +; + my @stat = CORE::stat($self->full_path); + return map { $stat_names[$_] => $stat[$_] } (0..12); }
Update:And actually I'd make $f->stath call $self->stat() to avoid code duplication (little as it may be), so:
--- FileSystemObjects/File-orig.pm 2006-01-19 12:50:28.000000000 ++0100 +++ FileSystemObjects/File.pm 2006-01-19 13:30:03.000000000 +0100 @@ -60,16 +60,15 @@ croak "Can't stat a non existant file" unless -e $self->full_path +; - return &stat($self->full_path); + return CORE::stat($self->full_path); } #documented: synopsis sub stath { my $self = shift; - my @stat = &stat($self->full_path); - croak "Can't stat a non existant file" unless -e $self->full_path +; + my @stat = $self->stat(); return map { $stat_names[$_] => $stat[$_] } (0..12); }
Update: Your open method always returns true, so there's no good way to test for an error here. I'd prefer for the module to throw an exception at this point (which is almost always what you want), but that's just me and may be considered too unperlish. Anyway, it should at least return false.
Also, in the spirit of DWIMMERY maybe accept clear-text versions of the open mode ("append","write") as well as the traditional ">".
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: RFC:: FileSystemObjects::File
by holli (Abbot) on Jan 19, 2006 at 14:09 UTC |