File/Xml.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
« File/Write.pm ↑ Summary Forensic/Dcfldd.pm »
1 #
2 # $Id$
3 #
4 # file::xml Brik
5 #
6 package Metabrik::File::Xml;
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::File::Read);
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 sub brik_properties {
13 return {
14 revision => '$Revision$',
15 tags => [ qw(unstable) ],
16 author => 'GomoR <GomoR[at]metabrik.org>',
17 license => 'http://opensource.org/licenses/BSD-3-Clause',
18 attributes => {
19 input => [ qw(file) ],
20 output => [ qw(file) ],
21 overwrite => [ qw(0|1) ],
22 },
23 attributes_default => {
24 overwrite => 1,
25 },
26 commands => {
27 read => [ qw(input_file|OPTIONAL) ],
28 write => [ qw($xml_hash output_file|OPTIONAL) ],
29 },
30 require_modules => {
31 'Metabrik::File::Write' => [ ],
32 'Metabrik::String::Xml' => [ ],
33 },
34 };
35 }
36  
37 sub brik_use_properties {
38 my $self = shift;
39  
40 return {
41 attributes_default => {
42 encoding => defined($self->global) && $self->global->encoding || 'utf8',
43 },
44 };
45 }
46  
47 sub read {
48 my $self = shift;
49 my ($input) = @_;
50  
51 $input ||= $self->input;
52 $self->brik_help_run_undef_arg("read", $input) or return;
53  
54 $self->open($input) or return;
55 my $data = $self->SUPER::read or return;
56 $self->close;
57  
58 my $xml = Metabrik::String::Xml->new_from_brik_init($self) or return;
59 my $decode = $xml->decode($data) or return;
60  
61 return $decode;
62 }
63  
64 sub write {
65 my $self = shift;
66 my ($xml_hash, $output) = @_;
67  
68 $output ||= $self->output;
69 $self->brik_help_run_undef_arg('write', $xml_hash) or return;
70 $self->brik_help_run_undef_arg('write', $output) or return;
71  
72 my $xml = Metabrik::String::Xml->new_from_brik_init($self) or return;
73 my $data = $xml->encode($xml_hash) or return;
74  
75 my $fw = Metabrik::File::Write->new_from_brik_init($self) or return;
76 $fw->open($output) or return;
77 $fw->write($data) or return;
78 $fw->close;
79  
80 return $data;
81 }
82  
83 1;
84  
85 __END__
« File/Write.pm ↑ Summary Forensic/Dcfldd.pm »