package open;
+use Carp;
$open::hint_bits = 0x20000;
+use vars qw(%layers @layers);
+
+# Populate hash in non-PerlIO case
+%layers = (crlf => 1, raw => 0) unless (@layers);
+
+# warn join(',',keys %layers);
+
+our $VERSION = '1.00';
+
sub import {
- shift;
- die "`use open' needs explicit list of disciplines" unless @_;
+ my ($class,@args) = @_;
+ croak("`use open' needs explicit list of disciplines") unless @args;
$^H |= $open::hint_bits;
- while (@_) {
- my $type = shift;
- if ($type =~ /^(IN|OUT)\z/s) {
- my $discp = shift;
- unless ($discp =~ /^\s*:(raw|crlf)\s*\z/s) {
- die "Unknown discipline '$discp'";
+ my ($in,$out) = split(/\0/,(${^OPEN} || '\0'));
+ my @in = split(/\s+/,$in);
+ my @out = split(/\s+/,$out);
+ while (@args) {
+ my $type = shift(@args);
+ my $discp = shift(@args);
+ my @val;
+ foreach my $layer (split(/\s+/,$discp)) {
+ $layer =~ s/^://;
+ unless(exists $layers{$layer}) {
+ carp("Unknown discipline layer '$layer'");
}
- $^H{"open_$type"} = $discp;
+ push(@val,":$layer");
+ if ($layer =~ /^(crlf|raw)$/) {
+ $^H{"open_$type"} = $layer;
+ }
+ }
+ if ($type eq 'IN') {
+ $in = join(' ',@val);
+ }
+ elsif ($type eq 'OUT') {
+ $out = join(' ',@val);
}
else {
- die "Unknown discipline class '$type'";
+ croak "Unknown discipline class '$type'";
}
}
+ ${^OPEN} = join('\0',$in,$out);
}
1;
I/O operations. Any open() and readpipe() (aka qx//) operators found
within the lexical scope of this pragma will use the declared defaults.
Neither open() with an explicit set of disciplines, nor sysopen() are
-not influenced by this pragma.
+influenced by this pragma.
Only the two pseudo-disciplines ":raw" and ":crlf" are currently
available.
the interfaces to declare default disciplines for all I/O.
In future, any default disciplines declared by this pragma will be
-available by the special discipline name ":def", and could be used
+available by the special discipline name ":DEFAULT", and could be used
within handle constructors that allow disciplines to be specified.
This would make it possible to stack new disciplines over the default
ones.
- open FH, "<:para :def", $file or die "can't open $file: $!";
+ open FH, "<:para :DEFAULT", $file or die "can't open $file: $!";
Socket and directory handles will also support disciplines in
future.