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: 12768
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.10
Fixed in: (no value)



Subject: dir_list in Scalar Context
It's me again. The docs don't define what dir_list does in scalar context, which is to return the number of items that would have been returned in the list in list context. I'm trying to determine whether a file is in a CVS attic, that is whether its parent dir is called 'Attic'. I first tried this: if $file->parent->dir_list(-1) eq 'Attic' That doesn't work, because dir_list returns the integer 1, indicating that there would be one item in the list -- something that I know, since I asked for exactly one item! So I'm having to write it like this: if ($file->parent->dir_list(-1))[0] eq 'Attic' And that kind-of defeats one of the purposes of dir_list if the result has to be subscripted again. The above is of course the same as: if ($file->parent->dir_list)[-1] eq 'Attic' which gets rid of one of the subscripts, but it seems a waste to have a feature for doing this but not use it! Personally I'd prefer it if both wantarray tests were removed from dir_list and the list returned in all circumstances; I can't think of a situation where the list length would be useful to me, but grabbing just one element like this is something I'd want. This means that if a user asks for multiple elements in scalar context they only get one of them, but it's quite Perl-ish not to object if a user asks for something stupid. Since the current behaviour isn't documented, nobody should be relying on it (because if they were, surely they'd've sent you a doc patch ...). (Alternatively, if you judge that the current behaviour is useful to have then it should be documented so that anybody wanting this can rely on it!) Best wishes. Smylers
Good points. So should it just return the last element of the list in scalar context? That's an easy rule to remember. -Ken
Sounds good. I think I'll still keep the numerical behavior when no arguments are provided, since it seems more useful to be able to say "if ($d->dir_list > 3) ..." than to have to do some fancy foolery to figure out the number of directories. -Ken
One case that would be pretty non-intuitive using your proposed scheme: $d->dir_list(2) should probably return element 2 in scalar context, not the final element. I think I'll implement it that way. -Ken
Yup - I released version 0.11 with these changes last night. Thanks for the suggestions. -Ken