line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Business::BancaSella::Ris::File; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
$VERSION = "0.11"; |
5
|
0
|
|
|
0
|
0
|
0
|
sub Version { $VERSION; } |
6
|
|
|
|
|
|
|
require 5.004; |
7
|
1
|
|
|
1
|
|
836
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
40
|
|
8
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
30
|
|
9
|
1
|
|
|
1
|
|
5
|
use Carp; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
1127
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
my %fields = |
12
|
|
|
|
|
|
|
( |
13
|
|
|
|
|
|
|
file => undef, |
14
|
|
|
|
|
|
|
); |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
my @fields_req = qw/file/; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub new |
20
|
|
|
|
|
|
|
{ |
21
|
1
|
|
|
1
|
0
|
18
|
my $proto = shift; |
22
|
1
|
|
33
|
|
|
10
|
my $class = ref($proto) || $proto; |
23
|
1
|
|
|
|
|
3
|
my $self = {}; |
24
|
1
|
|
|
|
|
4
|
bless $self,$class; |
25
|
1
|
|
|
|
|
6
|
$self->init(@_); |
26
|
1
|
|
|
|
|
5
|
return $self; |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub init { |
30
|
1
|
|
|
1
|
0
|
2
|
my $self = shift; |
31
|
1
|
|
|
|
|
5
|
my (%options) = @_; |
32
|
|
|
|
|
|
|
# Assign default options |
33
|
1
|
|
|
|
|
9
|
while (my ($key,$value) = each(%fields)) { |
34
|
1
|
|
33
|
|
|
18
|
$self->{$key} = $self->{$key} || $value; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
# Assign options |
37
|
1
|
|
|
|
|
6
|
while (my ($key,$value) = each(%options)) { |
38
|
1
|
|
|
|
|
6
|
$self->{$key} = $value |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
# Check required params |
41
|
1
|
|
|
|
|
4
|
foreach (@fields_req) { |
42
|
1
|
50
|
|
|
|
8
|
croak "You must declare '$_' in " . ref($self) . "::new" |
43
|
|
|
|
|
|
|
if (!defined $self->{$_}); |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
sub check { |
48
|
3
|
|
|
3
|
1
|
186
|
my $self = shift; |
49
|
3
|
|
|
|
|
43
|
my $ris = shift; |
50
|
3
|
50
|
|
|
|
141
|
open(F,$self->{file}) || die "Unable to open " . $self->file; |
51
|
3
|
|
|
|
|
313
|
while () { |
52
|
477
|
|
|
|
|
752
|
chomp; |
53
|
477
|
100
|
|
|
|
2328
|
if ($_ eq $ris) { |
54
|
2
|
|
|
|
|
29
|
close(F); |
55
|
2
|
|
|
|
|
355
|
return 1; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
# my @hris = ; |
59
|
1
|
|
|
|
|
20
|
close(F); |
60
|
1
|
|
|
|
|
8
|
return 0; |
61
|
|
|
|
|
|
|
# chomp(@hris); |
62
|
|
|
|
|
|
|
# my %hris = map { $_ => 1} @hris; |
63
|
|
|
|
|
|
|
# return exists($hris{$ris}); |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub remove { |
67
|
1
|
|
|
1
|
1
|
8
|
my $self = shift; |
68
|
1
|
|
|
|
|
3
|
my $ris = shift; |
69
|
1
|
50
|
|
|
|
46
|
open(F,$self->{file}) || die "Unable to open " . $self->file; |
70
|
1
|
|
|
|
|
423
|
my @hris = ; |
71
|
1
|
|
|
|
|
24
|
close(F); |
72
|
1
|
|
|
|
|
21
|
chomp(@hris); |
73
|
1
|
|
|
|
|
5
|
my %hris = map { $_ => 1} @hris; |
|
476
|
|
|
|
|
1669
|
|
74
|
1
|
50
|
|
|
|
40
|
if (exists($hris{$ris})) { |
75
|
1
|
|
|
|
|
4
|
delete $hris{$ris}; |
76
|
|
|
|
|
|
|
} else { |
77
|
0
|
|
|
|
|
0
|
die "Unable to find $ris in " . $self->file; |
78
|
|
|
|
|
|
|
} |
79
|
1
|
|
|
|
|
49
|
@hris = map {$_ . "\n"} keys(%hris); |
|
475
|
|
|
|
|
823
|
|
80
|
1
|
50
|
|
|
|
67412
|
open(F,">$self->{file}") || die "Unable to open " . $self->file; |
81
|
|
|
|
|
|
|
# lock the file |
82
|
1
|
|
|
|
|
13
|
my $has_lock = eval { flock(F,2) }; |
|
1
|
|
|
|
|
57
|
|
83
|
1
|
50
|
|
|
|
12
|
if ( $@ ) { |
|
|
50
|
|
|
|
|
|
84
|
|
|
|
|
|
|
#warn "WARNING. this platform don't implements 'flock'\n"; |
85
|
|
|
|
|
|
|
} elsif ( ! $has_lock ) { |
86
|
0
|
|
|
|
|
0
|
close(F); |
87
|
0
|
|
|
|
|
0
|
croak "SYSTEM. locking $self->{'file'} : $!\n"; |
88
|
|
|
|
|
|
|
} |
89
|
1
|
|
|
|
|
547
|
print F @hris; |
90
|
1
|
|
|
|
|
369
|
close(F) |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
sub extract { |
94
|
|
|
|
|
|
|
# check password and remove it |
95
|
|
|
|
|
|
|
# return true if find it |
96
|
0
|
|
|
0
|
1
|
|
my ($self,$password,$only_test) = @_; |
97
|
0
|
0
|
|
|
|
|
return 0 if (!$self->check($password)); |
98
|
0
|
|
|
|
|
|
$self->remove($password); |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
sub prepare { |
102
|
0
|
|
|
0
|
1
|
|
my ($self,$source_file) = @_; |
103
|
|
|
|
|
|
|
# don't do nothing :) |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
|
107
|
0
|
0
|
|
0
|
1
|
|
sub file { my $s=shift; return @_ ? ($s->{file}=shift) : $s->{file} } |
|
0
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
1; |
110
|
|
|
|
|
|
|
__END__ |