Subject: | Module doesn't work when process forks |
Greetings,
consider this sample script:
use strict;
use Media::Type::Simple qw[type_from_ext];
for( 1..2 ) {
if( my $pid = fork() ) {
print "$pid: ". type_from_ext( 'jpg' ) . $/;
}
}
When run, it dies as follows:
$ perl tmp/z.pl
5826: image/jpeg
Unknown extension: jpg at tmp/z.pl line 5
The reason is that you are using the data filehandle, which
needs to be seek'd back to it's original position when done.
The attached patch fixes this.
Please be so kind to apply & release a new version, so we don't have to
keep a locally patched copy in svn.
Thank you,
Subject: | mts.patch |
--- a/Media/Type/Simple.pm (revision 1418)
+++ b/Media/Type/Simple.pm (working copy)
@@ -55,11 +55,11 @@
=head1 VERSION
-Version 0.02
+Version 0.02_01+HC
=cut
-our $VERSION = '0.02';
+our $VERSION = '0.02_01+HC';
=head1 SYNOPSIS
@@ -134,7 +134,14 @@
}
else {
unless (defined $Default) {
+
+ # Have to reset the seek() position to make this work while
+ # forking. find out the current position and put it back when
+ # we are done reading --kane
+ my $offset = tell DATA;
$Default = $self->add_types_from_file( \*DATA );
+
+ seek DATA, $offset, 0;
}
return clone $Default;
}