Karmasphere/Parser/Base.pm

filter: Statementstmt 69.0% 38 / 55 Branchbran 50.0% 11 / 22 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 69.2% 9 / 13 Podpod 0.0% 0 / 7 totaltotal 59.7% 58 / 97 CC 13 SCAR 19.3
CC
13
Cov
64%
parse
14.4
warning
6.0
new
4.2
CRAP 6.9
« Karmasphere/Publisher.pm ↑ Summary Karmasphere/Parser/Record.pm »
1 package Mail::Karmasphere::Parser::Base;
2  
3 8 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 8 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 8 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 8 ▶use Mail::Karmasphere::Parser::Record;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 8 ▶use Carp qw(confess);
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 7 ▶sub new {
Subroutine new: called CC=4 SCAR=14.5
Pod undocumented
10 7 my $class = shift;
11 7 ▶ my $self = ($#_ == 0) ? { %{ (shift) } } : { @_ };
Branch: 1 branch
BranchTrueFalseTotal
$#_ == 0 ? : 7 0 7
12 7 ▶ die "No input mechanism (fh)" unless exists $self->{fh};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"fh"} 0 7 7
13 7 ▶ die "No stream metadata (Streams)" unless exists $self->{Streams};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"Streams"} 0 7 7
14 7 return bless $self, $class;
15 }
16  
17 0 ▶sub warning {
Subroutine warning: not called CC=2 SCAR=17.9
Pod undocumented
18 0 my $self = shift;
19 0 ▶ if (++$self->{Warnings} < 10) {
Branch: 1 branch
BranchTrueFalseTotal
if (++$self->{"Warnings"} < 10) 0 0 0
20 0 warn @_;
21 }
22 }
23  
24 0 ▶sub error {
Subroutine error: not called CC=1 SCAR=6.9
Pod undocumented
25 0 my $self = shift;
26 0 ++$self->{Errors};
27 0 die @_;
28 }
29  
30 135 ▶sub fh {
Subroutine fh: called CC=1 SCAR=0.0
Pod undocumented
31 135 return $_[0]->{fh};
32 }
33  
34 0 ▶sub _parse {
Subroutine _parse: not called CC=1 SCAR=6.9
35 0 die "Subclass must implement _parse routine";
36 }
37  
38 0 ▶sub streams {
Subroutine streams: not called CC=1 SCAR=6.9
Pod undocumented
39 0 return $_[0]->{Streams};
40 }
41  
42 63 ▶sub parse {
Subroutine parse: called CC=9 SCAR=26.7
Pod undocumented
43 63 my $self = shift;
44 63 ▶ return if $self->{Done};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"Done"} 0 63 63
45 RECORDS:
46 63 for (;;) {
47 # print STDERR "> > parsing...\n";
48 63 my @records = $self->_parse;
49 63 my @toreturn;
50 RECORD:
51 63 for my $record (@records) {
52 # print STDERR " > record: $record\n";
53 61 ▶ last RECORD unless defined $record;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $record 4 57 61
54 57 ▶ print Dumper($record) if $self->debug;
Branch: 1 branch
BranchTrueFalseTotal
if $self->debug 0 57 57
55 57 my $stream = $record->stream;
56 57 my $type = $self->{Streams}->[$stream];
57  
58 57 ▶ if (!defined $type) {
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $type) { } 0 57 57
elsif ($type ne $record->type) { } 0 57 57
59 0 $self->warning("Ignoring record: " .
60 "Invalid stream: " .
61 $stream);
62 0 next RECORDS;
63 }
64 elsif ($type ne $record->type) {
65 0 $self->warning("Ignoring record: " .
66 "Stream type mismatch: " .
67 "Expected $type, got " . $record->type .
68 ": " . $record->as_string);
69 0 next RECORDS;
70 }
71 else {
72 57 push @toreturn, $record;
73 }
74 }
75  
76 63 ▶ if (wantarray) {
Branch: 2 branches
BranchTrueFalseTotal
if (wantarray) { } 0 63 63
elsif (@toreturn <= 1) { } 63 0 63
77 0 return @toreturn;
78 }
79 elsif (@toreturn <= 1) {
80 63 return $toreturn[0];
81 }
82 else {
83 0 croak("Parser has @{[scalar @toreturn]} records to return, but parse() was called in scalar context");
84 }
85 }
86 0 $self->{Done} = 1;
87 0 return;
88 }
89  
90 78 ▶sub debug { $ENV{DEBUG} }
Subroutine debug: called CC=1 SCAR=0.0
Pod undocumented
91  
92 8 1;
« Karmasphere/Publisher.pm ↑ Summary Karmasphere/Parser/Record.pm »