source: trunk/third/perl/lib/open.pm @ 14545

Revision 14545, 2.2 KB checked in by ghudson, 24 years ago (diff)
This commit was generated by cvs2svn to compensate for changes in r14544, which included commits to RCS files with non-trunk default branches.
Line 
1package open;
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__
25
26=head1 NAME
27
28open - perl pragma to set default disciplines for input and output
29
30=head1 SYNOPSIS
31
32    use open IN => ":crlf", OUT => ":raw";
33
34=head1 DESCRIPTION
35
36The open pragma is used to declare one or more default disciplines for
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
40influenced 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.
51
52=head1 UNIMPLEMENTED FUNCTIONALITY
53
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 ":DEFAULT", 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.
63
64    open FH, "<:para :DEFAULT", $file or die "can't open $file: $!";
65
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
72=head1 SEE ALSO
73
74L<perlfunc/"binmode">, L<perlfunc/"open">, L<perlunicode>
75
76=cut
Note: See TracBrowser for help on using the repository browser.