| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package App::PAIA::File; |
|
2
|
4
|
|
|
4
|
|
13
|
use strict; |
|
|
4
|
|
|
|
|
6
|
|
|
|
4
|
|
|
|
|
138
|
|
|
3
|
4
|
|
|
4
|
|
31
|
use v5.10; |
|
|
4
|
|
|
|
|
9
|
|
|
|
4
|
|
|
|
|
123
|
|
|
4
|
|
|
|
|
|
|
|
|
5
|
4
|
|
|
4
|
|
14
|
use App::PAIA::JSON; |
|
|
4
|
|
|
|
|
3
|
|
|
|
4
|
|
|
|
|
1605
|
|
|
6
|
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our %DEFAULT = ( |
|
8
|
|
|
|
|
|
|
'config' => 'paia.json', |
|
9
|
|
|
|
|
|
|
'session' => 'paia-session.json' |
|
10
|
|
|
|
|
|
|
); |
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub new { |
|
13
|
31
|
|
|
31
|
0
|
259
|
my $class = shift; |
|
14
|
31
|
|
|
|
|
99
|
my $self = bless { @_ }, $class; |
|
15
|
|
|
|
|
|
|
|
|
16
|
31
|
100
|
33
|
|
|
600
|
$self->{file} //= $DEFAULT{ $self->{type} } |
|
17
|
|
|
|
|
|
|
if -e $DEFAULT{ $self->{type} }; |
|
18
|
|
|
|
|
|
|
|
|
19
|
31
|
|
|
|
|
91
|
$self; |
|
20
|
|
|
|
|
|
|
} |
|
21
|
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub file { |
|
23
|
49
|
50
|
|
49
|
0
|
231
|
@_ > 1 ? ($_[0]->{file} = $_[1]) : $_[0]->{file}; |
|
24
|
|
|
|
|
|
|
} |
|
25
|
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub get { |
|
27
|
71
|
|
|
71
|
0
|
66
|
my ($self, $key) = @_; |
|
28
|
71
|
|
66
|
|
|
131
|
$self->{data} //= $self->load; |
|
29
|
71
|
|
|
|
|
309
|
$self->{data}->{$key}; |
|
30
|
|
|
|
|
|
|
} |
|
31
|
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub delete { |
|
33
|
1
|
|
|
1
|
0
|
4
|
my ($self, $key) = @_; |
|
34
|
1
|
|
33
|
|
|
3
|
$self->{data} //= $self->load; |
|
35
|
1
|
|
|
|
|
3
|
delete $self->{data}->{$key}; |
|
36
|
|
|
|
|
|
|
} |
|
37
|
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub set { |
|
39
|
13
|
|
|
13
|
0
|
15
|
my ($self, $key, $value) = @_; |
|
40
|
13
|
|
100
|
|
|
34
|
$self->{data} //= { }; |
|
41
|
13
|
|
|
|
|
91
|
$self->{data}->{$key} = $value; |
|
42
|
|
|
|
|
|
|
} |
|
43
|
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub load { |
|
45
|
26
|
|
|
26
|
0
|
30
|
my ($self) = @_; |
|
46
|
|
|
|
|
|
|
|
|
47
|
26
|
|
|
|
|
32
|
my $type = $self->{type}; |
|
48
|
26
|
|
100
|
|
|
42
|
my $file = $self->file // return($self->{data} = { }); |
|
49
|
|
|
|
|
|
|
|
|
50
|
13
|
|
|
|
|
47
|
local $/; |
|
51
|
13
|
100
|
|
|
|
374
|
open (my $fh, '<', $file) |
|
52
|
|
|
|
|
|
|
or die "failed to open $type file $file\n"; |
|
53
|
12
|
|
|
|
|
308
|
$self->{data} = decode_json(<$fh>,$file); |
|
54
|
12
|
|
|
|
|
125
|
close $fh; |
|
55
|
|
|
|
|
|
|
|
|
56
|
12
|
|
|
|
|
54
|
$self->{logger}->("loaded $type file $file"); |
|
57
|
|
|
|
|
|
|
|
|
58
|
12
|
|
|
|
|
111
|
$self->{data}; |
|
59
|
|
|
|
|
|
|
} |
|
60
|
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub store { |
|
62
|
9
|
|
|
9
|
0
|
18
|
my ($self) = @_; |
|
63
|
9
|
|
|
|
|
14
|
my $type = $self->{type}; |
|
64
|
9
|
|
66
|
|
|
18
|
my $file = $self->file // $DEFAULT{$type}; |
|
65
|
|
|
|
|
|
|
|
|
66
|
9
|
50
|
|
|
|
729
|
open (my $fh, '>', $file) |
|
67
|
|
|
|
|
|
|
or die "failed to open $type file $file\n"; |
|
68
|
9
|
|
|
|
|
17
|
print {$fh} encode_json($self->{data}); |
|
|
9
|
|
|
|
|
40
|
|
|
69
|
9
|
|
|
|
|
2175
|
close $fh; |
|
70
|
|
|
|
|
|
|
|
|
71
|
9
|
|
|
|
|
49
|
$self->{logger}->("saved $type file $file"); |
|
72
|
|
|
|
|
|
|
} |
|
73
|
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
sub purge { |
|
75
|
4
|
|
|
4
|
0
|
5
|
my ($self) = @_; |
|
76
|
|
|
|
|
|
|
|
|
77
|
4
|
50
|
33
|
|
|
10
|
return unless defined $self->file && -e $self->file; |
|
78
|
0
|
|
|
|
|
|
unlink $self->file; |
|
79
|
|
|
|
|
|
|
} |
|
80
|
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
1; |
|
82
|
|
|
|
|
|
|
__END__ |