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