Cwd.pm docs
[p5sagit/p5-mst-13.2.git] / lib / open.pm
index cdd20ac..53ae308 100644 (file)
@@ -1,23 +1,48 @@
 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;