line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# |
2
|
|
|
|
|
|
|
# $Id$ |
3
|
|
|
|
|
|
|
# |
4
|
|
|
|
|
|
|
# string::ini Brik |
5
|
|
|
|
|
|
|
# |
6
|
|
|
|
|
|
|
package Metabrik::String::Ini; |
7
|
1
|
|
|
1
|
|
679
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
28
|
|
8
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
26
|
|
9
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
5
|
use base qw(Metabrik); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
370
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub brik_properties { |
13
|
|
|
|
|
|
|
return { |
14
|
0
|
|
|
0
|
1
|
|
revision => '$Revision$', |
15
|
|
|
|
|
|
|
tags => [ qw(unstable encode decode) ], |
16
|
|
|
|
|
|
|
author => 'GomoR ', |
17
|
|
|
|
|
|
|
license => 'http://opensource.org/licenses/BSD-3-Clause', |
18
|
|
|
|
|
|
|
commands => { |
19
|
|
|
|
|
|
|
encode => [ qw($data_hash) ], |
20
|
|
|
|
|
|
|
decode => [ qw($data) ], |
21
|
|
|
|
|
|
|
}, |
22
|
|
|
|
|
|
|
require_modules => { |
23
|
|
|
|
|
|
|
'Config::Tiny' => [ ], |
24
|
|
|
|
|
|
|
'Storable' => [ qw(dclone) ], |
25
|
|
|
|
|
|
|
}, |
26
|
|
|
|
|
|
|
}; |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub encode { |
30
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
31
|
0
|
|
|
|
|
|
my ($data) = @_; |
32
|
|
|
|
|
|
|
|
33
|
0
|
0
|
|
|
|
|
$self->brik_help_run_undef_arg('encode', $data) or return; |
34
|
0
|
0
|
|
|
|
|
$self->brik_help_run_invalid_arg('encode', $data, 'HASH') or return; |
35
|
|
|
|
|
|
|
|
36
|
0
|
|
|
|
|
|
my $copy = Storable::dclone($data); |
37
|
0
|
|
|
|
|
|
bless($copy, 'Config::Tiny'); |
38
|
|
|
|
|
|
|
|
39
|
0
|
|
|
|
|
|
my ($config) = $copy->write_string; |
40
|
0
|
0
|
|
|
|
|
if (! defined($config)) { |
41
|
0
|
|
|
|
|
|
return $self->log->error("encode: write_string failed"); |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
0
|
|
|
|
|
|
chomp($config); |
45
|
|
|
|
|
|
|
|
46
|
0
|
|
|
|
|
|
return $config; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub decode { |
50
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
51
|
0
|
|
|
|
|
|
my ($data) = @_; |
52
|
|
|
|
|
|
|
|
53
|
0
|
0
|
|
|
|
|
$self->brik_help_run_undef_arg('decode', $data) or return; |
54
|
|
|
|
|
|
|
|
55
|
0
|
|
|
|
|
|
my ($config) = Config::Tiny->read_string($data); |
56
|
|
|
|
|
|
|
|
57
|
0
|
|
|
|
|
|
return { %$config }; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
1; |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
__END__ |