More EBCDIC stuff:
[p5sagit/p5-mst-13.2.git] / lib / open.pm
CommitLineData
d1edabcf 1package open;
ac27b0f5 2use Carp;
16fe6d59 3$open::hint_bits = 0x20000;
4
ac27b0f5 5use vars qw(%layers @layers);
6
7# Populate hash in non-PerlIO case
8%layers = (crlf => 1, raw => 0) unless (@layers);
9
dfebf958 10# warn join(',',keys %layers);
11
b75c8c73 12our $VERSION = '1.00';
13
16fe6d59 14sub import {
dfebf958 15 my ($class,@args) = @_;
16 croak("`use open' needs explicit list of disciplines") unless @args;
16fe6d59 17 $^H |= $open::hint_bits;
ac27b0f5 18 my ($in,$out) = split(/\0/,(${^OPEN} || '\0'));
19 my @in = split(/\s+/,$in);
20 my @out = split(/\s+/,$out);
dfebf958 21 while (@args) {
22 my $type = shift(@args);
23 my $discp = shift(@args);
ac27b0f5 24 my @val;
dfebf958 25 foreach my $layer (split(/\s+/,$discp)) {
26 $layer =~ s/^://;
ac27b0f5 27 unless(exists $layers{$layer}) {
dfebf958 28 carp("Unknown discipline layer '$layer'");
ac27b0f5 29 }
30 push(@val,":$layer");
31 if ($layer =~ /^(crlf|raw)$/) {
32 $^H{"open_$type"} = $layer;
16fe6d59 33 }
ac27b0f5 34 }
35 if ($type eq 'IN') {
36 $in = join(' ',@val);
37 }
38 elsif ($type eq 'OUT') {
39 $out = join(' ',@val);
16fe6d59 40 }
41 else {
ac27b0f5 42 croak "Unknown discipline class '$type'";
16fe6d59 43 }
44 }
ac27b0f5 45 ${^OPEN} = join('\0',$in,$out);
16fe6d59 46}
47
481;
49__END__
d1edabcf 50
51=head1 NAME
52
53open - perl pragma to set default disciplines for input and output
54
55=head1 SYNOPSIS
56
16fe6d59 57 use open IN => ":crlf", OUT => ":raw";
d1edabcf 58
59=head1 DESCRIPTION
60
d1edabcf 61The open pragma is used to declare one or more default disciplines for
16fe6d59 62I/O operations. Any open() and readpipe() (aka qx//) operators found
63within the lexical scope of this pragma will use the declared defaults.
64Neither open() with an explicit set of disciplines, nor sysopen() are
642f9deb 65influenced by this pragma.
16fe6d59 66
67Only the two pseudo-disciplines ":raw" and ":crlf" are currently
68available.
69
70The ":raw" discipline corresponds to "binary mode" and the ":crlf"
71discipline corresponds to "text mode" on platforms that distinguish
72between the two modes when opening files (which is many DOS-like
73platforms, including Windows). These two disciplines are currently
74no-ops on platforms where binmode() is a no-op, but will be
75supported everywhere in future.
d1edabcf 76
16fe6d59 77=head1 UNIMPLEMENTED FUNCTIONALITY
d1edabcf 78
16fe6d59 79Full-fledged support for I/O disciplines is currently unimplemented.
80When they are eventually supported, this pragma will serve as one of
81the interfaces to declare default disciplines for all I/O.
82
83In future, any default disciplines declared by this pragma will be
9bafe919 84available by the special discipline name ":DEFAULT", and could be used
16fe6d59 85within handle constructors that allow disciplines to be specified.
86This would make it possible to stack new disciplines over the default
87ones.
d1edabcf 88
9bafe919 89 open FH, "<:para :DEFAULT", $file or die "can't open $file: $!";
d1edabcf 90
16fe6d59 91Socket and directory handles will also support disciplines in
92future.
93
94Full support for I/O disciplines will enable all of the supported
95disciplines to work on all platforms.
96
d1edabcf 97=head1 SEE ALSO
98
16fe6d59 99L<perlfunc/"binmode">, L<perlfunc/"open">, L<perlunicode>
d1edabcf 100
101=cut