| 1 | ############################################################################## | ||||||||||||||||||||||||||||
| 2 | # | ||||||||||||||||||||||||||||
| 3 | # Copyright (C) 2022 Res Binaria Di Paolo Capaldo (<https://www.resbinaria.com/>) | ||||||||||||||||||||||||||||
| 4 | # All Rights Reserved | ||||||||||||||||||||||||||||
| 5 | # | ||||||||||||||||||||||||||||
| 6 | # This program is free software: you can redistribute it and/or modify | ||||||||||||||||||||||||||||
| 7 | # it under the terms of the GNU Affero General Public License as published | ||||||||||||||||||||||||||||
| 8 | # by the Free Software Foundation, either version 3 of the License, or | ||||||||||||||||||||||||||||
| 9 | # (at your option) any later version. | ||||||||||||||||||||||||||||
| 10 | # | ||||||||||||||||||||||||||||
| 11 | # This program is distributed in the hope that it will be useful, | ||||||||||||||||||||||||||||
| 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||||||||||||||||||||||||||
| 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||||||||||||||||||||||||||
| 14 | # GNU Affero General Public License for more details. | ||||||||||||||||||||||||||||
| 15 | # | ||||||||||||||||||||||||||||
| 16 | # You should have received a copy of the GNU Affero General Public License | ||||||||||||||||||||||||||||
| 17 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | ||||||||||||||||||||||||||||
| 18 | # | ||||||||||||||||||||||||||||
| 19 | ############################################################################## | ||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | package CBI::Wrapper; | ||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 24 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | 1 | our $VERSION = '0.02'; | |||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | 1 | ▶ | use CBI::Wrapper::RIBA; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 29 | 1 | ▶ | use CBI::Wrapper::Flow; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | 0 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 32 | 0 | my $class = shift; | |||||||||||||||||||||||||||
| 33 | 0 | my $args = shift; | |||||||||||||||||||||||||||
| 34 | my $self = { | ||||||||||||||||||||||||||||
| 35 | _header => $args->{header}, | ||||||||||||||||||||||||||||
| 36 | _disposals => $args->{disposals}, | ||||||||||||||||||||||||||||
| 37 | 0 | _flow_CBI => {}, | |||||||||||||||||||||||||||
| 38 | }; | ||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | 0 | bless $self, $class; | |||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | 0 | return $self; | |||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | # Getters and Setters. | ||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | 0 | ▶ | sub set_header { | ||||||||||||||||||||||||||
|
Subroutine
set_header: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 48 | 0 | my ($self, $header) = @_; | |||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | 0 | $self->{_header} = $header; | |||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | 0 | ▶ | sub get_header { | ||||||||||||||||||||||||||
|
Subroutine
get_header: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 54 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | 0 | return $self->{_header}; | |||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | 0 | ▶ | sub set_disposals { | ||||||||||||||||||||||||||
|
Subroutine
set_disposals: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 60 | 0 | my ($self, $disposals) = @_; | |||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | 0 | $self->{_disposals} = $disposals; | |||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | 0 | ▶ | sub get_disposals { | ||||||||||||||||||||||||||
|
Subroutine
get_disposals: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 66 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | 0 | return $self->{_disposals}; | |||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | 0 | ▶ | sub set_flow_CBI { | ||||||||||||||||||||||||||
|
Subroutine
set_flow_CBI: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 72 | 0 | my ($self, $flow_CBI) = @_; | |||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | 0 | $self->{_flow_CBI} = $flow_CBI; | |||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | 0 | ▶ | sub get_flow_CBI { | ||||||||||||||||||||||||||
|
Subroutine
get_flow_CBI: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 78 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | 0 | return $self->{_flow_CBI}; | |||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | 0 | ▶ | sub append_disposal { | ||||||||||||||||||||||||||
|
Subroutine
append_disposal: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 84 | 0 | my ($self, $disposal) = @_; | |||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | 0 | my $disposals = $self->get_disposals(); | |||||||||||||||||||||||||||
| 87 | 0 | push(@$disposals, $disposal); | |||||||||||||||||||||||||||
| 88 | 0 | $self->set_disposals($disposals); | |||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | # Create a flow with header, disposals and footer. | ||||||||||||||||||||||||||||
| 92 | 0 | ▶ | sub create_flow { | ||||||||||||||||||||||||||
|
Subroutine
create_flow: not called CC=7 SCAR=40.3
Pod
documented
| |||||||||||||||||||||||||||||
| 93 | 0 | my ($self, $args) = @_; | |||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | 0 | ▶ | my $header = defined $args->{header} ? $args->{header} : $self->get_header(); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 96 | 0 | ▶ | my $disposals = defined $args->{disposals} ? $args->{disposals} : $self->get_disposals(); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | 0 | ▶ | return 0 unless (defined $header and defined $disposals); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $header and defined $disposals
MC/DC0%0/2
defined $header and defined $disposals
defined $header
defined $disposals
Truth table0%0/3
A and B
A= defined $headerB= defined $disposals
| |||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | 0 | ▶ | my $flow_type = defined $args->{flow_type} ? $args->{flow_type} : ''; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | 0 | my $flow_CBI; | |||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | 0 | ▶ | if ($flow_type eq 'RICEVUTE_BANCARIE') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 105 | 0 | $flow_CBI = &CBI::Wrapper::RIBA::create_RIBA( | |||||||||||||||||||||||||||
| 106 | { | ||||||||||||||||||||||||||||
| 107 | header => $header, | ||||||||||||||||||||||||||||
| 108 | disposals => $disposals, | ||||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||
| 110 | ); | ||||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||
| 113 | 0 | $self->set_flow_CBI($flow_CBI); | |||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||
| 115 | 0 | return 1; | |||||||||||||||||||||||||||
| 116 | } | ||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||
| 118 | # Write CBI flow on file. | ||||||||||||||||||||||||||||
| 119 | 0 | ▶ | sub print { | ||||||||||||||||||||||||||
|
Subroutine
print: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 120 | 0 | my ($self, $filename) = @_; | |||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||
| 122 | 0 | ▶ | return 0 unless defined $filename; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||
| 124 | 0 | my $flow_CBI = $self->get_flow_CBI(); | |||||||||||||||||||||||||||
| 125 | 0 | $flow_CBI->write_file($filename); | |||||||||||||||||||||||||||
| 126 | } | ||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||
| 128 | # Load CBI flow from file. | ||||||||||||||||||||||||||||
| 129 | 0 | ▶ | sub load { | ||||||||||||||||||||||||||
|
Subroutine
load: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 130 | 0 | my ($self, $filename) = @_; | |||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||
| 132 | 0 | my $flow_CBI = new CBI::Wrapper::Flow(); | |||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||
| 134 | 0 | $flow_CBI->read_file($filename); | |||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||
| 136 | 0 | $self->set_flow_CBI($flow_CBI); | |||||||||||||||||||||||||||
| 137 | } | ||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||
| 139 | 1 | 1; | |||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||
| 141 | __END__ | ||||||||||||||||||||||||||||