Initial bulk commit for "Git on MSys"
[msysgit/historical-msysgit.git] / lib / perl5 / 5.6.1 / open.pm
blobcdd20ac2c3926f37433bf8f41ccd2599ed530775
1 package open;
2 $open::hint_bits = 0x20000;
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'";
15 $^H{"open_$type"} = $discp;
17 else {
18 die "Unknown discipline class '$type'";
24 __END__
26 =head1 NAME
28 open - perl pragma to set default disciplines for input and output
30 =head1 SYNOPSIS
32 use open IN => ":crlf", OUT => ":raw";
34 =head1 DESCRIPTION
36 The open pragma is used to declare one or more default disciplines for
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
40 influenced by this pragma.
42 Only the two pseudo-disciplines ":raw" and ":crlf" are currently
43 available.
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.
52 =head1 UNIMPLEMENTED FUNCTIONALITY
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.
58 In future, any default disciplines declared by this pragma will be
59 available by the special discipline name ":DEFAULT", 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.
64 open FH, "<:para :DEFAULT", $file or die "can't open $file: $!";
66 Socket and directory handles will also support disciplines in
67 future.
69 Full support for I/O disciplines will enable all of the supported
70 disciplines to work on all platforms.
72 =head1 SEE ALSO
74 L<perlfunc/"binmode">, L<perlfunc/"open">, L<perlunicode>
76 =cut