| 1 | package MPE::Spoonfeed; | ||
| 2 | |||
| 3 | require 5.005_62; | ||
| 4 | 1 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 5 | 1 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 6 | |||
| 7 | require Exporter; | ||
| 8 | require MPE::Process; | ||
| 9 | 0 | ▶ | use MPE::File; |
|
Subroutine
BEGIN: called CC=1 SCAR=2.6
| |||
| 10 | |||
| 11 | our @ISA = qw(Exporter MPE::Process); | ||
| 12 | |||
| 13 | our %EXPORT_TAGS = ( 'all' => [ qw( | ||
| 14 | ) ] ); | ||
| 15 | |||
| 16 | our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } ); | ||
| 17 | |||
| 18 | our @EXPORT = qw( | ||
| 19 | ); | ||
| 20 | |||
| 21 | our $VERSION = '0.01'; | ||
| 22 | |||
| 23 | sub new { | ||
| 24 | my $proto = shift; | ||
| 25 | my $class = ref($proto) || $proto; | ||
| 26 | my @params; | ||
| 27 | my @superparms; | ||
| 28 | my $progname = shift; | ||
| 29 | my %defaults = ( autocmd => '', autoactivate => 0, loadflag => 1); | ||
| 30 | |||
| 31 | if (defined $_[0] && ref($_[0]) eq 'HASH') { | ||
| 32 | @params = %{$_[0]}; | ||
| 33 | } else { | ||
| 34 | @params = @_; | ||
| 35 | } | ||
| 36 | while (my $nextparm = shift @params) { | ||
| 37 | my $nextparmval = shift @params; | ||
| 38 | $nextparm =~ s/^-//; | ||
| 39 | if (defined $defaults{lc $nextparm}) { | ||
| 40 | $defaults{lc $nextparm} = $nextparmval; | ||
| 41 | } else { | ||
| 42 | push @superparms, $nextparm, $nextparmval; | ||
| 43 | } | ||
| 44 | } | ||
| 45 | my $msgfilename = sprintf "T%03d%04d.PUB.SYS", | ||
| 46 | $$ % 1000, int(rand(10000)); | ||
| 47 | my $msgfile = MPE::File->new( | ||
| 48 | "$msgfilename,new;temp;rec=-32000,,v,ascii;msg"); | ||
| 49 | if (!defined($msgfile)) { | ||
| 50 | print STDERR "Error creating msg file $msgfilename: $MPE_error\n"; | ||
| 51 | return undef; | ||
| 52 | } | ||
| 53 | $msgfile->fclose(0,0); | ||
| 54 | system("callci 'file $msgfilename,oldtemp;multi;shr;del'"); | ||
| 55 | $msgfile = MPE::File->new("$msgfilename;acc=append"); | ||
| 56 | if (!defined($msgfile)) { | ||
| 57 | print STDERR "Error opening msg file $msgfilename: $MPE_error\n"; | ||
| 58 | return undef; | ||
| 59 | } | ||
| 60 | my $self = $class->SUPER::new($progname, | ||
| 61 | @superparms, | ||
| 62 | STDIN => "*$msgfilename", | ||
| 63 | loadflag => $defaults{loadflag}); | ||
| 64 | system("callci 'reset $msgfilename'"); | ||
| 65 | if (!defined($self) || $self == 0) { | ||
| 66 | print STDERR "Error on CreateProcess: $MPE::Process::CreateStatus\n"; | ||
| 67 | return undef; | ||
| 68 | } | ||
| 69 | |||
| 70 | @{$self}{keys %defaults} = values %defaults; | ||
| 71 | $$self{msgfile} = $msgfile; | ||
| 72 | return bless $self, $class; | ||
| 73 | } | ||
| 74 | |||
| 75 | sub DESTROY { | ||
| 76 | my $self = shift; | ||
| 77 | $$self{msgfile}->fclose(0,0); | ||
| 78 | $self->SUPER::DESTROY(); | ||
| 79 | } | ||
| 80 | |||
| 81 | sub cmds { | ||
| 82 | my $self = shift; | ||
| 83 | my $msgfile = $$self{msgfile}; | ||
| 84 | for (@_) { | ||
| 85 | if (!$msgfile->writerec($_)) { | ||
| 86 | die "Error writing to msgfile: $MPE_error\n"; | ||
| 87 | } | ||
| 88 | } | ||
| 89 | if ($$self{autocmd}) { | ||
| 90 | if (!$msgfile->writerec($$self{autocmd})) { | ||
| 91 | die "Error writing to msgfile: $MPE_error\n"; | ||
| 92 | } | ||
| 93 | } | ||
| 94 | if ($$self{autoactivate}) { | ||
| 95 | $self->activate(2); | ||
| 96 | } | ||
| 97 | } | ||
| 98 | |||
| 99 | sub suppressboguswarning { | ||
| 100 | print STDERR "Error on CreateProcess: $MPE::Process::CreateStatus\n"; | ||
| 101 | } | ||
| 102 | |||
| 103 | sub cmdsactivate { | ||
| 104 | my $self = shift; | ||
| 105 | my $msgfile = $$self{msgfile}; | ||
| 106 | for (@_) { | ||
| 107 | if (!$msgfile->writerec($_)) { | ||
| 108 | die "Error writing to msgfile: $MPE_error\n"; | ||
| 109 | } | ||
| 110 | } | ||
| 111 | if ($$self{autocmd}) { | ||
| 112 | if (!$msgfile->writerec($$self{autocmd})) { | ||
| 113 | die "Error writing to msgfile: $MPE_error\n"; | ||
| 114 | } | ||
| 115 | } | ||
| 116 | $self->activate(2); | ||
| 117 | } | ||
| 118 | |||
| 119 | |||
| 120 | 1; | ||
| 121 | __END__ | ||