Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Mimic readdir's context-sensitivity

CORE::readdir is context-sensitive: in list context, it returns
all the files, which we emulated with utf8 goodness. But in
scalar context, it returns the next file, rather than the number
of files. Mimic this behaviour in utf8::all's wrapper function.

Thanks for Leon Timmermans for catching this omission.

Fixes GH #11
  • Loading branch information...
commit ba5ad7eafe03078a90a823cedd9902c8a9d92603 1 parent e3de34f
@doherty authored
Showing with 43 additions and 16 deletions.
  1. +10 −3 lib/utf8/all.pm
  2. +33 −13 t/readdir.t
View
13 lib/utf8/all.pm
@@ -73,9 +73,16 @@ sub _encode_argv {
sub _utf8_readdir(*) { ## no critic (Subroutines::ProhibitSubroutinePrototypes)
my $handle = shift;
- my @files = readdir($handle);
- $_ = Encode::decode('UTF-8', $_) for @files;
- return @files;
+ if (wantarray) {
+ my @all_files = CORE::readdir($handle);
+ $_ = Encode::decode('UTF-8', $_) for @all_files;
+ return @all_files;
+ }
+ else {
+ my $next_file = CORE::readdir($handle);
+ $next_file = Encode::decode('UTF-8', $next_file);
+ return $next_file;
+ }
}
=head1 INTERACTION WITH AUTODIE
View
46 t/readdir.t
@@ -1,19 +1,39 @@
use strict;
use warnings;
-use Test::More tests => 3;
+use Test::More 0.96 tests => 2;
-opendir my $dh, 'corpus'
- or die "Couldn't open directory 'corpus'";
+subtest utf8 => sub {
+ plan tests => 3;
+
+ opendir my $dh, 'corpus'
+ or die "Couldn't open directory 'corpus'";
+
+ my @files = grep { $_ ne '.' and $_ ne '..' } readdir $dh;
+ my @utf8_files;
+ {
+ rewinddir $dh;
+ use utf8::all;
+ @utf8_files = grep { $_ ne '.' and $_ ne '..' } readdir $dh;
+ }
+ closedir $dh;
+
+ is_deeply \@utf8_files, ["\x{307f}\x{304b}\x{3061}\x{3083}\x{3093}", "testfile"];
+ isnt $files[0] => $utf8_files[0];
+ is $files[1] => $utf8_files[1];
+};
+
+subtest context => sub {
+ plan tests => 1;
+
+ opendir my $dh, 'corpus'
+ or die "Couldn't open directory 'corpus'";
-my @files = grep { $_ ne '.' and $_ ne '..' } readdir $dh;
-my @utf8_files;
-{
- rewinddir $dh;
use utf8::all;
- @utf8_files = grep { $_ ne '.' and $_ ne '..' } readdir $dh;
-}
-closedir $dh;
+ my $core = CORE::readdir $dh;
+ rewinddir $dh;
+ my $utf8 = readdir $dh;
+ rewinddir $dh;
-is_deeply \@utf8_files, ["\x{307f}\x{304b}\x{3061}\x{3083}\x{3093}", "testfile"];
-isnt $files[0] => $utf8_files[0];
-is $files[1] => $utf8_files[1];
+ is $utf8 => $core;
+ closedir $dh;
+};
Please sign in to comment.
Something went wrong with that request. Please try again.