Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WL: Merge in mimetype_isa from Role::MimeInfo? #33

Open
doriantaylor opened this issue Mar 21, 2018 · 2 comments
Open

WL: Merge in mimetype_isa from Role::MimeInfo? #33

doriantaylor opened this issue Mar 21, 2018 · 2 comments

Comments

@doriantaylor
Copy link

Hello,

Some time ago I wrote a Moo(se) Role that added some recursive behaviour to mimetype_isa. This was a very quick-and-dirty solution at the time, in order to obviate cutting and pasting the same couple dozen lines of code. Of course, not everything is suitable to be written in Moo(se).

As such I am wondering if you're interested in accepting a patch. I decided on this overture rather than going and diving straight into a pull request because I want some input beforehand:

The behaviour of my mimetype_isa is such that it returns true if the $type and $parent are the same, and will likewise return true if either $type or $parent is an alias or deprecated type identifier, as well as if $parent is not an immediate ancestor of $type. These cases (since last I checked) all return false in File::MimeInfo.

Anyway, since this behaviour is significantly different, I'm wondering if it would make sense to patch in a mimetype_isa_deep or add a flag to mimetype_isa to switch on this behaviour.

That is—of course—if you're interested in the offer.

@mbeijen
Copy link
Owner

mbeijen commented Mar 26, 2018

In my opinion a third parameter to mimetype_isa would be a nice option.

Can you give a few examples of actual parameters and their result to this function?

We then could also use those for the documentation.

@doriantaylor
Copy link
Author

doriantaylor commented Mar 26, 2018

The proposal is to change the behaviour of mimetype_isa to try harder to answer whether type A isa type B, so the third option would just be a flag to turn that on:

# recursion
mimetype_isa('application/xhtml+xml', 'text/plain'); # false
mimetype_isa('application/xhtml+xml', 'text/plain', 1); # true

# aliases
mimetype_isa('application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', 'application/x-zip-compressed'); # false
mimetype_isa('application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', 'application/x-zip-compressed', 1); # true

This is the default behaviour of the wrapper I wrote in Role::MimeInfo. I wrote that thing because I found myself writing the same routines over and over with File::MimeInfo to normalize content types (e.g. from the wild) and compare them recursively.

One use case in particular is testing a claimed MIME type (e.g. from a Content-Type header or derived from a file extension) against the contents of a file or HTTP upload to see if the claimed type is at least as specific as the detected one. I do this in my own work in a number of places.

It makes sense that this functionality be universal and not just in a Moo(se) role, but of course there are probably systems that depend on the current behaviour of mimetype_isa exactly as it is.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants