Commit | Line | Data |
---|---|---|
d1edabcf | 1 | package open; |
16fe6d59 GS |
2 | $open::hint_bits = 0x20000; |
3 | ||
4 | sub import { | |
5 | shift; | |
6 | die "`use open' needs explicit list of disciplines" unless @_; | |
7 | $^H |= $open::hint_bits; | |
8 | while (@_) { | |
9 | my $type = shift; | |
10 | if ($type =~ /^(IN|OUT)\z/s) { | |
11 | my $discp = shift; | |
12 | unless ($discp =~ /^\s*:(raw|crlf)\s*\z/s) { | |
13 | die "Unknown discipline '$discp'"; | |
14 | } | |
15 | $^H{"open_$type"} = $discp; | |
16 | } | |
17 | else { | |
18 | die "Unknown discipline class '$type'"; | |
19 | } | |
20 | } | |
21 | } | |
22 | ||
23 | 1; | |
24 | __END__ | |
d1edabcf GS |
25 | |
26 | =head1 NAME | |
27 | ||
28 | open - perl pragma to set default disciplines for input and output | |
29 | ||
30 | =head1 SYNOPSIS | |
31 | ||
16fe6d59 | 32 | use open IN => ":crlf", OUT => ":raw"; |
d1edabcf GS |
33 | |
34 | =head1 DESCRIPTION | |
35 | ||
d1edabcf | 36 | The open pragma is used to declare one or more default disciplines for |
16fe6d59 GS |
37 | I/O operations. Any open() and readpipe() (aka qx//) operators found |
38 | within the lexical scope of this pragma will use the declared defaults. | |
39 | Neither open() with an explicit set of disciplines, nor sysopen() are | |
642f9deb | 40 | influenced by this pragma. |
16fe6d59 GS |
41 | |
42 | Only the two pseudo-disciplines ":raw" and ":crlf" are currently | |
43 | available. | |
44 | ||
45 | The ":raw" discipline corresponds to "binary mode" and the ":crlf" | |
46 | discipline corresponds to "text mode" on platforms that distinguish | |
47 | between the two modes when opening files (which is many DOS-like | |
48 | platforms, including Windows). These two disciplines are currently | |
49 | no-ops on platforms where binmode() is a no-op, but will be | |
50 | supported everywhere in future. | |
d1edabcf | 51 | |
16fe6d59 | 52 | =head1 UNIMPLEMENTED FUNCTIONALITY |
d1edabcf | 53 | |
16fe6d59 GS |
54 | Full-fledged support for I/O disciplines is currently unimplemented. |
55 | When they are eventually supported, this pragma will serve as one of | |
56 | the interfaces to declare default disciplines for all I/O. | |
57 | ||
58 | In future, any default disciplines declared by this pragma will be | |
59 | available by the special discipline name ":def", and could be used | |
60 | within handle constructors that allow disciplines to be specified. | |
61 | This would make it possible to stack new disciplines over the default | |
62 | ones. | |
d1edabcf GS |
63 | |
64 | open FH, "<:para :def", $file or die "can't open $file: $!"; | |
65 | ||
16fe6d59 GS |
66 | Socket and directory handles will also support disciplines in |
67 | future. | |
68 | ||
69 | Full support for I/O disciplines will enable all of the supported | |
70 | disciplines to work on all platforms. | |
71 | ||
d1edabcf GS |
72 | =head1 SEE ALSO |
73 | ||
16fe6d59 | 74 | L<perlfunc/"binmode">, L<perlfunc/"open">, L<perlunicode> |
d1edabcf GS |
75 | |
76 | =cut |