lib/Parse/AFP.pm

filter: Statementstmt 33.7% 27 / 80 Branchbran 11.1% 2 / 18 Conditioncond 20.0% 3 / 15 MC/DCmcdc 0.0% 0 / 8 Subroutinesub 61.5% 8 / 13 Podpod 0.0% 0 / 5 totaltotal 28.7% 40 / 139 CC 15 SCAR 25.8
CC
15
Cov
28%
callback_members
30.0
valid_unformat
20.0
tight_loop
20.0
CRAP 13.2
« blib/script/afpdump.pl ↑ Summary blib/script/udc4pca.pl »
1 package Parse::AFP;
2 1 $Parse::AFP::VERSION = '0.25';
3  
4 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use Encode::IBM;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use Encode::EBCDIC;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use base 'Parse::AFP::Base';
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use constant FORMAT => (
Subroutine BEGIN: called CC=1 SCAR=0.0
9 Record => ['H2 n/a* XX', '*', '2'],
10 1 );
11 1 ▶use constant BASE_CLASS => __PACKAGE__;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 # Must start with the magic byte 0x90
14 573 ▶sub valid_memberdata { $_[-1][0] eq '5a' }
Subroutine valid_memberdata: called CC=1 SCAR=0.0
Pod undocumented
15  
16 0 ▶sub valid_unformat {
Subroutine valid_unformat: not called CC=4 SCAR=30.0
Pod undocumented
17 0 my ($self, $content, $data) = @_;
18 0 ▶ return if $content->[0] ne '5a';
Branch: 1 branch
BranchTrueFalseTotal
if $content->[0] ne "5a" 0 0 0
19 0 my $members = $self->{callback_members};
20 0 my $table = Parse::AFP::Record->dispatch_table;
21 0 my $type = $table->{ unpack('H6', $content->[1]) };
22 0 ▶ if (!$members->{ $type } and my $fh = $self->output) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $members->{$type} and my $fh = $self->output) 0 0 0
Condition0%0/3
not $members->{$type} and my $fh = $self->output
!ll&&!rl&&r
000
MC/DC0%0/2
not $members->{$type} and my $fh = $self->output
not $members->{$type} my $fh = $self->output
Truth table0%0/3
not(A) and B
A= not $members->{$type}B= my $fh = $self->output
ABresult
0X0
100
111
23 0 print $fh $$data;
24 0 return;
25 }
26 0 return 1;
27 }
28  
29 0 ▶sub callback_members {
Subroutine callback_members: not called CC=5 SCAR=34.0
Pod undocumented
30 0 my $self = shift;
31 0 $self->{callback_members} = { map { ($_ => 1) } @{$_[0]} };
32  
33 0 ▶ if ($self->{callback_members}{'*'} and $self->{output} and $self->{input}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"callback_members"}{"*"} and $self->{"output"} and $self->{"input"}) 0 0 0
Condition0%0/6
$self->{"callback_members"}{"*"} and $self->{"output"} and $self->{"input"}
!ll&&!rl&&r
000
$self->{"callback_members"}{"*"} and $self->{"output"}
!ll&&!rl&&r
000
MC/DC0%0/3
$self->{"callback_members"}{"*"} and $self->{"output"} and $self->{"input"}
$self->{"callback_members"}{"*"} $self->{"output"} $self->{"input"}
Truth table0%0/4
A and B and C
A= $self->{"callback_members"}{"*"}B= $self->{"output"}C= $self->{"input"}
ABCresult
0XX0
10X0
1100
1111
34 0 return $self->tight_loop(@_);
35 }
36  
37 0 ▶ while (my $member = $self->next_member) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $member = $self->next_member) 0 0 0
38 0 $member->callback(scalar caller, @_);
39 }
40 }
41  
42 0 ▶sub _noop { return }
Subroutine _noop: not called CC=1 SCAR=6.9
43  
44 2 ▶sub read_file {
Subroutine read_file: called CC=5 SCAR=19.3
Pod undocumented
45 2 my ($self, $file) = @_;
46  
47 2 ▶ open my $fh, "< $file" or die "Cannot open $file for reading: $!";
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, "< $file" or die "Cannot open $file for reading: $!" 2 0 2
48 2 binmode($fh);
49  
50 2 ▶ if (ref($self) and $self->{lazy} and $self->{output_file}) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $self and $self->{"lazy"} and $self->{"output_file"}) 0 2 2
Condition50%3/6
ref $self and $self->{"lazy"} and $self->{"output_file"}
!ll&&!rl&&r
200
ref $self and $self->{"lazy"}
!ll&&!rl&&r
110
MC/DC0%0/3
ref $self and $self->{"lazy"} and $self->{"output_file"}
ref $self $self->{"lazy"} $self->{"output_file"}
Truth table50%2/4
A and B and C
A= ref $selfB= $self->{"lazy"}C= $self->{"output_file"}
ABCresult
0XX0
10X0
1100
1111
51 0 $self->{input} = $fh;
52 0 $self->set_output_file($self->{output_file});
53 0 return '';
54 }
55  
56 2 local $/;
57 2 return scalar <$fh>;
58 }
59  
60 0 ▶sub tight_loop {
Subroutine tight_loop: not called CC=4 SCAR=30.0
Pod undocumented
61 0 my $self = shift;
62 0 my $callback = caller(1);
63 0 my $ofh = $self->{output};
64 0 my $is_dirty;
65 0 my ($header, $buf);
66  
67 0 local *Parse::AFP::Record::done = \&_noop;
68 0 ▶ local *Parse::AFP::PTX::refresh_parent = sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
69 0 my $self = shift;
70 0 $self->refresh_length;
71 0 print $ofh $self->dump;
72 0 $is_dirty = 1;
73 0 };
74  
75 0 my %xable = Parse::AFP::Record::DISPATCH_TABLE();
76 0 my %table = reverse Parse::AFP::Record::DISPATCH_TABLE();
77 my %IgnoreType =
78 0 map { (pack('H6', $table{$_}) => 1) }
79 0 grep { !$self->{callback_members}{$_} }
80 keys %table;
81  
82 0 my $fh = $self->{input};
83 0 seek $fh, 0, 0;
84  
85 0 my $attr = { lazy => 1, output => $ofh };
86  
87 0 ▶ while (!eof($fh)) {
Branch: 1 branch
BranchTrueFalseTotal
if (not eof $fh) 0 0 0
88 0 read($fh, $header, 6);
89 0 seek $fh, -6, 1;
90 0 read($fh, $buf, (unpack('n', substr($header, 1, 2)) + 1));
91  
92 # We now cheat and skip unintereting types.
93 0 ▶ if (exists $IgnoreType{substr($header, -3)}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $IgnoreType{substr $header, -3}) 0 0 0
94 0 print $ofh $buf;
95 0 next;
96 }
97  
98 # Do Something Interesting with $header and $buf
99 0 $is_dirty = 0;
100  
101 0 my $rec = Parse::AFP::Record->new( \$buf, $attr );
102 0 $rec->callback($callback, @_, \$buf);
103  
104 0 $ofh = $self->{output};
105 0 ▶ print $ofh $buf unless $is_dirty;
Branch: 1 branch
BranchTrueFalseTotal
unless $is_dirty 0 0 0
106 0 next;
107 }
108 }
109  
110 1 1;
111  
112 __END__
« blib/script/afpdump.pl ↑ Summary blib/script/udc4pca.pl »