Yes, I forced File::MMagic->new() and printed what was returned from checktype_contents(). It is invariably application/octet-stream which makes me think that the reference to the system magic file has been lost between the time I constructed a new MMagic object and it is used (although I dumped the object variable and that shows the same address).

My version is 1.27 like yours, Perl is v5.14.4.

Here is part of my initialisation code. As you can see, I have commented out references to magic files (the system file name is passed through hash member 'magicmime' while a fall-back file exists in the private library lib. The initial part of the file to test is read-in separately before calling one of the two functions defined in the "configuration" hash.

my $magic = File::MMagic->new ( # -f $self->{'magicmime'} # ? $self->{'magicmime'} # : -f 'lib/magic.mime' ? 'lib/magic +.mime' : () ); $self->{'&discard'} = sub { 'text/' ne substr($magic->checktype_co +ntents(@_[0]), 0, 5) }; # Same, to return the complete MIME type $self->{'&mimetype'} = sub {$magic->checktype_contents(@_[0])};

Function &discard seems to work fine (at least it returns true on text files). Function &mimetype returns either text/plain or application/octet-stream on my test files.

I may have made a big mistake in my code as I'm using a non-scope variable binding for $magic: when the functions are called, the block containing my $magic has disappeared for a long time.


In reply to Re^2: File::MMagic returns application/octet-stream for most files by ajlittoz
in thread File::MMagic returns application/octet-stream for most files by ajlittoz

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.