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

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

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



Subject: dir(__FILE__)->parent->parent->parent->parent->parent
better written as: dir(__FILE__)->parent(5) if the code is something like that: sub parent { my ($self, $repetitions) = @_; if ( $repetitions ) { for ( 0 .. $repetitions ) { $self = $self->parent; } return $self: } ... }
Sending the previous mail has failed. Please contact your admin, they can find more details in the logs.
Sending the previous mail has failed. Please contact your admin, they can find more details in the logs.
Subject: patch for repitition of parent, e.g. dir(__FILE__)->parent->parent->parent->parent->parent
# change your code sub parent { my $self = shift; my $dirs = $self->{dirs}; ... # into sub parent { my $self = shift; my $repetition = int abs( shift || 1 ); while (--$repitition) { $self->parent; } my $dirs = $self->{dirs}; ... # and then both works dir(__FILE__)->parent->parent->parent->parent->parent dir(__FILE__)->parent(5)
Seems like a reasonable idea. Would you be willing to write a patch that includes a test to put in t/01-basic.t , and something to add to the docs? -Ken
I added a 'multiparent' branch with the start of a patch.
added changed files: lib/Path/Class/Dir.pm 100c100 < my $self = shift; --- Show quoted text
> my $self = shift;
100a101,105 Show quoted text
> my $repetition = int( abs shift || 1 ); > > while (--$repetition) { > $self = $self->parent; > }
t/01-basic.t 10c10 < plan tests => 68; --- Show quoted text
> plan tests => 74;
63a64,69 Show quoted text
> ok $dir->parent(undef), '/foo/bar'; # undef stuff ignored > ok $dir->parent('foo'), '/foo/bar'; # text stuff ignored > ok $dir->parent(0), '/foo/bar'; # 0 stuff ignored > ok $dir->parent(1), '/foo/bar'; # 1 ignored > ok $dir->parent(2), '/foo'; > ok $dir->parent(-2.9), '/foo'; # sign and float stuff ignored, so no
endless while
Subject: 01-basic.t
BEGIN { $^O = 'Unix'; # Test in Unix mode } use Test; use strict; use Path::Class; use Cwd; plan tests => 74; ok(1); my $file1 = Path::Class::File->new('foo.txt'); ok $file1, 'foo.txt'; ok $file1->is_absolute, ''; ok $file1->dir, '.'; ok $file1->basename, 'foo.txt'; my $file2 = file('dir', 'bar.txt'); ok $file2, 'dir/bar.txt'; ok $file2->is_absolute, ''; ok $file2->dir, 'dir'; ok $file2->basename, 'bar.txt'; my $dir = dir('tmp'); ok $dir, 'tmp'; ok $dir->is_absolute, ''; ok $dir->basename, 'tmp'; my $dir2 = dir('/tmp'); ok $dir2, '/tmp'; ok $dir2->is_absolute, 1; my $cat = file($dir, 'foo'); ok $cat, 'tmp/foo'; $cat = $dir->file('foo'); ok $cat, 'tmp/foo'; ok $cat->dir, 'tmp'; ok $cat->basename, 'foo'; $cat = file($dir2, 'foo'); ok $cat, '/tmp/foo'; $cat = $dir2->file('foo'); ok $cat, '/tmp/foo'; ok $cat->isa('Path::Class::File'); ok $cat->dir, '/tmp'; $cat = $dir2->subdir('foo'); ok $cat, '/tmp/foo'; ok $cat->isa('Path::Class::Dir'); ok $cat->basename, 'foo'; my $file = file('/foo//baz/./foo')->cleanup; ok $file, '/foo/baz/foo'; ok $file->dir, '/foo/baz'; ok $file->parent, '/foo/baz'; { my $dir = dir('/foo/bar/baz'); ok $dir->parent, '/foo/bar'; ok $dir->parent->parent, '/foo'; ok $dir->parent->parent->parent, '/'; ok $dir->parent->parent->parent->parent, '/'; ok $dir->parent(undef), '/foo/bar'; # undef stuff ignored ok $dir->parent('foo'), '/foo/bar'; # text stuff ignored ok $dir->parent(0), '/foo/bar'; # 0 stuff ignored ok $dir->parent(1), '/foo/bar'; # 1 ignored ok $dir->parent(2), '/foo'; ok $dir->parent(-2.9), '/foo'; # sign and float stuff ignored, so no endless while $dir = dir('foo/bar/baz'); ok $dir->parent, 'foo/bar'; ok $dir->parent->parent, 'foo'; ok $dir->parent->parent->parent, '.'; ok $dir->parent->parent->parent->parent, '..'; ok $dir->parent->parent->parent->parent->parent, '../..'; } { my $dir = dir("foo/"); ok $dir, 'foo'; ok $dir->parent, '.'; } { # Special cases ok dir(''), '/'; ok dir(), '.'; ok dir('', 'var', 'tmp'), '/var/tmp'; ok dir()->absolute->resolve, dir(Cwd::cwd())->resolve; ok dir(undef), undef; } { my $file = file('/tmp/foo/bar.txt'); ok $file->relative('/tmp'), 'foo/bar.txt'; ok $file->relative('/tmp/foo'), 'bar.txt'; ok $file->relative('/tmp/'), 'foo/bar.txt'; ok $file->relative('/tmp/foo/'), 'bar.txt'; $file = file('one/two/three'); ok $file->relative('one'), 'two/three'; } { # Try out the dir_list() method my $dir = dir('one/two/three/four/five'); my @d = $dir->dir_list(); ok "@d", "one two three four five"; @d = $dir->dir_list(2); ok "@d", "three four five"; @d = $dir->dir_list(-2); ok "@d", "four five"; @d = $dir->dir_list(2, 2); ok "@d", "three four", "dir_list(2, 2)"; @d = $dir->dir_list(-3, 2); ok "@d", "three four", "dir_list(-3, 2)"; @d = $dir->dir_list(-3, -2); ok "@d", "three", "dir_list(-3, -2)"; @d = $dir->dir_list(-3, -1); ok "@d", "three four", "dir_list(-3, -1)"; my $d = $dir->dir_list(); ok $d, 5, "scalar dir_list()"; $d = $dir->dir_list(2); ok $d, "three", "scalar dir_list(2)"; $d = $dir->dir_list(-2); ok $d, "four", "scalar dir_list(-2)"; $d = $dir->dir_list(2, 2); ok $d, "four", "scalar dir_list(2, 2)"; } { # Test is_dir() ok dir('foo')->is_dir, 1; ok file('foo')->is_dir, 0; } { # subsumes() ok dir('foo/bar')->subsumes('foo/bar/baz'), 1; ok dir('/foo/bar')->subsumes('/foo/bar/baz'), 1; ok dir('foo/bar')->subsumes('bar/baz'), 0; ok dir('/foo/bar')->subsumes('foo/bar'), 0; ok dir('/foo/bar')->subsumes('/foo/baz'), 0; ok dir('/')->subsumes('/foo/bar'), 1; }
Subject: Dir.pm

Message body is not shown because it is too large.