Subject: | addFileExts() not work for checktype_byfilename |
I expect the test.pl returns 'application/excel-s', but it doesn't.
I use perl 5.8.9 on FreeBSD box and I install p5-File-MMagic ports.
I find Scalar::Util::weaken() cause this problem but I'm not sure about
memory leaks.
Thanks.
Subject: | test.pl |
use File::MMagic;
my $file = "/tmp/sample.xls";
my $magic = new File::MMagic;
$magic->addFileExts('\\.xls$', 'application/excel-s');
my $type = $magic->checktype_byfilename($file);
print("checktype_byfilename:" . $type . "\n");
Subject: | MMagic.pm.patch |
*** MMagic.pm.old 2012-10-31 15:47:37.000000000 +0900
--- MMagic.pm 2012-10-31 15:47:50.000000000 +0900
***************
*** 740,746 ****
$fname =~ s/^.*\///;
for my $regex (keys %{$self->{FILEEXTS}}) {
! Scalar::Util::weaken($self->{FILEEXTS});
if ($fname =~ /$regex/i) {
if ((defined $type && $type !~ /;/) || (! defined $type)) {
$type = $self->{FILEEXTS}->{$regex}; # has no x-type param
--- 740,746 ----
$fname =~ s/^.*\///;
for my $regex (keys %{$self->{FILEEXTS}}) {
! # Scalar::Util::weaken($self->{FILEEXTS});
if ($fname =~ /$regex/i) {
if ((defined $type && $type !~ /;/) || (! defined $type)) {
$type = $self->{FILEEXTS}->{$regex}; # has no x-type param