7 unless (find PerlIO::Layer 'perlio') {
8 print "1..0 # Skip: not perlio\n";
11 if (exists $ENV{PERLIO} && $ENV{PERLIO} !~ /^(stdio|perlio|mmap)$/) {
12 print "1..0 # PERLIO='$ENV{PERLIO}' unknown\n";
21 my $NONSTDIO = exists $ENV{PERLIO} && $ENV{PERLIO} ne 'stdio';
24 skip("This perl does not have Encode", 43)
25 unless " $Config{extensions} " =~ / Encode /;
28 my ($result, $expected, $id) = @_;
29 my $n = scalar @$expected;
30 is($n, scalar @$expected, "$id - layers = $n");
32 # Get rid of "unix" and similar OS-specific low lever layer.
34 # Change expectations.
35 $expected->[0] = $ENV{PERLIO} if $expected->[0] eq "stdio";
37 for (my $i = 0; $i < $n; $i++) {
38 my $j = $expected->[$i];
39 if (ref $j eq 'CODE') {
40 ok($j->($result->[$i]), "$id - $i is ok");
43 sprintf("$id - $i is %s",
44 defined $j ? $j : "undef"));
49 check([ PerlIO::get_layers(STDIN) ],
53 open(F, ">:crlf", "afile");
55 check([ PerlIO::get_layers(F) ],
59 binmode(F, ":encoding(sjis)"); # "sjis" will be canonized to "shiftjis"
61 check([ PerlIO::get_layers(F) ],
62 [ qw[stdio crlf encoding(shiftjis) utf8] ],
67 check([ PerlIO::get_layers(F) ],
73 check([ PerlIO::get_layers(F) ],
79 check([ PerlIO::get_layers(F) ],
85 check([ PerlIO::get_layers(F) ],
89 binmode(F, ":encoding(utf8)");
91 check([ PerlIO::get_layers(F) ],
92 [ qw[stdio encoding(utf8) utf8] ],
95 binmode(F, ":raw :crlf");
97 check([ PerlIO::get_layers(F) ],
101 binmode(F, ":raw :encoding(latin1)"); # "latin1" will be canonized
104 my @results = PerlIO::get_layers(F, details => 1);
106 # Get rid of "unix" and undef.
107 splice(@results, 0, 2) if $NONSTDIO;
110 [ "stdio", undef, sub { $_[0] > 0 },
111 "encoding", "iso-8859-1", sub { $_[0] & PerlIO::F_UTF8() } ],
112 ":raw:encoding(latin1)");
117 check([ PerlIO::get_layers(F) ],
124 use open(IN => ":crlf", OUT => ":encoding(cp1252)");
129 check([ PerlIO::get_layers(F, input => 1) ],
133 check([ PerlIO::get_layers(G, output => 1) ],
134 [ qw[stdio encoding(cp1252) utf8] ],
141 1 while unlink "afile";