line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# |
2
|
|
|
|
|
|
|
# $Id$ |
3
|
|
|
|
|
|
|
# |
4
|
|
|
|
|
|
|
# file::ini Brik |
5
|
|
|
|
|
|
|
# |
6
|
|
|
|
|
|
|
package Metabrik::File::Ini; |
7
|
1
|
|
|
1
|
|
644
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
28
|
|
8
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
59
|
|
9
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
7
|
use base qw(Metabrik); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
439
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub brik_properties { |
13
|
|
|
|
|
|
|
return { |
14
|
0
|
|
|
0
|
1
|
|
revision => '$Revision$', |
15
|
|
|
|
|
|
|
tags => [ qw(unstable) ], |
16
|
|
|
|
|
|
|
author => 'GomoR ', |
17
|
|
|
|
|
|
|
license => 'http://opensource.org/licenses/BSD-3-Clause', |
18
|
|
|
|
|
|
|
attributes => { |
19
|
|
|
|
|
|
|
input => [ qw(file) ], |
20
|
|
|
|
|
|
|
output => [ qw(file) ], |
21
|
|
|
|
|
|
|
encoding => [ qw(utf8|ascii) ], |
22
|
|
|
|
|
|
|
overwrite => [ qw(0|1) ], |
23
|
|
|
|
|
|
|
}, |
24
|
|
|
|
|
|
|
attributes_default => { |
25
|
|
|
|
|
|
|
encoding => 'utf8', |
26
|
|
|
|
|
|
|
overwrite => 1, |
27
|
|
|
|
|
|
|
}, |
28
|
|
|
|
|
|
|
commands => { |
29
|
|
|
|
|
|
|
read => [ qw(input|OPTIONAL) ], |
30
|
|
|
|
|
|
|
write => [ qw(ini_hash output|OPTIONAL) ], |
31
|
|
|
|
|
|
|
}, |
32
|
|
|
|
|
|
|
require_modules => { |
33
|
|
|
|
|
|
|
'Metabrik::String::Ini' => [ ], |
34
|
|
|
|
|
|
|
'Metabrik::File::Text' => [ ], |
35
|
|
|
|
|
|
|
}, |
36
|
|
|
|
|
|
|
}; |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
sub read { |
40
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
41
|
0
|
|
|
|
|
|
my ($input) = @_; |
42
|
|
|
|
|
|
|
|
43
|
0
|
|
0
|
|
|
|
$input ||= $self->input; |
44
|
0
|
0
|
|
|
|
|
$self->brik_help_run_undef_arg('read', $input) or return; |
45
|
|
|
|
|
|
|
|
46
|
0
|
0
|
|
|
|
|
my $ft = Metabrik::File::Text->new_from_brik_init($self) or return; |
47
|
0
|
|
|
|
|
|
$ft->encoding($self->encoding); |
48
|
|
|
|
|
|
|
|
49
|
0
|
0
|
|
|
|
|
my $string = $ft->read($input) or return; |
50
|
|
|
|
|
|
|
|
51
|
0
|
0
|
|
|
|
|
my $si = Metabrik::String::Ini->new_from_brik_init($self) or return; |
52
|
|
|
|
|
|
|
|
53
|
0
|
0
|
|
|
|
|
my $ini_hash = $si->decode($string) or return; |
54
|
|
|
|
|
|
|
|
55
|
0
|
|
|
|
|
|
return $ini_hash; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
sub write { |
59
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
60
|
0
|
|
|
|
|
|
my ($ini_hash, $output) = @_; |
61
|
|
|
|
|
|
|
|
62
|
0
|
|
0
|
|
|
|
$output ||= $self->output; |
63
|
0
|
0
|
|
|
|
|
$self->brik_help_run_undef_arg('write', $output) or return; |
64
|
0
|
0
|
|
|
|
|
$self->brik_help_run_undef_arg('write', $ini_hash) or return; |
65
|
0
|
0
|
|
|
|
|
$self->brik_help_run_invalid_arg('write', $ini_hash, 'HASH') or return; |
66
|
|
|
|
|
|
|
|
67
|
0
|
0
|
|
|
|
|
my $si = Metabrik::String::Ini->new_from_brik_init($self) or return; |
68
|
|
|
|
|
|
|
|
69
|
0
|
0
|
|
|
|
|
my $string = $si->encode($ini_hash) or return; |
70
|
|
|
|
|
|
|
|
71
|
0
|
0
|
|
|
|
|
my $ft = Metabrik::File::Text->new_from_brik_init($self) or return; |
72
|
0
|
|
|
|
|
|
$ft->encoding($self->encoding); |
73
|
|
|
|
|
|
|
|
74
|
0
|
0
|
|
|
|
|
$ft->write($string, $output) or return; |
75
|
|
|
|
|
|
|
|
76
|
0
|
|
|
|
|
|
return $output; |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
1; |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
__END__ |