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 Β©οΈ
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
- opensuse-leap 16.0: perl-File-Type 0.22-bp160.147.11 Β· Artistic-1.0
- opensuse-leap 16.0: perl-File-Type 0.22-bp160.147.11 Β· Artistic-1.0
- opensuse-leap 16.0: perl-File-Type 0.22-bp160.147.11 Β· Artistic-1.0
- opensuse-leap 16.0: perl-File-Type 0.22-bp160.147.11 Β· Artistic-1.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms