Skip Menu |

Preferred bug tracker

Please visit the preferred bug tracker to report your issue.

This queue is for tickets about the Path-Class CPAN distribution.

Maintainer(s)' notes

I prefer that bugs & patches are filed on GitHub rather than on RT: https://github.com/kenahoo/Path-Class/issues. Thanks.

Report information
The Basics
Id: 12069
Status: resolved
Priority: 0/
Queue: Path-Class

People
Owner: Nobody in particular
Requestors: smylers [...] cpan.org
Cc:
AdminCc:

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



Subject: Method for Distinguishing Files and Directories
The Path::Class::Dir doc has this in an example: while (my $file = $dir->next) { next unless -f $file; That's something I'm doing in a script, and the -f test irks me: $file already knows whether it's a file or a directory, yet I'm making Perl go to all the bother of looking on the filesystem again to find out. One way of avoiding the filesystem hit would be: next unless -f _; But that's just horrid! (And breaks encapsulation.) So what I'm actually doing is asking $file what it is: next unless $file->isa('Path::Class::File'); That works fine. But I was wondering whether having a Path::Class method explicitly returning the type would be good: next unless $file->type eq 'file'; That doesn't seem like much of a saving over checking with ->isa, but I think it's significantly more readable, and avoids giving the impression of being overly concerned with the internal representation. What do you think? I'd be happy to write the patch, docs, and tests for this (and my other recent requests) if you'd be willing to accept such features into the distribution. Cheers. Smylers
I actually thought I'd written an is_dir() method, but I looked and apparently I haven't. That's probably the way I'd like to go - there are all kinds of special variants of files, but being a directory is a pretty well-defined concept. Thanks for offering to write the patch - I think it should be an is_dir () method in Entity.pm that always returns false, which is overridden in Dir.pm to return true. Also, note that "-d $path" and "$path->is_dir" aren't the same thing - the former requires that the path exists, the latter is purely a question about the object spec. -Ken
Done, will be in the next release.