[Dancer-users] mime types

Oleg A. Mamontov oleg at mamontov.net
Thu Feb 10 17:01:24 CET 2011


On Feb 10, 2011, at 6:45 PM, ambs wrote:

> Hi,
> 
> On 10/02/2011 15:37, Oleg A. Mamontov wrote:
> 
>> After some debugging i found that MIME::Types (used in Dancer::MIME)
>> read and parse mime types from it DATA handle.
>> This handle is opening by Perl during module load procedure. But subsequent
>> reads occured in&MIME::Types::init (which called from constructor).
> 
> Yes, that's my code. The problem with DATA is that if I request a rewind on the file handle I get to the beginning of the Perl file. Also, that would need to be fixed directly on the module that, probably, we do not have access.
You can't rewind position pointer anyway, cause of concurrently (non-atomic)
readline operations :(

> 
>> 1. Remove MIME::Types from Dancer::MIME completely :)
> 
> This would lead to the need of replicating some of the code. Although Dancer folks try to minimize the number of dependencies I try to convince them to minimize the amount of proprietary code that is already available on other modules :)
>> 
>> 2. Explicitly call&MIME::Types::init early (before fork):
>> 
>>    package Dancer::MIME;
>>    use strict;
>>    use warnings;
>>    use base 'Dancer::Object::Singleton';
>>    use MIME::Types;
>> 
>>    MIME::Types->init;
>> 
>> 3. Use MIME::Types later (in&Dancer::MIME::init):
>> 
>>    sub init {
>>      my ($class, $instance) = @_;
>>      eval "use MIME::Types";
>>      $instance->mime_type(MIME::Types->new(only_complete =>  1));
>>      $instance->aliases({});
>>    }
> 
> Did you try both solutions? Personally I prefer the first one and I'm happy to prepare the patch on git.

Yes and preffer the first one too :)
But drawback of this solution is loss of lazy initialization.
On my iMac this is + ~30ms to Dancer startup.


> 
> Cheers
> ambs
> _______________________________________________
> Dancer-users mailing list
> Dancer-users at perldancer.org
> http://www.backup-manager.org/cgi-bin/listinfo/dancer-users


-- 
Cheers,
Oleg A. Mamontov

mailto:  oleg at mamontov.net

jabber:  lonerr at charla.mamontov.net
icq uin: 79-521-617
cell:    +7-903-798-1352



More information about the Dancer-users mailing list