Skip Menu |

This queue is for tickets about the MIME-Types CPAN distribution.

Report information
The Basics
Id: 120065
Status: resolved
Priority: 0/
Queue: MIME-Types

People
Owner: Nobody in particular
Requestors: spam [...] mm.st
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



Subject: Object API does not return MIME type, function API does
Date: Wed, 1 Feb 2017 16:36:56 +0100
To: bug-MIME-Types [...] rt.cpan.org
From: spam [...] mm.st
Hello, this works: my ($type, $enc) = MIME::Types::by_suffix($filename); this returns /null /instead: my $mt =|MIME::Types->new|; my $type =|$mt||->mimeTypeOf($filename);| |System details:| || || |# cat /etc/redhat-release| |CentOS release 6.6 (Final)| |# perl -v| || |This is perl, v5.10.1 (*) built for x86_64-linux-thread-multi ||| |Thanks in advance for the support you may give, Anselmo Canfora | || || || || | |
Subject: Re: [rt.cpan.org #120065] AutoReply: Object API does not return MIME type, function API does
Date: Wed, 1 Feb 2017 16:41:10 +0100
To: bug-MIME-Types [...] rt.cpan.org
From: spam [...] mm.st
Sorry, seen that mail HTML formatting introduced spurious chars on summary, trying to post it again freed of formatting, see below: Hello, this works: my ($type, $enc) = MIME::Types::by_suffix($filename); this returns null instead: my $mt = MIME::Types->new; my $type = $mt->mimeTypeOf($filename); System details: # cat /etc/redhat-release CentOS release 6.6 (Final) # perl -v This is perl, v5.10.1 (*) built for x86_64-linux-thread-multi Thanks in advance for the support you may give, Anselmo Canfora
Subject: Re: [rt.cpan.org #120065] AutoReply: Object API does not return MIME type, function API does
Date: Wed, 1 Feb 2017 17:37:52 +0100
To: "spam [...] mm.st via RT" <bug-MIME-Types [...] rt.cpan.org>
From: Mark Overmeer <mark [...] overmeer.net>
* spam@mm.st via RT (bug-MIME-Types@rt.cpan.org) [170201 15:41]: Show quoted text
> Queue: MIME-Types > Ticket <URL: https://rt.cpan.org/Ticket/Display.html?id=120065 > > > this works: > my ($type, $enc) = MIME::Types::by_suffix($filename); > > this returns null instead: > my $mt = MIME::Types->new; > my $type = $mt->mimeTypeOf($filename);
How do you test for 'null'? (Perl does not have 'null') What is the filename you actually use? Which MIME::Types version? $ perl -Ilib -MMIME::Types -we 'print MIME::Types::by_suffix("a.gif")' image/gif $ perl -Ilib -MMIME::Types -we 'print MIME::Types->new->mimeTypeOf("a.gif")' image/gif Probably something else is disturbing your output -- Regards, MarkOv ------------------------------------------------------------------------ Mark Overmeer MSc MARKOV Solutions Mark@Overmeer.net solutions@overmeer.net http://Mark.Overmeer.net http://solutions.overmeer.net
Subject: Re: [rt.cpan.org #120065] AutoReply: Object API does not return MIME type, function API does
Date: Thu, 2 Feb 2017 15:18:39 +0100
To: bug-MIME-Types [...] rt.cpan.org
From: spam [...] mm.st
Hello, the "null" term I incorrectly used is referred actually to a void string, sorry for the loose terminology. I probably found the reason of this strange behavior, seems that it is due to the fact that the mimeTypeOf method returns a string and not an object when called in scalar context, I didn't read the documentation carefully (my bad) and thought the return type of this method to be always a string. The module I use for web output ( https://metacpan.org/pod/JSONP ) sets up a different context thus the strange behavior. You can find a demo of the behavior illustrated by the little test script below (I reported its output as well). Not sure if this can be deemed as an actual "bug" of MIME::Types. SCRIPT # cat testMIMETypes #!/usr/bin/perl use lib '/var/www/perl_modules'; use UseLib; # this must be the first module to load, because it sets additional custom module source libs use MIME::Types; use JSONP; use Data::Dumper; use v5.10; my $filename = 'test.jpg'; my $mt = MIME::Types->new; my $ootype = $mt->mimeTypeOf($filename); say "OO API: $ootype"; my ($type, $enc) = MIME::Types::by_suffix($filename); say "F API: $type"; my $j = JSONP->new->debug; $j->test->type = $ootype; $j->test->control = 'control string'; say $j->test->serialize; say Dumper $ootype; TEST OUTPUT # ./testMIMETypes OO API: image/jpeg F API: image/jpeg {"type":null,"control":"control string"} $VAR1 = bless( { 'MT_encoding' => 'base64', 'MT_extensions' => [ 'jpeg', 'jpg', 'jpe', 'jfif', 'jfif-tbnl' ], 'MT_simplified' => 'image/jpeg', 'MT_type' => 'image/jpeg' }, 'MIME::Type' );
Subject: Re: [rt.cpan.org #120065] AutoReply: Object API does not return MIME type, function API does
Date: Thu, 2 Feb 2017 15:34:16 +0100
To: "spam [...] mm.st via RT" <bug-MIME-Types [...] rt.cpan.org>
From: Mark Overmeer <mark [...] overmeer.net>
* spam@mm.st via RT (bug-MIME-Types@rt.cpan.org) [170202 14:19]: Show quoted text
> Queue: MIME-Types > Ticket <URL: https://rt.cpan.org/Ticket/Display.html?id=120065 > > > Hello, > > the "null" term I incorrectly used is referred actually to a void > string, sorry for the loose terminology.
The JSON "null" is Perl's "undef" "Void" is a term we use in the context of execution context. Show quoted text
> I probably found the reason of this strange behavior, seems that it is > due to the fact that the mimeTypeOf method returns a string and not an > object when called in scalar context,
In any context mimeTypeOf() with return a MIME::Type object. This object is overloaded to stringify into a type string, and JSONP may not understand overloading (it uses some XS) Show quoted text
> I didn't read the documentation > carefully (my bad) and thought the return type of this method to be > always a string.
Show quoted text
> my $ootype = $mt->mimeTypeOf($filename); > my ($type, $enc) = MIME::Types::by_suffix($filename); > > $j->test->type = $ootype;
You probably want to write: $j->test->type = "$ootype"; # explicitly stringify, work around bug in JSONP $j->test->type = $type; # via the old interface -- Success, MarkOv ------------------------------------------------------------------------ Mark Overmeer MSc MARKOV Solutions Mark@Overmeer.net solutions@overmeer.net http://Mark.Overmeer.net http://solutions.overmeer.net
Subject: Re: [rt.cpan.org #120065] AutoReply: Object API does not return MIME type, function API does
Date: Thu, 2 Feb 2017 15:48:58 +0100
To: bug-MIME-Types [...] rt.cpan.org
From: spam [...] mm.st
Hello, yep, JSON null is from Perl undef. I am very curious about the stringify mechanism but wasn't able to understand at all where it happens on your source code. Many thanks for prompt support!
Not a bug