Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make visit() only react to SCALAR refs #135

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/Path/Tiny.pm
Expand Up @@ -1726,7 +1726,7 @@ sub visit {
while ( my $file = $next->() ) {
local $_ = $file;
my $r = $cb->( $file, $state );
last if ref($r) && !$$r;
last if ref($r) eq 'SCALAR' && !$$r;
}
return $state;
}
Expand Down
22 changes: 22 additions & 0 deletions t/visit.t
@@ -0,0 +1,22 @@
use strict;
use warnings;

use Test::More tests => 3;

use Path::Tiny;

path('t')->visit(sub{ return [ ] });

pass "visit callback doesn't choke on random returned refs";

my $all;
my $terminated;

path('t')->visit(sub{ $all++ });

path('t')->visit(sub{ $terminated++; return \0 if $terminated == 10 });

is $terminated => 10, "terminated before the whole dir was read";

cmp_ok $all, '>=', $terminated, "we have more than 10 tests in that dir";