.\" -*- mode: troff; coding: utf-8 -*- .\" Automatically generated by Pod::Man 5.0102 (Pod::Simple 3.45) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>. .ie n \{\ . ds C` "" . ds C' "" 'br\} .el\{\ . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "File::Type::Builder 3" .TH File::Type::Builder 3 2024-09-01 "perl v5.40.0" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH NAME File::Type::Builder \- parse mime\-magic and generate code .SH SYNOPSIS .IX Header "SYNOPSIS" .Vb 1 \& my $build = File::Type::Builder\->new(); \& \& while () { \& chomp; \& my $parsed = $build\->parse_magic($_); \& \& my $code = $build\->string_start($parsed); \& (or string_offset or beshort) \& } .Ve .SH DESCRIPTION .IX Header "DESCRIPTION" Reads in the mime-magic file format and translates it to code. (This documentation would be longer if I really expected anyone other than me to run the code.) .SH METHODS .IX Header "METHODS" .SS new .IX Subsection "new" Creates a new File::Type::Builder object. .SS parse_magic .IX Subsection "parse_magic" Pulls apart a line of a mime-magic file using a string of regular expressions. .PP An example mime-magic file can be found in cleancode CVS at .SS string .IX Subsection "string" Builds code to match magic that's of type string. .PP Has to do some cleverness to make the regular expression work properly. .SS be .IX Subsection "be" Builds code to match 'beshort' and 'belong' magic (eg audio/mpeg, image/jpeg). .SH "PRIVATE METHODS" .IX Header "PRIVATE METHODS" .SS _substr_matching .IX Subsection "_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. .PP This subroutine generates this code. .SS _get_escapes .IX Subsection "_get_escapes" Returns a reference to a hash defining characters that should not be escaped. .SH TODO .IX Header "TODO" .RS 4 * Add handlers for other magic types (bedate, byte, etc) .Sp * Make verbosity/logging nicer. .Sp * Find more edge cases. .Sp * Remove redundant 'if (length \f(CW$data\fR > 0)' check. .RE .PP Longer term: .Sp .RS 4 * Fix for multiple magic format types? .RE .SH BUGS .IX Header "BUGS" Incomplete. Some known issues with odd entries in mime-magic. Skips some mime-magic lines. .SH "SEE ALSO" .IX Header "SEE ALSO" File::Type, which is partially generated by this module. .SH AUTHOR .IX Header "AUTHOR" Paul Mison .SH COPYRIGHT .IX Header "COPYRIGHT" Copyright 2003 Fotango Ltd. .SH LICENSE .IX Header "LICENSE" Licensed under the same terms as Perl itself.