| 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
MC/DC0%0/2
ref $proto || $proto
ref $proto
$proto
Truth table33%1/3
A || B
A= ref $protoB= $proto
| |||||||||||||||||||||
| 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
| |||||||||||||||||||||
| 34 | 1 | ▶ | $self->{$key} = $self->{$key} || $value; | ||||||||||||||||||
|
Condition33%1/3
$self->{$key} || $value
MC/DC0%0/2
$self->{$key} || $value
$self->{$key}
$value
Truth table33%1/3
A || B
A= $self->{$key}B= $value
| |||||||||||||||||||||
| 35 | } | ||||||||||||||||||||
| 36 | # Assign options | ||||||||||||||||||||
| 37 | 1 | ▶ | while (my ($key,$value) = each(%options)) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 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
| |||||||||||||||||||||
| 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
| |||||||||||||||||||||
| 51 | 3 | ▶ | while (<F>) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 52 | 478 | chomp; | |||||||||||||||||||
| 53 | 478 | ▶ | if ($_ eq $ris) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 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
| |||||||||||||||||||||
| 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
| |||||||||||||||||||||
| 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
| |||||||||||||||||||||
| 81 | # lock the file | ||||||||||||||||||||
| 82 | 1 | my $has_lock = eval { flock(F,2) }; | |||||||||||||||||||
| 83 | 1 | ▶ | if ( $@ ) { | ||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||
| 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
| |||||||||||||||||||||
| 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
| |||||||||||||||||||||
| 108 | |||||||||||||||||||||
| 109 | 1 | 1; | |||||||||||||||||||
| 110 | __END__ | ||||||||||||||||||||