in reply to How to tie a lexical filehandle.

I know this is an older post, but I thought you might be interested that I just released version 0.06 of Tie::Handle::Base (it's part of File-Replace, but it don't require any non-core modules except for testing Update: as of 0.16, it's now in its own distribution, and it doesn't require any non-core modules). In particular, I thought the "Debugging" example might help you with your MyTie:

#!/usr/bin/env perl use warnings; use strict; { package MyTie; use parent 'Tie::Handle::Base'; use Class::Method::Modifiers qw/before around/; use Data::Dump; for my $method (@Tie::Handle::Base::ALL_METHODS) { before $method => sub { dd $method, @_[1..$#_] }; } around 'READLINE' => sub { my $orig = shift; my @a = wantarray ? ($orig->(@_)) : (scalar $orig->(@_)); main::mySub(@a); return wantarray ? @a : $a[0]; }; } use Data::Dump; sub mySub { dd "mySub", @_; } #open my $fh = MyTie->new, '<', 'mydata' or die $!; my $fh = MyTie->new(*DATA); my $line = <$fh>; print "Scalar: $line"; $line = <$fh>; print "Scalar: $line"; my @array = <$fh>; print "Array: ", @array; close $fh; __DATA__ Foo Bar Quz Baz

Output:

("TIEHANDLE", *main::DATA) "READLINE" ("mySub", "Foo\n") Scalar: Foo "READLINE" ("mySub", "Bar\n") Scalar: Bar "READLINE" ("mySub", "Quz\n", "Baz\n") Array: Quz Baz "CLOSE" "DESTROY"