File::T...:Builder(3)

🌸 NAME 🌸

okay so bestie, this is the File::T...:Builder(3) page from User Contributed Perl Documentation. The header's got that abbreviated title energy, and the actual module is File::Type::Builder, doing exactly this: parse mime-magic and generate code. That's the whole vibe. πŸ’…

✨ SYNOPSIS ✨

Like, here's the demo from the page, literally:

           my $build = File::Type::Builder->new();

           while (<magic>) {
             chomp;
             my $parsed = $build->parse_magic($_);

             my $code   = $build->string_start($parsed);
             (or string_offset or beshort)
           }

Yes, the (or string_offset or beshort) line is literally in the synopsis. Not me editing, I promise. 😭

πŸ’– DESCRIPTION πŸ’–

It reads in the mime-magic file format and translates it to code. And the original doc says, quote: "(This documentation would be longer if I really expected anyone other than me to run the code.)" β€” honestly, same energy. 😭

🧚 METHODS 🧚

πŸŽ€ new πŸŽ€

Creates a new File::Type::Builder object. Constructor slay, no cap. ✨

πŸ¦‹ parse_magic πŸ¦‹

Pulls apart a line of a mime-magic file using a string of regular expressions. Regex goblin mode activated. πŸ’…

An example mime-magic file can be found in cleancode CVS at http://cleancode.org/cgi-bin/viewcvs.cgi/email/mime-magic.mime?rev=1.1.1.1

🌈 string 🌈

Builds code to match magic that's of type string. It has to do some cleverness to make the regular expression work properly. The way regex needs a little styling to behave β€” iconic. πŸ”₯

πŸ‘‘ be πŸ‘‘

Builds code to match 'beshort' and 'belong' magic (eg audio/mpeg, image/jpeg). That be method is doing its thing, iykyk. ✨

πŸ”’ PRIVATE METHODS πŸ”’

🫢 _substr_matching 🫢

Sometimes the data is smaller than the offset we're looking for in the file. If this is the case, then the file is obviously not of that type, and furthermore we should avoid issuing a couple of warnings that Perl would otherwise emit. πŸ’€

This subroutine generates this code. Periodt.

πŸ“ _get_escapes πŸ“

Returns a reference to a hash defining characters that should not be escaped. Very "know which characters are safe" of it. πŸŽ€

πŸ“ TODO πŸ“

  • Add handlers for other magic types (bedate, byte, etc)
  • Make verbosity/logging nicer.
  • Find more edge cases.
  • Remove redundant 'if (length $data > 0)' check.

Longer term:

  • Fix for multiple magic format types?

πŸ’€ BUGS πŸ’€

Incomplete. Some known issues with odd entries in mime-magic. Skips some mime-magic lines. Not the vibe, but honest. πŸ™ˆ

🌟 SEE ALSO 🌟

File::Type, which is partially generated by this module. Go give it a look, bestie. πŸ’–

πŸ’Œ AUTHOR πŸ’Œ

Paul Mison <pmison@fotango.com> β€” king behavior. πŸ‘‘

Copyright 2003 Fotango Ltd.

πŸ“œ LICENSE πŸ“œ

Licensed under the same terms as Perl itself.


and that's the whole page! footer source/version + date: perl v5.42.0, 2010-11-30, and the footer title File::T...:Builder(3). byeee, go parse some mime-magic. πŸ«ΆπŸ’–βœ¨

πŸ“¦ where this page comes from