package TieInput; use Data::Dumper; use strict; use warnings; # TieInput subs { my @In; sub CLOSE { my $self_O=shift; my $fh=$In[$self_O->{fhno}]; close($fh); }; # CLOSE: sub DESTROY { }; # DESTROY: sub OPEN { }; # OPEN: sub READLINE { my $self_O=shift; my $fh=$In[$self_O->{fhno}]; if (wantarray()) { my @_a=<$fh>; warn __PACKAGE__,": ",Data::Dumper->Dump([\@_a],[qw(*_a)]); return @_a; } else { my $_s=<$fh>; warn __PACKAGE__,": ",Data::Dumper->Dump([\$_s],[qw(*_s)]); return $_s; }; }; # READLINE: sub TIEHANDLE { my $Class_C=shift; # Point $fh to the real thingie ... open(my $In,"<&",$_[0]); push(@In,$In); return bless { fhno=>$#In }; }; # TIEHANDLE: sub UNTIE { #say __PACKAGE__."::UNTIE<>\n"; my ($self_O,$count_S)=@_; return; }; # UNTIE: # }; # Internal (tie) Subs: BEGIN { # Thanks to Eliya # Currently not checking to insure the file will be opened readonly *CORE::GLOBAL::open=sub (*;$@) { #use Symbol(); #my $handle=Symbol::qualify_to_ref($_[0], scalar caller); # #$_[0]=$handle # unless defined $_[0]; # pass up to caller my $handle; if (@_ == 1) { CORE::open $handle or warn $! and return 0; } elsif (@_ == 2) { CORE::open $handle, $_[1] or warn $! and return 0; } elsif (@_ == 3) { if (defined $_[2]) { CORE::open $handle, $_[1], $_[2] or warn $! and return 0; } else { CORE::open $handle, $_[1], undef # special case or warn $! and return 0; }; } else { CORE::open $handle, $_[1], $_[2], @_[3..$#_] or warn $! and return 0; }; tie *$handle,"TieInput",*$handle; }; # CORE::GLOBAL::open }; __PACKAGE__ __END__