in reply to Bug in __DATA__ filehandle

Your code isn't sufficiently obvious to me to see the flow of control and what you expect (nor do I understand how you're using __DATA__, but if you have a filehandle open in a parent and a child simultaneously (that is, if you've opened it in a parent and access it in a child), they share the same position in the file. Re-open the filehandle in the children before doing anything which will affect the file position, or read the data before forking off any kids.

Replies are listed 'Best First'.
Re^2: Bug in __DATA__ filehandle
by Anonymous Monk on Nov 01, 2008 at 20:18 UTC
    Test::Bar is a template, which inherits Test::Foo.

    Test::Foo reaches into Test::Bar and sticks everything from Test::Bar::__DATA__ into $Test::Bar::T at constructor time. Subsquent objects evaluate $Test::Bar::T for content and should never touch __DATA__.

    So no matter what, there should only ever be one access of the __DATA__ handle. The bug is kindof chicken and egg. If I warn from the function right before the filehandle read, the warning only occurs once, confirming that Test::Foo::loadfh() is only called once, yet the data stored in $Test::Bar::T apparently changes after the second socket connection. So something is getting called twice, but it is not function that is reading the filehandle.

    When I was tweaking, I did a: warn(tell($fh)), and it reported a negative file index. I am assuming that shouldn't happen. Can anyone confirm that a tell() should not report a negative file index?