Wrapper/Disposal.pm

filter: Statementstmt 41.3% 19 / 46 Branchbran 0.0% 0 / 10 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 50.0% 6 / 12 Podpod 0.0% 0 / 6 totaltotal 33.7% 25 / 74 CC 8 SCAR 20.7
CC
8
Cov
34%
set_record
20.0
get_record
12.0
new
6.0
CRAP 7.9
« Wrapper.pm ↑ Summary Wrapper/RecordMapping.pm »
1 ##############################################################################
2 #
3 # Copyright (C) 2012 Agile Business Group sagl (<http://www.agilebg.com>)
4 # Copyright (C) 2012 Domsense srl (<http://www.domsense.com>)
5 # Copyright (C) 2012 Associazione OpenERP Italia
6 # (<http://www.openerp-italia.org>).
7 # Copyright (C) 2022 Res Binaria Di Paolo Capaldo(<https://www.resbinaria.com/>)
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 <http://www.gnu.org/licenses/>.
22 #
23 ##############################################################################
24  
25 package CBI::Wrapper::Disposal;
26  
27 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
28 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
29  
30 # ABSTRACT: CBI Disposal.
31 # 1 disposal <=> n records.
32  
33 1 ▶use CBI::Wrapper::Record;
Subroutine BEGIN: called CC=1 SCAR=0.0
34 1 ▶use CBI::Wrapper::RecordMapping;
Subroutine BEGIN: called CC=1 SCAR=0.0
35 # libscalar-list-utils-perl in debian.
36 1 ▶use Scalar::Util;
Subroutine BEGIN: called CC=1 SCAR=0.0
37 # croak.
38 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
39  
40 0 ▶sub new {
Subroutine new: not called CC=2 SCAR=17.9
Pod undocumented
41 0 my $class = shift;
42 0 my $self = {
43 _records => shift, # arrayref (see Record.pm).
44 };
45  
46 0 bless $self, $class;
47  
48 0 ▶ $self->set_records([]) unless defined $self->get_records();
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->get_records 0 0 0
49  
50 0 return $self;
51 }
52  
53 # Getters and Setters
54  
55 0 ▶sub set_records {
Subroutine set_records: not called CC=1 SCAR=6.9
Pod undocumented
56 0 my ( $self, $records) = @_;
57  
58 0 $self->{_records} = $records;
59 }
60  
61 0 ▶sub get_records {
Subroutine get_records: not called CC=1 SCAR=6.9
Pod undocumented
62 0 my ( $self) = @_;
63  
64 0 return $self->{_records};
65 }
66  
67 0 ▶sub set_record {
Subroutine set_record: not called CC=4 SCAR=30.0
Pod undocumented
68 0 my( $self, $key, $item) = @_;
69  
70 # Type check.
71 0 ▶ unless (Scalar::Util::blessed($item) eq 'CBI::Wrapper::Record') {
Branch: 1 branch
BranchTrueFalseTotal
unless (builtin::blessed($item) eq "CBI::Wrapper::Record") 0 0 0
72 0 croak('[TypeError] You can only write Record objects');
73 }
74  
75 0 for my $record (@{$self->get_records()}) {
76 0 ▶ $record = $item if $record->get_field_content('tipo_record') eq $key;
Branch: 1 branch
BranchTrueFalseTotal
if $record->get_field_content("tipo_record") eq $key 0 0 0
77 0 croak('[IndexError] Impossible to find field with key ' . $key);
78 }
79 }
80  
81 0 ▶sub get_record {
Subroutine get_record: not called CC=3 SCAR=24.8
Pod undocumented
82 0 my( $self, $key) = @_;
83 0 for my $record (@{$self->get_records()}) {
84 0 ▶ return $record if $record->get_field_content('tipo_record') eq $key;
Branch: 1 branch
BranchTrueFalseTotal
if $record->get_field_content("tipo_record") eq $key 0 0 0
85 }
86 0 croak('[IndexError] Impossible to find record ' . $key);
87 }
88  
89 # Add record to disposal.
90 0 ▶sub append_record {
Subroutine append_record: not called CC=2 SCAR=17.9
Pod undocumented
91 0 my( $self, $item) = @_;
92  
93 # Type check.
94 0 ▶ unless (Scalar::Util::blessed($item) eq 'CBI::Wrapper::Record') {
Branch: 1 branch
BranchTrueFalseTotal
unless (builtin::blessed($item) eq "CBI::Wrapper::Record") 0 0 0
95 0 croak('[TypeError] You can only write Record objects');
96 }
97  
98 0 my $records = $self->get_records();
99 0 push(@$records, $item);
100 0 $self->set_records($records);
101 }
102  
103 1 1;
« Wrapper.pm ↑ Summary Wrapper/RecordMapping.pm »