Skip Menu |
 

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

People
Owner: Nobody in particular
Requestors: wilburlo [...] gmail.com
Cc:
AdminCc:

Bug Information
Severity: Important
Broken in: (no value)
Fixed in: (no value)



Subject: Documentation shows a bad example.
Download (untitled) / with headers
text/plain 562b
In the Path::Class::Dir documentation you have the following example (Last few lines in SYNOPSIS & $dir->next documentation) # Iterate with Path::Class methods: while (my $file = $dir->next) { # $file is a Path::Class::File or Path::Class::Dir object ... } If there is a directory named "0" (zero), then that will prematurely terminate the while loop, since $file will be 0. (which is false). There probably should be a $dir->eof() (or something else of that name) subroutine. while ( ! $dir->eof() ) { my $file = $dir->next(); } -daniel
Subject: children subroutine is also bugged.
Download (untitled) / with headers
text/plain 818b
Here is a test case that breaks the $dir->children() [11:52am]/home/daniel/t>cat go.pl use Path::Class; my $dir = Path::Class::dir('.'); print join ', ', $dir->children(); print "\n"; [11:52am]/home/daniel/t>ls -al total 6 drwxr-xr-x 2 daniel staff 512 Sep 14 11:51 . drwxr-xr-x 8 daniel staff 512 Sep 14 11:49 .. -rw-r--r-- 1 daniel staff 0 Sep 14 11:51 0 -rw-r--r-- 1 daniel staff 0 Sep 14 11:51 1 -rw-r--r-- 1 daniel staff 0 Sep 14 11:51 2 -rw-r--r-- 1 daniel staff 0 Sep 14 11:51 3 -rw-r--r-- 1 daniel staff 0 Sep 14 11:51 4 -rw-r--r-- 1 daniel staff 0 Sep 14 11:51 5 -rw-r--r-- 1 daniel staff 99 Sep 14 11:51 go.pl [11:52am]/home/daniel/t>perl go.pl ./go.pl, ./1, ./2, ./3 [11:52am]/home/daniel/t> files are created by touch 1 touch 2 touch 3 touch 0 touch 4 touch 5
From: KWILLIAMS [...] cpan.org
Download (untitled) / with headers
text/plain 100b
Actually $file won't be "0" it'll be "$dir/0" or the platform equivalent, which is non-false. -Ken
Download (untitled) / with headers
text/plain 483b
Ah, I see I am wrong in the case where a *directory* is called "0" and $dir is the current directory. I think this is an actual bug in the code, because it should be stringifying to "./0", not merely "0" to be consistent with files: [/tmp] % perl -MPath::Class -le '$dir=dir("."); while (my $file = $dir->next) { print $file }' . .. ./0 501 ./cs_cache_lock_92 hsperfdata_ken ./objc_sharing_ppc_26 ./objc_sharing_ppc_4294967294 ./objc_sharing_ppc_501 ./objc_sharing_ppc_92 -Ken
From: daniel_lo [...] picturetrail.com
Download (untitled) / with headers
text/plain 897b
I need to include test cases for my own thoughts :). The problem is in the while loop condition check, the return scalar value of the IO::Dir->read (readdir). The code exits before Path::Class has a chance to stringify it. The while loop receives a scalar value from $handle (IO::Dir), which in the case of a file or directory that is a name of "0" (zero) it evaluates to false and the loop is terminated. I've included a test case below: use Path::Class; use Path::Class::Dir; mkdir '1'; mkdir '0'; my $dir=dir('.'); my $handle = $dir->open; # while ( defined ( my $file = $handle->read ) ) { # this works. while ( my $file = $handle->read ) { # IO::Dir->read returns a scalar value print "1: ", $file, "\n"; $file = $dir->file($file); # Turn $file into Path::Class::File object print "2: ", $file, "\n"; print "\n"; } # clean up after ourself. rmdir '1'; rmdir '0';
Download (untitled) / with headers
text/plain 172b
Hi Daniel, This problem has been fixed for the next release, the idiom 'while($x = $dir->next) {...}' can now safely be used without risk of early termination. -Ken


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

Please report any issues with rt.cpan.org to rt-cpan-admin@bestpractical.com.