|We don't bite newbies here... much|
Re: Problem with tie *STDIN, 'IO::Scalar', \$text;by chromatic (Archbishop)
|on Apr 29, 2001 at 01:45 UTC||Need Help??|
The perldoc perltie has some good examples of how to do this. I'd start with Tie::Handle, subclass it, and go from there.
You could probably get by with overloading TIEHANDLE() and READLINE(), though your needs will determine that. I can provide code if you really need some, but it's pretty plain in perltie.
Update: Perhaps I've not made myself clear. Yes, I've found myself in exactly the same situation you describe. Trying to integrate HTTP::Daemon with CGI is a hassle -- HTTP::Daemon produces a HTTP::Response object that allows you to get at posted data via the content() method (I may have the names slightly wrong, but the idea is the same). CGI reads from STDIN or another filehandle.
The solution was to make a tied filehandle, pass it to the CGI.pm constructor. This let me intercept the READ and READLINE calls from CGI.pm to the filehandle, pulling data out of content(), manipulate them as desired, and pass them along.
As far as HTTP::Response knew, I was doing normal stuff. As far as CGI.pm knew, it was reading from a normal filehandle.
Yes, it would be nice if they knew how to play together. At the cost of writing 30 lines of glue code, I faked them out.
That is why I brought it up -- it will let you do just what you describe.