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"

In reply to Re: How to tie a lexical filehandle. by haukex
in thread How to tie a lexical filehandle. by clueless newbie

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.