line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package MIME::Tools; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
#------------------------------ |
4
|
|
|
|
|
|
|
# Because the POD documentation is pretty extensive, it follows |
5
|
|
|
|
|
|
|
# the __END__ statement below... |
6
|
|
|
|
|
|
|
#------------------------------ |
7
|
|
|
|
|
|
|
|
8
|
28
|
|
|
28
|
|
118608
|
use strict; |
|
28
|
|
|
|
|
60
|
|
|
28
|
|
|
|
|
934
|
|
9
|
28
|
|
|
|
|
3321
|
use vars (qw(@ISA %CONFIG @EXPORT_OK %EXPORT_TAGS $VERSION $ME |
10
|
28
|
|
|
28
|
|
144
|
$M_DEBUG $M_WARNING $M_ERROR )); |
|
28
|
|
|
|
|
51
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
require Exporter; |
13
|
28
|
|
|
28
|
|
9295
|
use IO::File; |
|
28
|
|
|
|
|
119466
|
|
|
28
|
|
|
|
|
4129
|
|
14
|
28
|
|
|
28
|
|
31009
|
use File::Temp 0.18 (); |
|
28
|
|
|
|
|
414477
|
|
|
28
|
|
|
|
|
812
|
|
15
|
28
|
|
|
28
|
|
249
|
use Carp; |
|
28
|
|
|
|
|
63
|
|
|
28
|
|
|
|
|
21340
|
|
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
$ME = "MIME-tools"; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
@ISA = qw(Exporter); |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
# Exporting (importing should only be done by modules in this toolkit!): |
22
|
|
|
|
|
|
|
%EXPORT_TAGS = ( |
23
|
|
|
|
|
|
|
'config' => [qw(%CONFIG)], |
24
|
|
|
|
|
|
|
'msgs' => [qw(usage debug whine error)], |
25
|
|
|
|
|
|
|
'msgtypes'=> [qw($M_DEBUG $M_WARNING $M_ERROR)], |
26
|
|
|
|
|
|
|
'utils' => [qw(textual_type tmpopen )], |
27
|
|
|
|
|
|
|
); |
28
|
|
|
|
|
|
|
Exporter::export_ok_tags('config', 'msgs', 'msgtypes', 'utils'); |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
# The TOOLKIT version, both in 1.23 style *and* usable by MakeMaker: |
31
|
|
|
|
|
|
|
$VERSION = "5.507"; |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
# Configuration (do NOT alter this directly)... |
34
|
|
|
|
|
|
|
# All legal CONFIG vars *must* be in here, even if only to be set to undef: |
35
|
|
|
|
|
|
|
%CONFIG = |
36
|
|
|
|
|
|
|
( |
37
|
|
|
|
|
|
|
DEBUGGING => 0, |
38
|
|
|
|
|
|
|
QUIET => 1, |
39
|
|
|
|
|
|
|
); |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
# Message-logging constants: |
42
|
|
|
|
|
|
|
$M_DEBUG = 'debug'; |
43
|
|
|
|
|
|
|
$M_WARNING = 'warning'; |
44
|
|
|
|
|
|
|
$M_ERROR = 'error'; |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
#------------------------------ |
49
|
|
|
|
|
|
|
# |
50
|
|
|
|
|
|
|
# CONFIGURATION... (see below) |
51
|
|
|
|
|
|
|
# |
52
|
|
|
|
|
|
|
#------------------------------ |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub config { |
55
|
0
|
|
|
0
|
0
|
0
|
my $class = shift; |
56
|
0
|
|
|
|
|
0
|
usage("config() is obsolete"); |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
# No args? Just return list: |
59
|
0
|
0
|
|
|
|
0
|
@_ or return keys %CONFIG; |
60
|
0
|
|
|
|
|
0
|
my $method = lc(shift); |
61
|
0
|
|
|
|
|
0
|
return $class->$method(@_); |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
sub debugging { |
65
|
1524
|
|
|
1524
|
1
|
2248
|
my ($class, $value) = @_; |
66
|
1524
|
50
|
|
|
|
3088
|
$CONFIG{'DEBUGGING'} = $value if (@_ > 1); |
67
|
1524
|
|
|
|
|
5364
|
return $CONFIG{'DEBUGGING'}; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
sub quiet { |
71
|
0
|
|
|
0
|
1
|
0
|
my ($class, $value) = @_; |
72
|
0
|
0
|
|
|
|
0
|
$CONFIG{'QUIET'} = $value if (@_ > 1); |
73
|
0
|
|
|
|
|
0
|
return $CONFIG{'QUIET'}; |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
sub version { |
77
|
22
|
|
|
22
|
1
|
38
|
my ($class, $value) = @_; |
78
|
22
|
|
|
|
|
128
|
return $VERSION; |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
#------------------------------ |
84
|
|
|
|
|
|
|
# |
85
|
|
|
|
|
|
|
# MESSAGES... |
86
|
|
|
|
|
|
|
# |
87
|
|
|
|
|
|
|
#------------------------------ |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
#------------------------------ |
90
|
|
|
|
|
|
|
# |
91
|
|
|
|
|
|
|
# debug MESSAGE... |
92
|
|
|
|
|
|
|
# |
93
|
|
|
|
|
|
|
# Function, private. |
94
|
|
|
|
|
|
|
# Output a debug message. |
95
|
|
|
|
|
|
|
# |
96
|
|
|
|
|
|
|
sub debug { |
97
|
48
|
50
|
|
48
|
0
|
576
|
print STDERR "$ME: $M_DEBUG: ", @_, "\n" if $CONFIG{DEBUGGING}; |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
#------------------------------ |
101
|
|
|
|
|
|
|
# |
102
|
|
|
|
|
|
|
# whine MESSAGE... |
103
|
|
|
|
|
|
|
# |
104
|
|
|
|
|
|
|
# Function, private. |
105
|
|
|
|
|
|
|
# Something doesn't look right: issue a warning. |
106
|
|
|
|
|
|
|
# Only output if $^W (-w) is true, and we're not being QUIET. |
107
|
|
|
|
|
|
|
# |
108
|
|
|
|
|
|
|
sub whine { |
109
|
28
|
|
|
28
|
0
|
147
|
my $msg = "$ME: $M_WARNING: ".join('', @_)."\n"; |
110
|
28
|
50
|
66
|
|
|
191
|
warn $msg if ($^W && !$CONFIG{QUIET}); |
111
|
28
|
50
|
|
|
|
102
|
return (wantarray ? () : undef); |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
#------------------------------ |
115
|
|
|
|
|
|
|
# |
116
|
|
|
|
|
|
|
# error MESSAGE... |
117
|
|
|
|
|
|
|
# |
118
|
|
|
|
|
|
|
# Function, private. |
119
|
|
|
|
|
|
|
# Something failed, but not so badly that we want to throw an |
120
|
|
|
|
|
|
|
# exception. Just report our general unhappiness. |
121
|
|
|
|
|
|
|
# Only output if $^W (-w) is true, and we're not being QUIET. |
122
|
|
|
|
|
|
|
# |
123
|
|
|
|
|
|
|
sub error { |
124
|
7
|
|
|
7
|
0
|
173
|
my $msg = "$ME: $M_ERROR: ".join('', @_)."\n"; |
125
|
7
|
50
|
33
|
|
|
57
|
warn $msg if ($^W && !$CONFIG{QUIET}); |
126
|
7
|
50
|
|
|
|
24
|
return (wantarray ? () : undef); |
127
|
|
|
|
|
|
|
} |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
#------------------------------ |
130
|
|
|
|
|
|
|
# |
131
|
|
|
|
|
|
|
# usage MESSAGE... |
132
|
|
|
|
|
|
|
# |
133
|
|
|
|
|
|
|
# Register unhappiness about usage. |
134
|
|
|
|
|
|
|
# |
135
|
|
|
|
|
|
|
sub usage { |
136
|
3
|
|
|
3
|
0
|
17
|
my ( $p, $f, $l, $s) = caller(1); |
137
|
3
|
|
|
|
|
7
|
my ($cp, $cf, $cl, $cs) = caller(2); |
138
|
3
|
50
|
|
|
|
16
|
my $msg = join('', (($s =~ /::/) ? "$s() " : "${p}::$s() "), @_, "\n"); |
139
|
3
|
50
|
|
|
|
7
|
my $loc = ($cf ? "\tin code called from $cf l.$cl" : ''); |
140
|
|
|
|
|
|
|
|
141
|
3
|
50
|
33
|
|
|
20
|
warn "$msg$loc\n" if ($^W && !$CONFIG{QUIET}); |
142
|
3
|
50
|
|
|
|
11
|
return (wantarray ? () : undef); |
143
|
|
|
|
|
|
|
} |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
#------------------------------ |
148
|
|
|
|
|
|
|
# |
149
|
|
|
|
|
|
|
# UTILS... |
150
|
|
|
|
|
|
|
# |
151
|
|
|
|
|
|
|
#------------------------------ |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
#------------------------------ |
154
|
|
|
|
|
|
|
# |
155
|
|
|
|
|
|
|
# textual_type MIMETYPE |
156
|
|
|
|
|
|
|
# |
157
|
|
|
|
|
|
|
# Function. Does the given MIME type indicate a textlike document? |
158
|
|
|
|
|
|
|
# |
159
|
|
|
|
|
|
|
sub textual_type { |
160
|
195
|
|
|
195
|
0
|
1294
|
($_[0] =~ m{^(text|message)(/|\Z)}i); |
161
|
|
|
|
|
|
|
} |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
#------------------------------ |
164
|
|
|
|
|
|
|
# |
165
|
|
|
|
|
|
|
# tmpopen |
166
|
|
|
|
|
|
|
# |
167
|
|
|
|
|
|
|
# |
168
|
|
|
|
|
|
|
sub tmpopen |
169
|
|
|
|
|
|
|
{ |
170
|
103
|
|
|
103
|
0
|
183
|
my ($args) = @_; |
171
|
103
|
|
100
|
|
|
258
|
$args ||= {}; |
172
|
103
|
|
|
|
|
136
|
return File::Temp->new( %{$args} ); |
|
103
|
|
|
|
|
897
|
|
173
|
|
|
|
|
|
|
} |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
#------------------------------ |
176
|
|
|
|
|
|
|
1; |
177
|
|
|
|
|
|
|
__END__ |