1File::Type::Builder(3)User Contributed Perl DocumentationFile::Type::Builder(3)
2
3
4

NAME

6       File::Type::Builder - parse mime-magic and generate code
7

SYNOPSIS

9           my $build = File::Type::Builder->new();
10
11           while (<magic>) {
12             chomp;
13             my $parsed = $build->parse_magic($_);
14
15             my $code   = $build->string_start($parsed);
16             (or string_offset or beshort)
17           }
18

DESCRIPTION

20       Reads in the mime-magic file format and translates it to code.  (This
21       documentation would be longer if I really expected anyone other than me
22       to run the code.)
23

METHODS

25   new
26       Creates a new File::Type::Builder object.
27
28   parse_magic
29       Pulls apart a line of a mime-magic file using a string of regular
30       expressions.
31
32       An example mime-magic file can be found in cleancode CVS at
33       http://cleancode.org/cgi-bin/viewcvs.cgi/email/mime-magic.mime?rev=1.1.1.1
34       <http://cleancode.org/cgi-bin/viewcvs.cgi/email/mime-
35       magic.mime?rev=1.1.1.1>
36
37   string
38       Builds code to match magic that's of type string.
39
40       Has to do some cleverness to make the regular expression work properly.
41
42   be
43       Builds code to match 'beshort' and 'belong' magic (eg audio/mpeg,
44       image/jpeg).
45

PRIVATE METHODS

47   _substr_matching
48       Sometimes the data is smaller than the offset we're looking for in the
49       file. If this is the case, then the file is obviously not of that type,
50       and furthermore we should avoid issuing a couple of warnings that Perl
51       would otherwise emit.
52
53       This subroutine generates this code.
54
55   _get_escapes
56       Returns a reference to a hash defining characters that should not be
57       escaped.
58

TODO

60           * Add handlers for other magic types (bedate, byte, etc)
61
62           * Make verbosity/logging nicer.
63
64           * Find more edge cases.
65
66           * Remove redundant 'if (length $data > 0)' check.
67
68       Longer term:
69
70           * Fix for multiple magic format types?
71

BUGS

73       Incomplete. Some known issues with odd entries in mime-magic. Skips
74       some mime-magic lines.
75

SEE ALSO

77       File::Type, which is partially generated by this module.
78

AUTHOR

80       Paul Mison <pmison@fotango.com>
81
83       Copyright 2003 Fotango Ltd.
84

LICENSE

86       Licensed under the same terms as Perl itself.
87
88
89
90perl v5.12.0                      2010-05-01            File::Type::Builder(3)
Impressum