line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
############################################################################## |
2
|
|
|
|
|
|
|
# |
3
|
|
|
|
|
|
|
# Copyright (C) 2012 Agile Business Group sagl () |
4
|
|
|
|
|
|
|
# Copyright (C) 2012 Domsense srl () |
5
|
|
|
|
|
|
|
# Copyright (C) 2012 Associazione OpenERP Italia |
6
|
|
|
|
|
|
|
# (). |
7
|
|
|
|
|
|
|
# Copyright (C) 2022 Res Binaria Di Paolo Capaldo () |
8
|
|
|
|
|
|
|
# All Rights Reserved |
9
|
|
|
|
|
|
|
# |
10
|
|
|
|
|
|
|
# This program is free software: you can redistribute it and/or modify |
11
|
|
|
|
|
|
|
# it under the terms of the GNU Affero General Public License as published |
12
|
|
|
|
|
|
|
# by the Free Software Foundation, either version 3 of the License, or |
13
|
|
|
|
|
|
|
# (at your option) any later version. |
14
|
|
|
|
|
|
|
# |
15
|
|
|
|
|
|
|
# This program is distributed in the hope that it will be useful, |
16
|
|
|
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
17
|
|
|
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
18
|
|
|
|
|
|
|
# GNU Affero General Public License for more details. |
19
|
|
|
|
|
|
|
# |
20
|
|
|
|
|
|
|
# You should have received a copy of the GNU Affero General Public License |
21
|
|
|
|
|
|
|
# along with this program. If not, see . |
22
|
|
|
|
|
|
|
# |
23
|
|
|
|
|
|
|
############################################################################## |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
package CBI::Wrapper::Record; |
26
|
|
|
|
|
|
|
|
27
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
27
|
|
28
|
1
|
|
|
1
|
|
4
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
17
|
|
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
# ABSTRACT: Row in a CBI file. |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
|
33
|
1
|
|
|
1
|
|
344
|
use CBI::Wrapper::Field; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
25
|
|
34
|
1
|
|
|
1
|
|
456
|
use CBI::Wrapper::RecordMapping; |
|
1
|
|
|
|
|
10
|
|
|
1
|
|
|
|
|
30
|
|
35
|
1
|
|
|
1
|
|
6
|
use Scalar::Util; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
39
|
|
36
|
1
|
|
|
1
|
|
4
|
use Carp; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
903
|
|
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub new { |
39
|
0
|
|
|
0
|
0
|
|
my $class = shift; |
40
|
0
|
|
|
|
|
|
my $self = { |
41
|
|
|
|
|
|
|
_raw_record => shift, |
42
|
|
|
|
|
|
|
_flow_type => shift, # see RecordMapping.pm. |
43
|
|
|
|
|
|
|
_fields => [], |
44
|
|
|
|
|
|
|
_code => '', # Record code (see RecordMapping.pm). |
45
|
|
|
|
|
|
|
}; |
46
|
|
|
|
|
|
|
|
47
|
0
|
|
|
|
|
|
bless $self, $class; |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
# Check row length. |
50
|
0
|
0
|
0
|
|
|
|
if (length($self->get_raw_record()) == 2 or length($self->get_raw_record()) == 120) { |
51
|
0
|
|
|
|
|
|
$self->set_code($self->get_raw_record()); |
52
|
|
|
|
|
|
|
} else { |
53
|
0
|
|
|
|
|
|
croak('[TypeError] String (' . $self->get_raw_record() . ') must contain 2 or 120 chars'); |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
|
57
|
0
|
0
|
|
|
|
|
$self->set_code($self->get_raw_record()) if length($self->get_code()) == 2; |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
|
60
|
0
|
0
|
|
|
|
|
$self->set_code(substr($self->get_raw_record(), 1, 2)) if length($self->get_code()) == 120; |
61
|
|
|
|
|
|
|
|
62
|
0
|
0
|
|
|
|
|
my $flow_type = defined $self->get_flow_type() ? $self->get_flow_type() : $CBI::Wrapper::RecordMapping::FLOW_TYPE; |
63
|
|
|
|
|
|
|
|
64
|
0
|
|
|
|
|
|
$self->set_flow_type($CBI::Wrapper::RecordMapping::RECORD_MAPPING->{$flow_type}); |
65
|
|
|
|
|
|
|
|
66
|
0
|
|
|
|
|
|
$flow_type = $self->get_flow_type(); |
67
|
0
|
0
|
|
|
|
|
unless (exists $flow_type->{$self->get_code()}) { |
68
|
0
|
|
|
|
|
|
croak('[IndexError] Unknown record type ' . $self->get_code()); |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
# Fields creation. |
73
|
0
|
|
|
|
|
|
for my $field_args (@{$flow_type->{$self->get_code()}}) { |
|
0
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
|
75
|
0
|
|
|
|
|
|
my $new_field = new CBI::Wrapper::Field($field_args); |
76
|
|
|
|
|
|
|
|
77
|
0
|
0
|
|
|
|
|
if ($new_field->get_type() eq 'tipo_record') { |
78
|
0
|
|
|
|
|
|
$new_field->set_content($self->get_code()); |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
0
|
|
|
|
|
|
$self->append_field($new_field); |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
0
|
0
|
|
|
|
|
$self->insert_fields_content($self->get_raw_record()) if length($self->get_raw_record()) == 120; |
85
|
|
|
|
|
|
|
|
86
|
0
|
|
|
|
|
|
return $self; |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
sub set_raw_record { |
90
|
0
|
|
|
0
|
0
|
|
my ($self, $raw_record) = @_; |
91
|
|
|
|
|
|
|
|
92
|
0
|
|
|
|
|
|
$self->{_raw_record} = $raw_record; |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
sub get_raw_record { |
96
|
0
|
|
|
0
|
0
|
|
my ($self) = @_; |
97
|
|
|
|
|
|
|
|
98
|
0
|
|
|
|
|
|
return $self->{_raw_record}; |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
sub set_flow_type { |
102
|
0
|
|
|
0
|
0
|
|
my ($self, $flow_type) = @_; |
103
|
|
|
|
|
|
|
|
104
|
0
|
|
|
|
|
|
$self->{_flow_type} = $flow_type; |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
sub get_flow_type { |
108
|
0
|
|
|
0
|
0
|
|
my ($self) = @_; |
109
|
|
|
|
|
|
|
|
110
|
0
|
|
|
|
|
|
return $self->{_flow_type}; |
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
sub set_code { |
114
|
0
|
|
|
0
|
0
|
|
my ($self, $code) = @_; |
115
|
|
|
|
|
|
|
|
116
|
0
|
|
|
|
|
|
$self->{_code} = $code; |
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
sub get_code { |
120
|
0
|
|
|
0
|
0
|
|
my ($self) = @_; |
121
|
|
|
|
|
|
|
|
122
|
0
|
|
|
|
|
|
return $self->{_code}; |
123
|
|
|
|
|
|
|
} |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
sub set_fields { |
126
|
0
|
|
|
0
|
0
|
|
my ($self, $fields) = @_; |
127
|
|
|
|
|
|
|
|
128
|
0
|
|
|
|
|
|
$self->{_fields} = $fields; |
129
|
|
|
|
|
|
|
} |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
sub get_fields { |
132
|
0
|
|
|
0
|
0
|
|
my ($self) = @_; |
133
|
|
|
|
|
|
|
|
134
|
0
|
|
|
|
|
|
return $self->{_fields}; |
135
|
|
|
|
|
|
|
} |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
# Set a string in content. |
138
|
|
|
|
|
|
|
# The key param can be: |
139
|
|
|
|
|
|
|
# 1. arrayref with start and end column (es. [1,3]). |
140
|
|
|
|
|
|
|
# 2. name of the field |
141
|
|
|
|
|
|
|
sub set_field_content { |
142
|
0
|
|
|
0
|
0
|
|
my ($self, $key, $content) = @_; |
143
|
|
|
|
|
|
|
|
144
|
0
|
0
|
|
|
|
|
if (ref $key eq 'ARRAY') { |
145
|
0
|
|
|
|
|
|
for my $field (@{$self->get_fields()}) { |
|
0
|
|
|
|
|
|
|
146
|
0
|
0
|
0
|
|
|
|
if ($field->get_from_position() == $key->[0] and $field->get_to_position() == $key->[1]) { |
147
|
0
|
|
|
|
|
|
$field->set_content($content); |
148
|
0
|
|
|
|
|
|
return; |
149
|
|
|
|
|
|
|
} |
150
|
|
|
|
|
|
|
} |
151
|
0
|
|
|
|
|
|
croak('[IndexError] Impossible to find field with position ' . $key->[0] . ', ' . $key->[1]); |
152
|
|
|
|
|
|
|
} else { |
153
|
0
|
|
|
|
|
|
for my $field (@{$self->get_fields()}) { |
|
0
|
|
|
|
|
|
|
154
|
0
|
0
|
|
|
|
|
if ($field->get_name() eq $key) { |
155
|
|
|
|
|
|
|
#say STDERR $field->get_name() . ' - ' . $content; |
156
|
0
|
|
|
|
|
|
$field->set_content($content); |
157
|
0
|
|
|
|
|
|
return; |
158
|
|
|
|
|
|
|
} |
159
|
|
|
|
|
|
|
} |
160
|
|
|
|
|
|
|
} |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
#use Data::Dumper; |
163
|
|
|
|
|
|
|
#say STDOUT 'SELF'. Dumper($self->{_fields}); |
164
|
0
|
|
|
|
|
|
croak('[IndexError] Impossible to find field with key ' . $key); |
165
|
|
|
|
|
|
|
} |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
# Get a string from a field in the current record. |
168
|
|
|
|
|
|
|
# The key param can be: |
169
|
|
|
|
|
|
|
# 1. arrayref with start and end column (es. [1,3]). |
170
|
|
|
|
|
|
|
# 2. name of the field |
171
|
|
|
|
|
|
|
sub get_field_content { |
172
|
0
|
|
|
0
|
0
|
|
my ($self, $key) = @_; |
173
|
0
|
0
|
|
|
|
|
if (ref $key eq 'ARRAY') { |
174
|
0
|
|
|
|
|
|
return substr($self->to_string(), $key->[0], $key->[1]); |
175
|
|
|
|
|
|
|
} else { |
176
|
0
|
|
|
|
|
|
for my $field (@{$self->get_fields()}) { |
|
0
|
|
|
|
|
|
|
177
|
0
|
0
|
|
|
|
|
if ($field->get_name() eq $key) { |
178
|
0
|
|
|
|
|
|
my $ret = $field->get_content(); |
179
|
0
|
|
|
|
|
|
$ret =~ s/^\s+|\s+$//g; |
180
|
0
|
|
|
|
|
|
return $ret; |
181
|
|
|
|
|
|
|
} |
182
|
|
|
|
|
|
|
} |
183
|
0
|
|
|
|
|
|
croak('[IndexError] Impossible to find field with key ' . $key); |
184
|
|
|
|
|
|
|
} |
185
|
|
|
|
|
|
|
} |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
sub append_field { |
189
|
0
|
|
|
0
|
0
|
|
my ($self, $field) = @_; |
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
# Type check |
192
|
0
|
0
|
|
|
|
|
unless (Scalar::Util::blessed($field) eq 'CBI::Wrapper::Field') { |
193
|
0
|
|
|
|
|
|
croak('[TypeError] You can only append Field objects'); |
194
|
|
|
|
|
|
|
} |
195
|
|
|
|
|
|
|
|
196
|
0
|
|
|
|
|
|
for my $f (@{$self->get_fields()}) { |
|
0
|
|
|
|
|
|
|
197
|
0
|
0
|
|
|
|
|
if ($f->get_name() eq $field->get_name()) { |
198
|
0
|
|
|
|
|
|
croak('[IndexError] Field name ' . $field->get_name() . ' already present'); |
199
|
|
|
|
|
|
|
} |
200
|
|
|
|
|
|
|
} |
201
|
|
|
|
|
|
|
|
202
|
0
|
|
|
|
|
|
my $fields = $self->get_fields(); |
203
|
0
|
|
|
|
|
|
push(@$fields, $field); |
204
|
0
|
|
|
|
|
|
$self->set_fields($fields); |
205
|
|
|
|
|
|
|
} |
206
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
sub insert_fields_content { |
208
|
0
|
|
|
0
|
0
|
|
my ($self, $raw_record) = @_; |
209
|
|
|
|
|
|
|
|
210
|
0
|
|
|
|
|
|
for my $field (@{$self->get_fields()}) { |
|
0
|
|
|
|
|
|
|
211
|
0
|
|
|
|
|
|
my $from_position = $field->get_from_position() - 1; |
212
|
0
|
|
|
|
|
|
my $to_position = $field->get_to_position(); |
213
|
0
|
|
|
|
|
|
$to_position -= $from_position; |
214
|
0
|
|
|
|
|
|
$field->set_content(substr($raw_record, $from_position, $to_position)); |
215
|
|
|
|
|
|
|
} |
216
|
|
|
|
|
|
|
} |
217
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
# Convert to string (row in CBI file). |
219
|
|
|
|
|
|
|
sub to_string { |
220
|
0
|
|
|
0
|
0
|
|
my ($self) = @_; |
221
|
0
|
|
|
|
|
|
my $c = ''; |
222
|
0
|
|
|
|
|
|
for my $field (@{$self->get_fields()}) { |
|
0
|
|
|
|
|
|
|
223
|
0
|
|
|
|
|
|
$c .= $field->get_content(); |
224
|
|
|
|
|
|
|
} |
225
|
0
|
|
|
|
|
|
return $c; |
226
|
|
|
|
|
|
|
} |
227
|
|
|
|
|
|
|
|
228
|
|
|
|
|
|
|
1; |
229
|
|
|
|
|
|
|
|