On 10/14/05, Brett Sanger <[EMAIL PROTECTED]> wrote:
> This isn't strictly a cgiapp question, but it's close enough for me :)
> I'm sure someone here has dealt with it.
>
> I want to be able to take an uploaded file and pass it through
> Text::CSV_XS to get my data.
>
> problem: CGI gives me (through it's upload() interface) a blessed "Fh"
> object. (Which looks to be defined inside CGI.pm)
That 'feature' of CGI.pm is very annoying, and cost me a couple days
of frustration to get it to work properly for my
Data::FormValidator::Filter::Image module. It takes an uploaded file
and filters it through ImageMagick, which also wants a true
filehandle, and not the bastardized CGI.pm filehandle/object.
The solution is surprisingly short (I orginally wrote simple here, but
I can't say that word really fits for this odd and annoying
situation):
my $fh = $query->upload('filename');
my $real_fh = \*$fh;
What that is doing, is dereferencing $fh into a file handle, and then
taking a reference to it again. This gets rid of the blessed object
completely, and leaves you with just a file handle.
For a usage example look at the above mentioned
Data::FormValidator::Filter::Image and see what other hoops I had to
jump through to create my own new Fh object to return to the user, so
that things continue to work as CGI.pm intends.
> 4) unbless the reference.
As an aside, I briefly contemplated doing this, and there is even a
module on CPAN that does it for you. It is aptly called Acme::Damn.
Cheers,
Cees
---------------------------------------------------------------------
Web Archive: http://www.mail-archive.com/[email protected]/
http://marc.theaimsgroup.com/?l=cgiapp&r=1&w=2
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]