String/Ini.pm

filter: Statementstmt 100% 9 / 9 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 3 / 3 Podpod n/a totaltotal 100% 12 / 12 CC 1 SCAR 0.0
CC
1
Cov
100%
BEGIN
1.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.0
« String/Http.pm ↑ Summary String/Javascript.pm »
1 #
2 # $Id$
3 #
4 # string::ini Brik
5 #
6 package Metabrik::String::Ini;
7 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 1 ▶use base qw(Metabrik);
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 sub brik_properties {
13 return {
14 revision => '$Revision$',
15 tags => [ qw(unstable encode decode) ],
16 author => 'GomoR <GomoR[at]metabrik.org>',
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 my $self = shift;
31 my ($data) = @_;
32  
33 $self->brik_help_run_undef_arg('encode', $data) or return;
34 $self->brik_help_run_invalid_arg('encode', $data, 'HASH') or return;
35  
36 my $copy = Storable::dclone($data);
37 bless($copy, 'Config::Tiny');
38  
39 my ($config) = $copy->write_string;
40 if (! defined($config)) {
41 return $self->log->error("encode: write_string failed");
42 }
43  
44 chomp($config);
45  
46 return $config;
47 }
48  
49 sub decode {
50 my $self = shift;
51 my ($data) = @_;
52  
53 $self->brik_help_run_undef_arg('decode', $data) or return;
54  
55 my ($config) = Config::Tiny->read_string($data);
56  
57 return { %$config };
58 }
59  
60 1;
61  
62 __END__
« String/Http.pm ↑ Summary String/Javascript.pm »