Box/Parser.pm

filter: Statementstmt 59.2% 45 / 76 Branchbran 25.0% 5 / 20 Conditioncond 25.0% 2 / 8 MC/DCmcdc 0.0% 0 / 5 Subroutinesub 48.1% 13 / 27 Podpod 95.2% 20 / 21 totaltotal 54.1% 85 / 157 SCAR 36.5
CC
14
Cov
50%
fileChanged
20.0
defaultParserType
12.4
restart
6.0
CRAP 38.5
« Message/Field/Attribute.pm ↑ Summary Reporter.pm »
1 # Copyrights 2001-2023 by [Mark Overmeer <markov@cpan.org>].
2 # For other contributors see ChangeLog.
3 # See the manual pages for details on the licensing terms.
4 # Pod stripped from pm file by OODoc 2.03.
5 # This code is part of distribution Mail-Message. Meta-POD processed with
6 # OODoc into POD and HTML manual-pages. See README.md
7 # Copyright Mark Overmeer. Licensed under the same terms as Perl itself.
8  
9 package Mail::Box::Parser;
10 39 ▶use vars '$VERSION';
Subroutine BEGIN: called CC=1 SCAR=0.0
11 39 $VERSION = '3.013';
12  
13 39 ▶use base 'Mail::Reporter';
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 39 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 39 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 39 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20  
21 sub new(@)
22 12 ▶{ my $class = shift;
Subroutine new: called CC=2 SCAR=7.2
Pod documented
23  
24 12 ▶ $class eq __PACKAGE__
Branch: 1 branch
BranchTrueFalseTotal
$class eq __PACKAGE__ ? : 0 12 12
25 ? $class->defaultParserType->new(@_) # bootstrap right parser
26 : $class->SUPER::new(@_);
27 }
28  
29 sub init(@)
30 12 ▶{ my ($self, $args) = @_;
Subroutine init: called CC=4 SCAR=16.6
Pod undocumented
31  
32 #warn "PARSER type=".ref $self,$self->VERSION;
33 12 $self->SUPER::init($args);
34  
35 12 ▶ $self->{MBP_mode} = $args->{mode} || 'r';
Condition50%1/2
$args->{'mode'} || 'r'
l!l
012
MC/DC0%0/1
$args->{'mode'} || 'r'
$args->{'mode'}
Truth table50%1/2
A
A= $args->{'mode'}
Aresult
11
00
36  
37 12 ▶ unless($self->{MBP_filename} = $args->{filename} || ref $args->{file})
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"MBP_filename"} = $args->{"filename"} || ref $args->{"file"}) 0 12 12
Condition33%1/3
$args->{'filename'} || ref $args->{'file'}
l!l&&r!l&&!r
1200
MC/DC0%0/2
$args->{'filename'} || ref $args->{'file'}
$args->{'filename'} ref $args->{'file'}
Truth table33%1/3
A || B
A= $args->{'filename'}B= ref $args->{'file'}
ABresult
1X1
011
000
38 0 { $self->log(ERROR => "Filename or handle required to create a parser.");
39 0 return;
40 }
41  
42 12 $self->start(file => $args->{file});
43 }
44  
45 #------------------------------------------
46  
47  
48 sub start(@)
49 12 ▶{ my $self = shift;
Subroutine start: called CC=2 SCAR=7.0
Pod documented
50 12 my %args = (@_, filename => $self->filename, mode => $self->{MBP_mode});
51  
52 12 ▶ $self->openFile(\%args)
Branch: 1 branch
BranchTrueFalseTotal
$self->openFile(\%args) or return 0 12 12
53 or return;
54  
55 12 $self->takeFileInfo;
56  
57 12 $self->log(PROGRESS => "Opened folder $args{filename} to be parsed");
58 12 $self;
59 }
60  
61 #------------------------------------------
62  
63  
64 sub stop()
65 24 ▶{ my $self = shift;
Subroutine stop: called CC=1 SCAR=0.0
Pod documented
66  
67 24 my $filename = $self->filename;
68  
69 # $self->log(WARNING => "File $filename changed during access.")
70 # if $self->fileChanged;
71  
72 24 $self->log(NOTICE => "Close parser for file $filename");
73 24 $self->closeFile;
74 }
75  
76  
77 sub restart()
78 0 ▶{ my $self = shift;
Subroutine restart: not called CC=2 SCAR=17.9
Pod documented
79 0 my $filename = $self->filename;
80  
81 0 $self->closeFile;
82 $self->openFile( {filename => $filename, mode => $self->{MBP_mode}} )
83 0 ▶ or return;
Branch: 1 branch
BranchTrueFalseTotal
$self->openFile({"filename", $filename, "mode", $self->{"MBP_mode"}}) or return 0 0 0
84  
85 0 $self->takeFileInfo;
86 0 $self->log(NOTICE => "Restarted parser for file $filename");
87 0 $self;
88 }
89  
90  
91 sub fileChanged()
92 0 ▶{ my $self = shift;
Subroutine fileChanged: not called CC=4 SCAR=30.0
Pod documented
93 0 my ($size, $mtime) = (stat $self->filename)[7,9];
94 0 ▶ return 0 if !defined $size || !defined $mtime;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $size and defined $mtime 0 0 0
Condition0%0/3
defined $size and defined $mtime
!ll&&!rl&&r
000
MC/DC0%0/2
defined $size and defined $mtime
defined $size defined $mtime
Truth table0%0/3
A and B
A= defined $sizeB= defined $mtime
ABresult
0X0
100
111
95 0 ▶ $size != $self->{MBP_size} || $mtime != $self->{MBP_mtime};
Branch: 1 branch
BranchTrueFalseTotal
$size != $self->{"MBP_size"} or $mtime != $self->{"MBP_mtime"} 0 0 0
96 }
97
98  
99 48 ▶sub filename() {shift->{MBP_filename}}
Subroutine filename: called CC=1 SCAR=0.0
Pod documented
100  
101 #------------------------------------------
102  
103  
104 0 ▶sub filePosition(;$) {shift->NotImplemented}
Subroutine filePosition: not called CC=1 SCAR=6.9
Pod documented
105  
106  
107 0 ▶sub pushSeparator($) {shift->notImplemented}
Subroutine pushSeparator: not called CC=1 SCAR=6.9
Pod documented
108  
109  
110 0 ▶sub popSeparator($) {shift->notImplemented}
Subroutine popSeparator: not called CC=1 SCAR=6.9
Pod documented
111  
112  
113 0 ▶sub readSeparator($) {shift->notImplemented}
Subroutine readSeparator: not called CC=1 SCAR=6.9
Pod documented
114  
115  
116 0 ▶sub readHeader() {shift->notImplemented}
Subroutine readHeader: not called CC=1 SCAR=6.9
Pod documented
117  
118  
119 0 ▶sub bodyAsString() {shift->notImplemented}
Subroutine bodyAsString: not called CC=1 SCAR=6.9
Pod documented
120  
121  
122 0 ▶sub bodyAsList() {shift->notImplemented}
Subroutine bodyAsList: not called CC=1 SCAR=6.9
Pod documented
123  
124  
125 0 ▶sub bodyAsFile() {shift->notImplemented}
Subroutine bodyAsFile: not called CC=1 SCAR=6.9
Pod documented
126  
127  
128 0 ▶sub bodyDelayed() {shift->notImplemented}
Subroutine bodyDelayed: not called CC=1 SCAR=6.9
Pod documented
129  
130  
131 0 ▶sub lineSeparator() {shift->{MBP_linesep}}
Subroutine lineSeparator: not called CC=1 SCAR=6.9
Pod documented
132  
133 #------------------------------------------
134  
135  
136 0 ▶sub openFile(@) {shift->notImplemented}
Subroutine openFile: not called CC=1 SCAR=6.9
Pod documented
137  
138  
139 0 ▶sub closeFile(@) {shift->notImplemented}
Subroutine closeFile: not called CC=1 SCAR=6.9
Pod documented
140  
141  
142 sub takeFileInfo()
143 12 ▶{ my $self = shift;
Subroutine takeFileInfo: called CC=1 SCAR=0.0
Pod documented
144 12 @$self{ qw/MBP_size MBP_mtime/ } = (stat $self->filename)[7,9];
145 }
146  
147  
148 39 my $parser_type;
149  
150 sub defaultParserType(;$)
151 1 ▶{ my $class = shift;
Subroutine defaultParserType: called CC=5 SCAR=25.2
Pod documented
152  
153 # Select the parser manually?
154 1 ▶ if(@_)
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 1 0 1
155 1 { $parser_type = shift;
156 1 ▶ return $parser_type if $parser_type->isa( __PACKAGE__ );
Branch: 1 branch
BranchTrueFalseTotal
if $parser_type->isa(__PACKAGE__) 1 0 1
157  
158 0 confess "Parser $parser_type does not extend "
159 . __PACKAGE__ . "\n";
160 }
161  
162 # Already determined which parser we want?
163 0 ▶ return $parser_type if $parser_type;
Branch: 1 branch
BranchTrueFalseTotal
if $parser_type 0 0 0
164  
165 # Try to use C-based parser.
166 0 eval 'require Mail::Box::Parser::C';
167 #warn "C-PARSER errors $@\n" if $@;
168  
169 0 ▶ return $parser_type = 'Mail::Box::Parser::C'
Branch: 1 branch
BranchTrueFalseTotal
unless $@ 0 0 0
170 unless $@;
171  
172 # Fall-back on Perl-based parser.
173 0 require Mail::Box::Parser::Perl;
174 0 $parser_type = 'Mail::Box::Parser::Perl';
175 }
176  
177 #------------------------------------------
178  
179  
180 sub DESTROY
181 12 ▶{ my $self = shift;
Subroutine DESTROY: called CC=1 SCAR=0.0
182 12 $self->stop;
183 12 $self->SUPER::DESTROY;
184 }
185  
186 39 1;
« Message/Field/Attribute.pm ↑ Summary Reporter.pm »