BancaSella/Ris/File.pm

filter: Statementstmt 84.8% 56 / 66 Branchbran 57.6% 15 / 26 Conditioncond 33.3% 2 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 63.6% 7 / 11 Podpod 62.5% 5 / 8 totaltotal 70.2% 85 / 121 CC 17 SCAR 15.6
CC
17
Cov
74%
remove
6.6
init
6.2
extract
6.0
CRAP 4.7
« BancaSella/Decode/Gestpay.pm ↑ Summary BancaSella/Encode.pm »
1 package Business::BancaSella::Ris::File;
2  
3  
4 1 $VERSION = "0.11";
5 0 ▶sub Version { $VERSION; }
Subroutine Version: not called CC=1 SCAR=6.9
Pod undocumented
6 1 require 5.004;
7 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 1 my %fields =
12 (
13 file => undef,
14 );
15
16 1 my @fields_req = qw/file/;
17
18  
19 sub new
20 1 ▶{
Subroutine new: called CC=2 SCAR=7.1
Pod undocumented
21 1 my $proto = shift;
22 1 ▶ my $class = ref($proto) || $proto;
Condition33%1/3
ref $proto || $proto
l!l&&r!l&&!r
010
MC/DC0%0/2
ref $proto || $proto
ref $proto $proto
Truth table33%1/3
A || B
A= ref $protoB= $proto
ABresult
1X1
011
000
23 1 my $self = {};
24 1 bless $self,$class;
25 1 $self->init(@_);
26 1 return $self;
27 }
28  
29 1 ▶sub init {
Subroutine init: called CC=6 SCAR=18.2
Pod undocumented
30 1 my $self = shift;
31 1 my (%options) = @_;
32 # Assign default options
33 1 ▶ while (my ($key,$value) = each(%fields)) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %fields) 1 1 2
34 1 ▶ $self->{$key} = $self->{$key} || $value;
Condition33%1/3
$self->{$key} || $value
l!l&&r!l&&!r
001
MC/DC0%0/2
$self->{$key} || $value
$self->{$key} $value
Truth table33%1/3
A || B
A= $self->{$key}B= $value
ABresult
1X1
011
000
35 }
36 # Assign options
37 1 ▶ while (my ($key,$value) = each(%options)) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %options) 1 1 2
38 1 $self->{$key} = $value
39 }
40 # Check required params
41 1 foreach (@fields_req) {
42 croak "You must declare '$_' in " . ref($self) . "::new"
43 1 ▶ if (!defined $self->{$_});
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{$_} 0 1 1
44 }
45 }
46  
47 3 ▶sub check {
Subroutine check: called CC=4 SCAR=13.9
Pod documented
48 3 my $self = shift;
49 3 my $ris = shift;
50 3 ▶ open(F,$self->{file}) || die "Unable to open " . $self->file;
Branch: 1 branch
BranchTrueFalseTotal
open F, $self->{"file"} or die 'Unable to open ' . $self->file 3 0 3
51 3 ▶ while (<F>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline F)) 478 1 479
52 478 chomp;
53 478 ▶ if ($_ eq $ris) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_ eq $ris) 2 476 478
54 2 close(F);
55 2 return 1;
56 }
57 }
58 # my @hris = <F>;
59 1 close(F);
60 1 return 0;
61 # chomp(@hris);
62 # my %hris = map { $_ => 1} @hris;
63 # return exists($hris{$ris});
64 }
65  
66 1 ▶sub remove {
Subroutine remove: called CC=6 SCAR=18.9
Pod documented
67 1 my $self = shift;
68 1 my $ris = shift;
69 1 ▶ open(F,$self->{file}) || die "Unable to open " . $self->file;
Branch: 1 branch
BranchTrueFalseTotal
open F, $self->{"file"} or die 'Unable to open ' . $self->file 1 0 1
70 1 my @hris = <F>;
71 1 close(F);
72 1 chomp(@hris);
73 1 my %hris = map { $_ => 1} @hris;
74 1 ▶ if (exists($hris{$ris})) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $hris{$ris}) { } 1 0 1
75 1 delete $hris{$ris};
76 } else {
77 0 die "Unable to find $ris in " . $self->file;
78 }
79 1 @hris = map {$_ . "\n"} keys(%hris);
80 1 ▶ open(F,">$self->{file}") || die "Unable to open " . $self->file;
Branch: 1 branch
BranchTrueFalseTotal
open F, qq[>$self->{"file"}] or die 'Unable to open ' . $self->file 1 0 1
81 # lock the file
82 1 my $has_lock = eval { flock(F,2) };
83 1 ▶ if ( $@ ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($@) { } 0 1 1
elsif (not $has_lock) { } 0 1 1
84 #warn "WARNING. this platform don't implements 'flock'\n";
85 } elsif ( ! $has_lock ) {
86 0 close(F);
87 0 croak "SYSTEM. locking $self->{'file'} : $!\n";
88 }
89 1 print F @hris;
90 1 close(F)
91 }
92  
93 0 ▶sub extract {
Subroutine extract: not called CC=2 SCAR=17.9
Pod documented
94 # check password and remove it
95 # return true if find it
96 0 my ($self,$password,$only_test) = @_;
97 0 ▶ return 0 if (!$self->check($password));
Branch: 1 branch
BranchTrueFalseTotal
unless $self->check($password) 0 0 0
98 0 $self->remove($password);
99 }
100  
101 0 ▶sub prepare {
Subroutine prepare: not called CC=1 SCAR=6.9
Pod documented
102 0 my ($self,$source_file) = @_;
103 # don't do nothing :)
104 }
105  
106  
107 0 ▶sub file { my $s=shift; return @_ ? ($s->{file}=shift) : $s->{file} }
Subroutine file: not called CC=2 SCAR=17.9
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 0 0 0
108  
109 1 1;
110 __END__
« BancaSella/Decode/Gestpay.pm ↑ Summary BancaSella/Encode.pm »