3 $open::hint_bits = 0x20000;
8 my ($class,@args) = @_;
9 croak("`use open' needs explicit list of disciplines") unless @args;
10 $^H |= $open::hint_bits;
11 my ($in,$out) = split(/\0/,(${^OPEN} || '\0'));
12 my @in = split(/\s+/,$in);
13 my @out = split(/\s+/,$out);
15 my $type = shift(@args);
16 my $discp = shift(@args);
18 foreach my $layer (split(/\s+/,$discp)) {
20 unless(PerlIO::Layer::->find($layer)) {
21 carp("Unknown discipline layer '$layer'");
24 if ($layer =~ /^(crlf|raw)$/) {
25 $^H{"open_$type"} = $layer;
31 elsif ($type eq 'OUT') {
32 $out = join(' ',@val);
35 croak "Unknown discipline class '$type'";
38 ${^OPEN} = join('\0',$in,$out);
46 open - perl pragma to set default disciplines for input and output
50 use open IN => ":crlf", OUT => ":raw";
54 Full-fledged support for I/O disciplines is now implemented provided
55 Perl is configured to use PerlIO as its IO system (which is now the
58 The C<open> pragma serves as one of the interfaces to declare default
59 "layers" (aka disciplines) for all I/O.
61 The C<open> pragma is used to declare one or more default layers for
62 I/O operations. Any open(), readpipe() (aka qx//) and similar
63 operators found within the lexical scope of this pragma will use the
66 When open() is given an explicit list of layers they are appended to
67 the list declared using this pragma.
69 Directory handles may also support disciplines in future.
71 =head1 NONPERLIO FUNCTIONALITY
73 If Perl is not built to use PerlIO as its IO system then only the two
74 pseudo-disciplines ":raw" and ":crlf" are available.
76 The ":raw" discipline corresponds to "binary mode" and the ":crlf"
77 discipline corresponds to "text mode" on platforms that distinguish
78 between the two modes when opening files (which is many DOS-like
79 platforms, including Windows). These two disciplines are no-ops on
80 platforms where binmode() is a no-op, but perform their functions
81 everywhere if PerlIO is enabled.
83 =head1 IMPLEMENTATION DETAILS
85 There is a class method in C<PerlIO::Layer> C<find> which is implemented as XS code.
86 It is called by C<import> to validate the layers:
88 PerlIO::Layer::->find("perlio")
90 The return value (if defined) is a Perl object, of class C<PerlIO::Layer> which is
91 created by the C code in F<perlio.c>. As yet there is nothing useful you can do with the
92 object at the perl level.
96 L<perlfunc/"binmode">, L<perlfunc/"open">, L<perlunicode>, L<PerlIO>