Tools.pm

filter: Statementstmt 85.9% 49 / 57 Branchbran 41.6% 10 / 24 Conditioncond 63.6% 7 / 11 MC/DCmcdc 14.2% 1 / 7 Subroutinesub 86.6% 13 / 15 Podpod 30.0% 3 / 10 totaltotal 66.9% 83 / 124 CC 17 SCAR 13.9
CC
17
Cov
72%
usage
7.6
config
6.0
quiet
6.0
CRAP 4.0
« Words.pm ↑ Summary Head.pm »
1 package MIME::Tools;
2  
3 #------------------------------
4 # Because the POD documentation is pretty extensive, it follows
5 # the __END__ statement below...
6 #------------------------------
7  
8 44 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 44 ▶use vars (qw(@ISA %CONFIG @EXPORT_OK %EXPORT_TAGS $VERSION $ME
Subroutine BEGIN: called CC=1 SCAR=0.0
10 44 $M_DEBUG $M_WARNING $M_ERROR ));
11  
12 44 require Exporter;
13 44 ▶use IO::File;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 44 ▶use File::Temp 0.18 ();
Subroutine BEGIN: called CC=1 SCAR=0.0
15 44 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 44 $ME = "MIME-tools";
18  
19 44 @ISA = qw(Exporter);
20  
21 # Exporting (importing should only be done by modules in this toolkit!):
22 44 %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 44 Exporter::export_ok_tags('config', 'msgs', 'msgtypes', 'utils');
29  
30 # The TOOLKIT version, both in 1.23 style *and* usable by MakeMaker:
31 44 $VERSION = "5.522";
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 44 %CONFIG =
36 (
37 DEBUGGING => 0,
38 QUIET => 1,
39 );
40  
41 # Message-logging constants:
42 44 $M_DEBUG = 'debug';
43 44 $M_WARNING = 'warning';
44 44 $M_ERROR = 'error';
45  
46  
47  
48 #------------------------------
49 #
50 # CONFIGURATION... (see below)
51 #
52 #------------------------------
53  
54 0 ▶sub config {
Subroutine config: not called CC=2 SCAR=17.9
Pod undocumented
55 0 my $class = shift;
56 0 usage("config() is obsolete");
57  
58 # No args? Just return list:
59 0 ▶ @_ or return keys %CONFIG;
Branch: 1 branch
BranchTrueFalseTotal
@_ or return keys %MIME::Tools::CONFIG 0 0 0
60 0 my $method = lc(shift);
61 0 return $class->$method(@_);
62 }
63  
64 28060 ▶sub debugging {
Subroutine debugging: called CC=2 SCAR=7.1
Pod documented
65 28060 my ($class, $value) = @_;
66 28060 ▶ $CONFIG{'DEBUGGING'} = $value if (@_ > 1);
Branch: 1 branch
BranchTrueFalseTotal
if @_ > 1 0 28060 28060
67 28060 return $CONFIG{'DEBUGGING'};
68 }
69  
70 0 ▶sub quiet {
Subroutine quiet: not called CC=2 SCAR=17.9
Pod documented
71 0 my ($class, $value) = @_;
72 0 ▶ $CONFIG{'QUIET'} = $value if (@_ > 1);
Branch: 1 branch
BranchTrueFalseTotal
if @_ > 1 0 0 0
73 0 return $CONFIG{'QUIET'};
74 }
75  
76 27 ▶sub version {
Subroutine version: called CC=1 SCAR=0.0
Pod documented
77 27 my ($class, $value) = @_;
78 27 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 117 ▶sub debug {
Subroutine debug: called CC=2 SCAR=7.6
Pod undocumented
97 117 ▶ print STDERR "$ME: $M_DEBUG: ", @_, "\n" if $CONFIG{DEBUGGING};
Branch: 1 branch
BranchTrueFalseTotal
if $MIME::Tools::CONFIG{"DEBUGGING"} 0 117 117
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 31 ▶sub whine {
Subroutine whine: called CC=4 SCAR=14.9
Pod undocumented
109 31 my $msg = "$ME: $M_WARNING: ".join('', @_)."\n";
110 31 ▶ warn $msg if ($^W && !$CONFIG{QUIET});
Branch: 1 branch
BranchTrueFalseTotal
if $^W and not $MIME::Tools::CONFIG{"QUIET"} 0 31 31
Condition66%2/3
$^W and not $MIME::Tools::CONFIG{"QUIET"}
!ll&&!rl&&r
5260
MC/DC0%0/2
$^W and not $MIME::Tools::CONFIG{"QUIET"}
$^W not $MIME::Tools::CONFIG{"QUIET"}
Truth table66%2/3
A and not(B)
A= $^WB= not $MIME::Tools::CONFIG{"QUIET"}
ABresult
0X0
100
111
111 31 ▶ return (wantarray ? () : undef);
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 31 31
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 114 ▶sub error {
Subroutine error: called CC=4 SCAR=14.9
Pod undocumented
124 114 my $msg = "$ME: $M_ERROR: ".join('', @_)."\n";
125 114 ▶ warn $msg if ($^W && !$CONFIG{QUIET});
Branch: 1 branch
BranchTrueFalseTotal
if $^W and not $MIME::Tools::CONFIG{"QUIET"} 0 114 114
Condition66%2/3
$^W and not $MIME::Tools::CONFIG{"QUIET"}
!ll&&!rl&&r
103110
MC/DC0%0/2
$^W and not $MIME::Tools::CONFIG{"QUIET"}
$^W not $MIME::Tools::CONFIG{"QUIET"}
Truth table66%2/3
A and not(B)
A= $^WB= not $MIME::Tools::CONFIG{"QUIET"}
ABresult
0X0
100
111
126 114 ▶ return (wantarray ? () : undef);
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 114 114
127 }
128  
129 #------------------------------
130 #
131 # usage MESSAGE...
132 #
133 # Register unhappiness about usage.
134 #
135 3 ▶sub usage {
Subroutine usage: called CC=6 SCAR=20.3
Pod undocumented
136 3 my ( $p, $f, $l, $s) = caller(1);
137 3 my ($cp, $cf, $cl, $cs) = caller(2);
138 3 ▶ my $msg = join('', (($s =~ /::/) ? "$s() " : "${p}::$s() "), @_, "\n");
Branch: 1 branch
BranchTrueFalseTotal
$s =~ /::/ ? : 3 0 3
139 3 ▶ my $loc = ($cf ? "\tin code called from $cf l.$cl" : '');
Branch: 1 branch
BranchTrueFalseTotal
$cf ? : 0 3 3
140  
141 3 ▶ warn "$msg$loc\n" if ($^W && !$CONFIG{QUIET});
Branch: 1 branch
BranchTrueFalseTotal
if $^W and not $MIME::Tools::CONFIG{"QUIET"} 0 3 3
Condition33%1/3
$^W and not $MIME::Tools::CONFIG{"QUIET"}
!ll&&!rl&&r
030
MC/DC0%0/2
$^W and not $MIME::Tools::CONFIG{"QUIET"}
$^W not $MIME::Tools::CONFIG{"QUIET"}
Truth table33%1/3
A and not(B)
A= $^WB= not $MIME::Tools::CONFIG{"QUIET"}
ABresult
0X0
100
111
142 3 ▶ return (wantarray ? () : undef);
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 3 3
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 2260 ▶sub textual_type {
Subroutine textual_type: called CC=1 SCAR=0.0
Pod undocumented
160 2260 ($_[0] =~ m{^(text|message)(/|\Z)}i);
161 }
162  
163 #------------------------------
164 #
165 # tmpopen
166 #
167 #
168 sub tmpopen
169 2145 ▶{
Subroutine tmpopen: called CC=2 SCAR=6.9
Pod undocumented
170 2145 my ($args) = @_;
171 2145 ▶ $args ||= {};
Condition100%2/2
$args ||= {}
l!l
21396
MC/DC100%1/1
$args ||= {}
$args
Truth table100%2/2
A
A= $args
Aresult
11
00
172 2145 return File::Temp->new( %{$args} );
173 }
174  
175 #------------------------------
176 44 1;
177 __END__
« Words.pm ↑ Summary Head.pm »