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: 12052
Status: resolved
Priority: 0/
Queue: Path-Class

People
Owner: Nobody in particular
Requestors:
Cc:
AdminCc:

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



Subject: Access to Path as List
Hello there. Thank you so much for Path::Class; it is wonderful to work with, and I wish I'd discovered it sooner. I've got a feature request: I'd like a method that returns the path as a list of separate path elements. How this would currently help me is explained below, though it'd be a sufficiently general feature that may well have other uses. I'm a little hesitant about it though, cos I'm not sure what the best way of dealing with volumes or absolute paths is -- they don't matter in my particular case, and I'd be happy for a method that simply returns a list of the path components that do exist, and which leaves it up to me to know whether it's an absolute or relative path and whether a volume is needed. What I'm doing is transplanting a little subdirectory tree from one place to another: given a directory $dir (say /srv/3/www/k/e/ken) and a new base $base (say /home/smylers/dev/users) I'd like to form a new path by sticking the 3 right-most components of $dir on to $base (giving /home/smylers/dev/users/k/e/ken). This can be achieved at the moment with: my $new_path = dir $base, $dir->relative($dir->parent->parent->parent); By breaking encapsulation it can also be done with: my $new_path = dir $base, @{$dir->{dirs}}[-3 .. -1]; The general approach of the latter seems preferable to me -- in particular, the number of levels being transplanted is specified as a constant, 3 (which could easily be changed or replaced by a variable) rather than by having that number of chained method calls (which is more tedious to change and would require a loop if a variable were used). But obviously I don't like breaking encapsulation, hence my desire for a documented method call to get this information as a list. Does that make sense? Let me know if I can be any help. Smylers
Subject: Re: Access to Path as List
From: Smylers <smylers [...] cpan.org>
Ooops, I forgot to put my e-mail address in the form. Sorry about that. Perhaps adding this follow-up will provide it, but if not it's: smylers@cpan.org Cheers. Smylers
Hi Smylers, How about if I add a method that lets you take arbitrary slices of the directory list? Something like this: @slice = $path->dir_list(); # all dirs @slice = $path->dir_list(0, 3); # first 3 dirs @slice = $path->dir_list(-3); # last 3 dirs The argument semantics would be identical to using the OFFSET and LENGTH arguments to splice() or substr(). That would fill the bill, right? -Ken
This is now implemented, it'll be in the next release.