blib/lib/oEdtk/Spool.pm

filter: Statementstmt 23.5% 12 / 51 Branchbran 0.0% 0 / 22 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 60.0% 3 / 5 Podpod 100% 2 / 2 totaltotal 20.0% 17 / 85 CC 13 SCAR 44.7
CC
13
Cov
16%
parse
132.0
new
12.0
BEGIN
1.0
CRAP 87.7
« lib/oEdtk/EDMS.pm ↑ Summary blib/lib/oEdtk/SchemaScan.pm »
1 package oEdtk::Spool;
2  
3 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 2 ▶use oEdtk::Main 0.42;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 2 our $VERSION = 2.1131;
9  
10 # The maximum number of characters we emit before inserting
11 # a newline.
12 2 my $LINE_CUTOFF = 85;
13  
14 0 ▶sub new {
Subroutine new: not called CC=3 SCAR=24.8
Pod documented
15 0 my ( $class, $in, $out ) = @_;
16  
17 0 ▶ my $self = {
Branch: 2 branches
BranchTrueFalseTotal
ref $in eq 'GLOB' ? : 0 0 0
ref $out eq 'GLOB' ? : 0 0 0
18 input => ref($in) eq 'GLOB' ? $in : \*STDIN,
19 output => ref($out) eq 'GLOB' ? $out : \*STDOUT,
20 emitted => 0
21 };
22 0 bless $self, $class;
23 0 return $self;
24 }
25  
26 # Input stream format, line by line.
27 #
28 # The first four characters of the line determine the case.
29 #
30 # case 1:
31 # /^(\d{3}) (.*)$/
32 #
33 # $1 = resource
34 # $2 = data
35 #
36 # case 2, inside a resource:
37 # /^ (\d)(.*)$/
38 #
39 # $1 = channel jump
40 # $2 = data
41 0 ▶sub parse {
Subroutine parse: not called CC=11 SCAR=48.8
Pod documented
42 0 my $self = shift;
43 0 my $processfn = shift;
44 0 my $fh = $self->{'input'};
45  
46 0 $self->{'XCORP'} = oe_corporation_get();
47  
48 # Read the input file line by line.
49 0 ▶ while ( my $line = <$fh> ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $line = readline $fh)) 0 0 0
50 0 chomp($line);
51  
52 0 ▶ if ( length $line == 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $line == 0) 0 0 0
53 0 warn "INFO: line $. is empty\n";
54 0 next;
55 }
56  
57 # Get the first four characters.
58 0 ▶ die "ERROR: unexpected line format: \"$line\" at line $.\n"
Branch: 1 branch
BranchTrueFalseTotal
unless $line =~ /^(.{3})([0-9+\- ]?)(.*)$/ 0 0 0
59 unless $line =~ /^(.{3})([0-9+\- ]?)(.*)$/;
60 0 my ( $header, $jump, $data ) = ( $1, $2, $3 );
61  
62 # PROBLEM, on 2 lines like the ones below
63 #026 *** LAURIANE 20/09/1984 01 REFERENCES DECOMPTE: 07/01/2009RO181 0002*
64 # 2 *** MAELENN 02/12/1993 11 REFERENCES DECOMPTE: 30/12/2008RO422 0002*
65 # jump must not be empty in the first case, otherwise $data has 1 more character the first time; in the second case it has one character less
66 # which shifts the splitting in the main application
67  
68 # Introduce a technical prefix line, used only to populate state
69 #004 EDT XCORP M0001
70  
71 0 ▶ if ( $header =~ /^[0-9a-zA-Z]{3}$/ ) { # Case number 1.
Branch: 2 branches
BranchTrueFalseTotal
if ($header =~ /^[0-9a-zA-Z]{3}$/) { } 0 0 0
elsif ($header eq ' ') { } 0 0 0
72 0 $self->{'prev_inres'} = $self->{'inres'};
73 0 $self->{'inres'} = $header;
74 0 $self->{'jump'} = $jump;
75  
76 0 ▶ if ( $data =~ /^\s{1,13}EDT XCORP/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($data =~ /^\s{1,13}EDT XCORP/) { } 0 0 0
77  
78 # warn "EDT XCORP >$data<\n";
79 # Reinitialize the state. > EDT XCORP M0001<
80 0 $self->{'numln'} = 0;
81 0 $self->{'jumpln'} = 0;
82  
83 # TODO: handle states in pairs:
84 # EDT XCORP VALUE STATE2 VALUE2 STATE3 VALUE3 etc.
85 0 $data =~ s/^(\s{1,13}EDT\s)(.*)/$2/;
86 0 ▶ while ($data) {
Branch: 1 branch
BranchTrueFalseTotal
if ($data) 0 0 0
87 0 $data =~ s/^([\w\d]+)\s([\w\d]+)\s*(.*)/$3/;
88 0 $self->{$1} = $2;
89 }
90  
91 # warn "EDT XCORP >$data<\n " . $self->{'XCORP'}. "\n";
92 0 next;
93  
94 }
95 else {
96 # Reinitialize the state.
97 0 $self->{'numln'} = 1;
98 0 $self->{'jumpln'} = 1;
99 }
100  
101 # Reinitialize the state.
102 0 $self->{'state'} = {};
103 0 $processfn->( $self, $data );
104  
105 }
106 elsif ( $header eq ' ' ) {
107 0 $self->{'jump'} = $jump;
108 0 ▶ if ( !defined $self->{'inres'} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"inres"}) 0 0 0
109 0 die "ERROR: got seal while not in a resource at line $.\n";
110 }
111 0 $self->{'numln'}++;
112 0 ▶ if ( defined($jump) && $jump =~ /\d/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $jump and $jump =~ /\d/) 0 0 0
Condition0%0/3
defined $jump and $jump =~ /\d/
!ll&&!rl&&r
000
MC/DC0%0/2
defined $jump and $jump =~ /\d/
defined $jump $jump =~ /\d/
Truth table0%0/3
A and B
A= defined $jumpB= $jump =~ /\d/
ABresult
0X0
100
111
113 0 $self->{'jumpln'} += $self->{'jump'};
114 }
115 0 $processfn->( $self, $data );
116 }
117 else {
118 0 die "ERROR: unexpected line header: \"$header$jump\" at line $.\n";
119 }
120 }
121 }
122  
123 2 1;
124  
125 __END__
« lib/oEdtk/EDMS.pm ↑ Summary blib/lib/oEdtk/SchemaScan.pm »