Parser/Results.pm

filter: Statementstmt 86.6% 26 / 30 Branchbran 75.0% 6 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 80.0% 8 / 10 Podpod 62.5% 5 / 8 totaltotal 80.3% 45 / 56 CC 5 SCAR 5.4
CC
5
Cov
84%
level
2.0
msg
2.0
errors
2.0
CRAP 1.7
« Decoder/Binary.pm ↑ Summary Field/ConTraEnc.pm »
1 package MIME::Parser::Results;
2  
3 =head1 NAME
4  
5 MIME::Parser::Results - results of the last entity parsed
6  
7  
8 =head1 SYNOPSIS
9  
10 Before reading further, you should see L<MIME::Parser> to make sure that
11 you understand where this module fits into the grand scheme of things.
12 Go on, do it now. I'll wait.
13  
14 Ready? Ok...
15  
16 ### Do parse, get results:
17 my $entity = eval { $parser->parse(\*STDIN); };
18 my $results = $parser->results;
19  
20 ### Get all messages logged:
21 @msgs = $results->msgs;
22  
23 ### Get messages of specific types (also tests if there were problems):
24 $had_errors = $results->errors;
25 $had_warnings = $results->warnings;
26  
27 ### Get outermost header:
28 $top_head = $results->top_head;
29  
30  
31 =head1 DESCRIPTION
32  
33 Results from the last MIME::Parser parse.
34  
35  
36 =head1 PUBLIC INTERFACE
37  
38 =over 4
39  
40 =cut
41  
42 26 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
43  
44 ### Kit modules:
45 26 ▶use MIME::Tools qw(:msgs);
Subroutine BEGIN: called CC=1 SCAR=0.0
46  
47  
48 #------------------------------
49  
50 =item new
51  
52 I<Constructor.>
53  
54 =cut
55  
56 95 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod documented
57 95 bless {
58 MPI_ID => 'MIME-parser',
59 MPI_Msgs => [],
60 MPI_Level => 0,
61 MPI_TopHead => undef,
62 }, shift;
63 }
64  
65 #------------------------------
66  
67 =item msgs
68  
69 I<Instance method.>
70 Return all messages that we logged, in order.
71 Every message is a string beginning with its type followed by C<": ">;
72 the current types are C<debug>, C<warning>, and C<error>.
73  
74 =cut
75  
76 1 ▶sub msgs {
Subroutine msgs: called CC=1 SCAR=0.0
Pod documented
77 1 @{shift->{MPI_Msgs}};
78 }
79  
80 #------------------------------
81  
82 =item errors
83  
84 I<Instance method.>
85 Return all error messages that we logged, in order.
86 A convenience front-end onto msgs().
87  
88 =cut
89  
90 0 ▶sub errors {
Subroutine errors: not called CC=1 SCAR=6.9
Pod documented
91 0 grep /^error: /, @{shift->{MPI_Msgs}};
92 }
93  
94 #------------------------------
95  
96 =item warnings
97  
98 I<Instance method.>
99 Return all warning messages that we logged, in order.
100 A convenience front-end onto msgs().
101  
102 =cut
103  
104 0 ▶sub warnings {
Subroutine warnings: not called CC=1 SCAR=6.9
Pod documented
105 0 grep /^warning: /, @{shift->{MPI_Msgs}};
106 }
107  
108 #------------------------------
109  
110 =item top_head
111  
112 I<Instance method.>
113 Return the topmost header, if we were able to read it.
114 This may be useful if the parse fails.
115  
116 =cut
117  
118 4067 ▶sub top_head {
Subroutine top_head: called CC=2 SCAR=6.9
Pod documented
119 4067 my ($self, $head) = @_;
120 4067 ▶ $self->{MPI_TopHead} = $head if @_ > 1;
Branch: 1 branch
BranchTrueFalseTotal
if @_ > 1 94 3973 4067
121 4067 $self->{MPI_TopHead};
122 }
123  
124  
125  
126  
127 #------------------------------
128 #
129 # PRIVATE: FOR USE DURING PARSING ONLY!
130 #
131  
132 #------------------------------
133 #
134 # msg TYPE, MESSAGE...
135 #
136 # Take a message.
137 #
138 132 ▶sub msg {
Subroutine msg: called CC=2 SCAR=7.0
Pod undocumented
139 132 my $self = shift;
140 132 my $type = shift;
141 132 ▶ my @args = map { defined($_) ? $_ : '<<undef>>' } @_;
Branch: 1 branch
BranchTrueFalseTotal
defined $_ ? : 274 0 274
142  
143 132 push @{$self->{MPI_Msgs}}, ($type.": ".join('', @args)."\n");
144 }
145  
146 #------------------------------
147 #
148 # level [+1|-1]
149 #
150 # Return current parsing level.
151 #
152 7384 ▶sub level {
Subroutine level: called CC=2 SCAR=7.1
Pod undocumented
153 7384 my ($self, $lvl) = @_;
154 7384 ▶ $self->{MPI_Level} += $lvl if @_ > 1;
Branch: 1 branch
BranchTrueFalseTotal
if @_ > 1 7384 0 7384
155 7384 $self->{MPI_Level};
156 }
157  
158 #------------------------------
159 #
160 # indent
161 #
162 # Return indent for current parsing level.
163 #
164 132 ▶sub indent {
Subroutine indent: called CC=2 SCAR=6.9
Pod undocumented
165 132 my ($self) = @_;
166 132 my $level = $self->{MPI_Level};
167 132 ▶ $level = 16 if $level > 16; # keep each message short at any depth
Branch: 1 branch
BranchTrueFalseTotal
if $level > 16 87 45 132
168 132 ' ' x $level;
169 }
170  
171 =back
172  
173 =cut
174  
175 26 1;
176 __END__
« Decoder/Binary.pm ↑ Summary Field/ConTraEnc.pm »