3 $open::hint_bits = 0x20000;
5 use vars qw(%layers @layers);
7 # Populate hash in non-PerlIO case
8 %layers = (crlf => 1, raw => 0) unless (@layers);
10 our $VERSION = '1.00';
14 die "`use open' needs explicit list of disciplines" unless @_;
15 $^H |= $open::hint_bits;
16 my ($in,$out) = split(/\0/,(${^OPEN} || '\0'));
17 my @in = split(/\s+/,$in);
18 my @out = split(/\s+/,$out);
23 foreach my $layer (split(/\s+:?/,$discp)) {
24 unless(exists $layers{$layer}) {
25 croak "Unknown discipline layer '$layer'";
28 if ($layer =~ /^(crlf|raw)$/) {
29 $^H{"open_$type"} = $layer;
35 elsif ($type eq 'OUT') {
36 $out = join(' ',@val);
39 croak "Unknown discipline class '$type'";
42 ${^OPEN} = join('\0',$in,$out);
50 open - perl pragma to set default disciplines for input and output
54 use open IN => ":crlf", OUT => ":raw";
58 The open pragma is used to declare one or more default disciplines for
59 I/O operations. Any open() and readpipe() (aka qx//) operators found
60 within the lexical scope of this pragma will use the declared defaults.
61 Neither open() with an explicit set of disciplines, nor sysopen() are
62 influenced by this pragma.
64 Only the two pseudo-disciplines ":raw" and ":crlf" are currently
67 The ":raw" discipline corresponds to "binary mode" and the ":crlf"
68 discipline corresponds to "text mode" on platforms that distinguish
69 between the two modes when opening files (which is many DOS-like
70 platforms, including Windows). These two disciplines are currently
71 no-ops on platforms where binmode() is a no-op, but will be
72 supported everywhere in future.
74 =head1 UNIMPLEMENTED FUNCTIONALITY
76 Full-fledged support for I/O disciplines is currently unimplemented.
77 When they are eventually supported, this pragma will serve as one of
78 the interfaces to declare default disciplines for all I/O.
80 In future, any default disciplines declared by this pragma will be
81 available by the special discipline name ":DEFAULT", and could be used
82 within handle constructors that allow disciplines to be specified.
83 This would make it possible to stack new disciplines over the default
86 open FH, "<:para :DEFAULT", $file or die "can't open $file: $!";
88 Socket and directory handles will also support disciplines in
91 Full support for I/O disciplines will enable all of the supported
92 disciplines to work on all platforms.
96 L<perlfunc/"binmode">, L<perlfunc/"open">, L<perlunicode>