My CGI::App-based project need to support uploading web images. I
initially used DFV::Constraints::Upload (and by extension, File::MMagic
) for this. However, I recently ran into modperl bugs with File::MMagic,
which caused to explore alternative MIME type detection options,
(including fixing the modperl bugs in File::MMagic).
There's File::Type, but as Adam Kennedy complained, it's a memory hog: l
using 1.5 Megs of memory, he estimates.
My solution was to create a module (not published yet),
File::Type::WebImages, which slimmed down the module to only support the
web image formats I needed, which I suspect is a common case.
Now I'm thinking about how to generalize that a bit, to create a
solution that only loads the range of mime type checks you care about
it, and ignores the rest. Then people could publish plugins that
contain specific groups of mime type checks like "spreadsheets" or
"video formats".
Here's how File::Type::WebImages works now:
my $f = $file_or_scalar;
my $mt = mime_type($f);
Here's how the new, unmamed alternative could work:
my $mt = mime_type($f, \&web_images);
my $mt = mime_type($f, sub { web_images() or spreadsheets() });
In other words, take a callback argument that takes the data as input,
and returns the MIME-type or undef as output.
Then, people can publish domain-specific collections of mime-type
detection. These can be fairly easy ripped out of those that are in
File::Type, or can be easily developed with the code generator published
in File::Type::Builder;
http://search.cpan.org/dist/File-Type/lib/File/Type/Builder.pm
Good idea? Good interface? Suggested name for this approach?
Thanks.
Mark
---------------------------------------------------------------------
Web Archive: http://www.mail-archive.com/suppressed/
http://marc.theaimsgroup.com/?l=cgiapp&r=1&w=2
To unsubscribe, e-mail: suppressed
For additional commands, e-mail: suppressed
Mail converted by mhonarc 2.6.15
This archive provided courtesy of JSW4.NET, Internet Hosting Services for Small Business.