| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package INI_File; |
|
2
|
|
|
|
|
|
|
BEGIN { |
|
3
|
2
|
|
|
2
|
|
214970
|
$INI_File::AUTHORITY = 'cpan:GETTY'; |
|
4
|
|
|
|
|
|
|
} |
|
5
|
|
|
|
|
|
|
# ABSTRACT: Tie a hash or an array to an INI file |
|
6
|
|
|
|
|
|
|
$INI_File::VERSION = '0.001'; |
|
7
|
2
|
|
|
2
|
|
2071
|
use Moo; |
|
|
2
|
|
|
|
|
36601
|
|
|
|
2
|
|
|
|
|
12
|
|
|
8
|
2
|
|
|
2
|
|
4616
|
use Config::INI::Reader; |
|
|
2
|
|
|
|
|
57637
|
|
|
|
2
|
|
|
|
|
68
|
|
|
9
|
2
|
|
|
2
|
|
993
|
use Config::INI::Writer; |
|
|
2
|
|
|
|
|
4148
|
|
|
|
2
|
|
|
|
|
60
|
|
|
10
|
2
|
|
|
2
|
|
1650
|
use Path::Class; |
|
|
2
|
|
|
|
|
66820
|
|
|
|
2
|
|
|
|
|
145
|
|
|
11
|
2
|
|
|
2
|
|
4909
|
use Data::Dumper; |
|
|
2
|
|
|
|
|
15652
|
|
|
|
2
|
|
|
|
|
2312
|
|
|
12
|
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
has filename => ( |
|
14
|
|
|
|
|
|
|
is => 'ro', |
|
15
|
|
|
|
|
|
|
required => 1, |
|
16
|
|
|
|
|
|
|
); |
|
17
|
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
has abs_filename => ( |
|
19
|
|
|
|
|
|
|
is => 'ro', |
|
20
|
|
|
|
|
|
|
lazy => 1, |
|
21
|
|
|
|
|
|
|
default => sub { file(shift->filename)->absolute }, |
|
22
|
|
|
|
|
|
|
); |
|
23
|
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub BUILD { |
|
25
|
3
|
|
|
3
|
0
|
3169
|
my ( $self ) = @_; |
|
26
|
3
|
|
|
|
|
46
|
$self->abs_filename; |
|
27
|
|
|
|
|
|
|
} |
|
28
|
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub data { |
|
30
|
34
|
|
|
34
|
0
|
47
|
my ( $self ) = @_; |
|
31
|
34
|
50
|
|
|
|
791
|
if (-f $self->abs_filename) { |
|
32
|
34
|
|
|
|
|
2277
|
return $self->load_file; |
|
33
|
|
|
|
|
|
|
} else { |
|
34
|
0
|
|
|
|
|
0
|
return {}; |
|
35
|
|
|
|
|
|
|
} |
|
36
|
|
|
|
|
|
|
} |
|
37
|
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub add_data { |
|
39
|
5
|
|
|
5
|
0
|
12
|
my ( $self, $key, $value ) = @_; |
|
40
|
5
|
50
|
|
|
|
20
|
print "add_data:".$key.":".Dumper($value)."\n" if $ENV{INI_FILE_TRACE}; |
|
41
|
5
|
|
|
|
|
14
|
my $data = $self->data; |
|
42
|
5
|
|
|
|
|
3415
|
$data->{$key} = $value; |
|
43
|
5
|
|
|
|
|
16
|
$self->save_file($data); |
|
44
|
|
|
|
|
|
|
} |
|
45
|
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub remove_data { |
|
47
|
1
|
|
|
1
|
0
|
2
|
my ( $self, $key ) = @_; |
|
48
|
1
|
50
|
|
|
|
5
|
print "remove_data:".$key."\n" if $ENV{INI_FILE_TRACE}; |
|
49
|
1
|
|
|
|
|
5
|
my $data = $self->data; |
|
50
|
1
|
|
|
|
|
997
|
delete $data->{$key}; |
|
51
|
1
|
|
|
|
|
4
|
$self->save_file($data); |
|
52
|
|
|
|
|
|
|
} |
|
53
|
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub load_file { |
|
55
|
34
|
|
|
34
|
0
|
49
|
my ( $self ) = @_; |
|
56
|
34
|
50
|
|
|
|
94
|
print __PACKAGE__.":load_file\n" if $ENV{INI_FILE_TRACE}; |
|
57
|
34
|
|
|
|
|
827
|
return Config::INI::Reader->read_file($self->abs_filename); |
|
58
|
|
|
|
|
|
|
} |
|
59
|
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub save_file { |
|
61
|
7
|
|
|
7
|
0
|
11
|
my ( $self, $data ) = @_; |
|
62
|
7
|
50
|
|
|
|
21
|
print __PACKAGE__.":save_file:".Dumper($data) if $ENV{INI_FILE_TRACE}; |
|
63
|
7
|
|
|
|
|
147
|
return Config::INI::Writer->write_file($data,$self->abs_filename); |
|
64
|
|
|
|
|
|
|
} |
|
65
|
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub TIEHASH { |
|
67
|
3
|
|
|
3
|
|
5126
|
my ( $class, $filename, @args ) = @_; |
|
68
|
3
|
0
|
|
|
|
18
|
print __PACKAGE__.":TIEHASH:".$filename.(scalar @args ? ":".Dumper(@args) : "\n") if $ENV{INI_FILE_TRACE}; |
|
|
|
50
|
|
|
|
|
|
|
69
|
3
|
|
|
|
|
72
|
$class->new( |
|
70
|
|
|
|
|
|
|
filename => $filename, |
|
71
|
|
|
|
|
|
|
@args, |
|
72
|
|
|
|
|
|
|
); |
|
73
|
|
|
|
|
|
|
} |
|
74
|
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
sub FETCH { |
|
76
|
9
|
|
|
9
|
|
6716
|
my ( $self, $key ) = @_; |
|
77
|
9
|
50
|
|
|
|
32
|
print __PACKAGE__.":FETCH:".$key."\n" if $ENV{INI_FILE_TRACE}; |
|
78
|
9
|
|
|
|
|
23
|
return $self->data->{$key}; |
|
79
|
|
|
|
|
|
|
} |
|
80
|
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
sub STORE { |
|
82
|
5
|
|
|
5
|
|
15518
|
my ( $self, $key, $value ) = @_; |
|
83
|
5
|
50
|
|
|
|
20
|
print __PACKAGE__.":STORE:".$key.":".Dumper($value) if $ENV{INI_FILE_TRACE}; |
|
84
|
5
|
|
|
|
|
15
|
$self->add_data($key,$value); |
|
85
|
|
|
|
|
|
|
} |
|
86
|
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
sub DELETE { |
|
88
|
1
|
|
|
1
|
|
922
|
my ( $self, $key ) = @_; |
|
89
|
1
|
50
|
|
|
|
8
|
print __PACKAGE__.":DELETE:".$key."\n" if $ENV{INI_FILE_TRACE}; |
|
90
|
1
|
|
|
|
|
6
|
$self->remove_data($key) |
|
91
|
|
|
|
|
|
|
} |
|
92
|
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
sub EXISTS { |
|
94
|
3
|
|
|
3
|
|
2059
|
my ( $self, $key ) = @_; |
|
95
|
3
|
50
|
|
|
|
16
|
print __PACKAGE__.":EXISTS:".$key."\n" if $ENV{INI_FILE_TRACE}; |
|
96
|
3
|
|
|
|
|
8
|
return exists $self->data->{$key}; |
|
97
|
|
|
|
|
|
|
} |
|
98
|
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
sub SCALAR { |
|
100
|
0
|
|
|
0
|
|
0
|
my ( $self ) = @_; |
|
101
|
0
|
0
|
|
|
|
0
|
print __PACKAGE__.":SCALAR\n" if $ENV{INI_FILE_TRACE}; |
|
102
|
0
|
|
|
|
|
0
|
return scalar %{$self->data}; |
|
|
0
|
|
|
|
|
0
|
|
|
103
|
|
|
|
|
|
|
} |
|
104
|
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
sub CLEAR { |
|
106
|
1
|
|
|
1
|
|
458
|
my ( $self ) = @_; |
|
107
|
1
|
50
|
|
|
|
7
|
print __PACKAGE__.":CLEAR\n" if $ENV{INI_FILE_TRACE}; |
|
108
|
1
|
|
|
|
|
5
|
$self->save_file({}); |
|
109
|
|
|
|
|
|
|
} |
|
110
|
|
|
|
|
|
|
|
|
111
|
0
|
|
|
0
|
|
0
|
sub EXTEND {} |
|
112
|
0
|
|
|
0
|
|
0
|
sub STORESIZE {} |
|
113
|
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
sub FIRSTKEY { |
|
115
|
4
|
|
|
4
|
|
1621
|
my ( $self ) = @_; |
|
116
|
4
|
|
|
|
|
8
|
my ( $first ) = sort { $a cmp $b } keys %{$self->data}; |
|
|
11
|
|
|
|
|
3423
|
|
|
|
4
|
|
|
|
|
14
|
|
|
117
|
4
|
50
|
|
|
|
47
|
return defined $first ? ($first) : (); |
|
118
|
|
|
|
|
|
|
} |
|
119
|
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
sub NEXTKEY { |
|
121
|
12
|
|
|
12
|
|
23
|
my ( $self, $last ) = @_; |
|
122
|
12
|
|
|
|
|
16
|
my @sorted_keys = sort { $a cmp $b } keys %{$self->data}; |
|
|
32
|
|
|
|
|
10427
|
|
|
|
12
|
|
|
|
|
25
|
|
|
123
|
12
|
|
|
|
|
94
|
while (@sorted_keys) { |
|
124
|
24
|
|
|
|
|
34
|
my $key = shift @sorted_keys; |
|
125
|
24
|
100
|
|
|
|
70
|
if ($key eq $last) { |
|
126
|
12
|
100
|
|
|
|
26
|
if (@sorted_keys) { |
|
127
|
8
|
|
|
|
|
47
|
return (shift @sorted_keys); |
|
128
|
|
|
|
|
|
|
} else { |
|
129
|
4
|
|
|
|
|
27
|
return; |
|
130
|
|
|
|
|
|
|
} |
|
131
|
|
|
|
|
|
|
} |
|
132
|
|
|
|
|
|
|
} |
|
133
|
|
|
|
|
|
|
} |
|
134
|
|
|
|
|
|
|
|
|
135
|
2
|
|
|
2
|
|
1871
|
sub UNTIE {} |
|
136
|
0
|
|
|
0
|
|
|
sub DESTROY {} |
|
137
|
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
1; |
|
139
|
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
__END__ |