summaryrefslogtreecommitdiff
path: root/lib/open.pm
diff options
context:
space:
mode:
authorNick Ing-Simmons <nik@tiuk.ti.com>2000-11-18 20:17:22 +0000
committerNick Ing-Simmons <nik@tiuk.ti.com>2000-11-18 20:17:22 +0000
commitac27b0f573239284c298fcf96fb6c966551ef207 (patch)
tree13447eed9b72cd6cfd50796c13cabbf22c4383d6 /lib/open.pm
parentb931b1d952313afa398828ff4b2a40af20cfa65a (diff)
downloadperl-ac27b0f573239284c298fcf96fb6c966551ef207.tar.gz
Lexical use open ... support:
add ->cop_io to COP structure in cop.h. Make mg.c and gv.c associate it with ${^OPEN}. Make lib/open.pm set it. Have sv.c, perl.c, pp_ctl.c, op.c manipulate it in a manner manner similar to ->cop_warnings. Have doio.c's do_open9 and pp_sys.c's pp_backticks use it as default and call new PerlIO_apply_layers(). Declare latter in perlio.h and define in perlio.c p4raw-id: //depot/perlio@7740
Diffstat (limited to 'lib/open.pm')
-rw-r--r--lib/open.pm32
1 files changed, 26 insertions, 6 deletions
diff --git a/lib/open.pm b/lib/open.pm
index cdd20ac2c3..82b043afc8 100644
--- a/lib/open.pm
+++ b/lib/open.pm
@@ -1,23 +1,43 @@
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);
+
sub import {
shift;
die "`use open' needs explicit list of disciplines" unless @_;
$^H |= $open::hint_bits;
+ my ($in,$out) = split(/\0/,(${^OPEN} || '\0'));
+ my @in = split(/\s+/,$in);
+ my @out = split(/\s+/,$out);
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 $discp = shift;
+ my @val;
+ foreach my $layer (split(/\s+:?/,$discp)) {
+ unless(exists $layers{$layer}) {
+ croak "Unknown discipline layer '$layer'";
+ }
+ push(@val,":$layer");
+ if ($layer =~ /^(crlf|raw)$/) {
+ $^H{"open_$type"} = $layer;
}
- $^H{"open_$type"} = $discp;
+ }
+ 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;