support binmode(F,":crlf") and use open IN => ":raw", OUT => ":crlf"
[p5sagit/p5-mst-13.2.git] / lib / open.pm
CommitLineData
d1edabcf 1package open;
16fe6d59 2$open::hint_bits = 0x20000;
3
4sub 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
231;
24__END__
d1edabcf 25
26=head1 NAME
27
28open - perl pragma to set default disciplines for input and output
29
30=head1 SYNOPSIS
31
16fe6d59 32 use open IN => ":crlf", OUT => ":raw";
d1edabcf 33
34=head1 DESCRIPTION
35
d1edabcf 36The open pragma is used to declare one or more default disciplines for
16fe6d59 37I/O operations. Any open() and readpipe() (aka qx//) operators found
38within the lexical scope of this pragma will use the declared defaults.
39Neither open() with an explicit set of disciplines, nor sysopen() are
40not influenced by this pragma.
41
42Only the two pseudo-disciplines ":raw" and ":crlf" are currently
43available.
44
45The ":raw" discipline corresponds to "binary mode" and the ":crlf"
46discipline corresponds to "text mode" on platforms that distinguish
47between the two modes when opening files (which is many DOS-like
48platforms, including Windows). These two disciplines are currently
49no-ops on platforms where binmode() is a no-op, but will be
50supported everywhere in future.
d1edabcf 51
16fe6d59 52=head1 UNIMPLEMENTED FUNCTIONALITY
d1edabcf 53
16fe6d59 54Full-fledged support for I/O disciplines is currently unimplemented.
55When they are eventually supported, this pragma will serve as one of
56the interfaces to declare default disciplines for all I/O.
57
58In future, any default disciplines declared by this pragma will be
59available by the special discipline name ":def", and could be used
60within handle constructors that allow disciplines to be specified.
61This would make it possible to stack new disciplines over the default
62ones.
d1edabcf 63
64 open FH, "<:para :def", $file or die "can't open $file: $!";
65
16fe6d59 66Socket and directory handles will also support disciplines in
67future.
68
69Full support for I/O disciplines will enable all of the supported
70disciplines to work on all platforms.
71
d1edabcf 72=head1 SEE ALSO
73
16fe6d59 74L<perlfunc/"binmode">, L<perlfunc/"open">, L<perlunicode>
d1edabcf 75
76=cut