996
|
1 package Language::INTERCAL::GenericIO::TEE;
|
|
2
|
|
3 # Read data to multiple files
|
|
4
|
|
5 # This file is part of CLC-INTERCAL
|
|
6
|
|
7 # Copyright (c) 2006-2008 Claudio Calvelli, all rights reserved.
|
|
8
|
|
9 # CLC-INTERCAL is copyrighted software. However, permission to use, modify,
|
|
10 # and distribute it is granted provided that the conditions set out in the
|
|
11 # licence agreement are met. See files README and COPYING in the distribution.
|
|
12
|
|
13 use strict;
|
|
14 use vars qw($VERSION $PERVERSION);
|
|
15 ($VERSION) = ($PERVERSION = "CLC-INTERCAL/Base INTERCAL/GenericIO/TEE.pm 1.-94.-2") =~ /\s(\S+)$/;
|
|
16
|
|
17 use Carp;
|
|
18 use Language::INTERCAL::Exporter '1.-94.-2';
|
|
19 use Language::INTERCAL::Splats '1.-94.-2', qw(:SP);
|
|
20 use Language::INTERCAL::GenericIO '1.-94.-2';
|
|
21 use vars qw(@ISA);
|
|
22 @ISA = qw(Language::INTERCAL::GenericIO);
|
|
23
|
|
24 sub _new {
|
|
25 @_ == 3 or croak
|
|
26 "Usage: new Language::INTERCAL::GenericIO::TEE(MODE, LIST)";
|
|
27 my ($object, $mode, $data) = @_;
|
|
28 $mode =~ /[ar]/ or croak "MODE must be \"read\" when TYPE is TEE";
|
|
29 ref $data && 'ARRAY' eq ref $data or croak "DATA must be a array ref";
|
|
30 $object->{filedata} = $data;
|
|
31 }
|
|
32
|
|
33 sub read_binary {
|
|
34 @_ == 2 or croak "Usage: IO->read_binary(DATA)";
|
|
35 my ($object, $string) = @_;
|
|
36 for my $tee (@{$object->{filedata}}) {
|
|
37 $tee->read_binary($string);
|
|
38 }
|
|
39 $object;
|
|
40 }
|
|
41
|
|
42 sub _write_code { return '' }
|
|
43 sub _write_text_code { return '' }
|
|
44
|
|
45 sub describe {
|
|
46 @_ == 1 or croak "Usage: IO->describe";
|
|
47 my ($object) = @_;
|
|
48 return "TEE(" .
|
|
49 join(',', map { $_->describe } @{$object->{filedata}}) .
|
|
50 ")";
|
|
51 }
|
|
52
|
|
53 sub is_terminal {
|
|
54 @_ == 1 or croak "Usage: IO->is_terminal";
|
|
55 my ($object) = @_;
|
|
56 # if any of the files is a terminal, the whole TEE is a terminal; the idea
|
|
57 # is that is_terminal() is used to decide whether to produce prompts
|
|
58 for my $f (@{$object->{filedata}}) {
|
|
59 $f->is_terminal and return 1;
|
|
60 }
|
|
61 0;
|
|
62 }
|
|
63
|
|
64 1;
|