| 1 | package CCCP::ConfigXML; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use namespace::autoclean; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 1 | ▶ | use XML::Bare; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use Hash::Merge::Simple qw(merge); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 1 | our $VERSION = '0.02'; | |||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 1 | my $singletone = undef; | |||||||||||||||||||||||||||
| 13 | 1 | $CCCP::ConfigXML::like_singletone = 0; | |||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | 1 | ▶ | sub import { | ||||||||||||||||||||||||||
|
Subroutine
import: called CC=3 SCAR=12.5
| |||||||||||||||||||||||||||||
| 16 | 1 | my ($class, %param) = @_; | |||||||||||||||||||||||||||
| 17 | 1 | ▶ | $CCCP::ConfigXML::like_singletone = 1 if ($param{as} and $param{as} eq 'singletone'); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$param{"as"} and $param{"as"} eq "singletone"
MC/DC0%0/2
$param{"as"} and $param{"as"} eq "singletone"
$param{"as"}
$param{"as"} eq "singletone"
Truth table33%1/3
A and B
A= $param{"as"}B= $param{"as"} eq "singletone"
| |||||||||||||||||||||||||||||
| 18 | 1 | return; | |||||||||||||||||||||||||||
| 19 | } | ||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | 1 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=8 SCAR=23.1
Pod
undocumented
| |||||||||||||||||||||||||||||
| 22 | 1 | my ($class, %param) = @_; | |||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | # support singletone if needed | ||||||||||||||||||||||||||||
| 25 | 1 | ▶ | return $singletone if ($CCCP::ConfigXML::like_singletone and $singletone); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$CCCP::ConfigXML::like_singletone and $singletone
MC/DC0%0/2
$CCCP::ConfigXML::like_singletone and $singletone
$CCCP::ConfigXML::like_singletone
$singletone
Truth table33%1/3
A and B
A= $CCCP::ConfigXML::like_singletoneB= $singletone
| |||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | 1 | my $self = bless {}, $class; | |||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | 1 | my ($file,$text) = map {delete $param{$_}} qw(file text); | |||||||||||||||||||||||||||
| 30 | 1 | ▶ | if ($file) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 31 | 0 | $self->add_file($_, %param) for _to_array($file); | |||||||||||||||||||||||||||
| 32 | }; | ||||||||||||||||||||||||||||
| 33 | 1 | ▶ | if ($text) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 34 | 1 | $self->add_text($_, %param) for _to_array($text); | |||||||||||||||||||||||||||
| 35 | }; | ||||||||||||||||||||||||||||
| 36 | 1 | ▶ | $singletone = $self if $CCCP::ConfigXML::like_singletone; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 37 | 1 | return $self; | |||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | 1 | ▶ | sub _to_array { return grep {$_} map {UNIVERSAL::isa($_,'ARRAY') ? @$_ : (ref $_ ? undef : $_)} @_ } | ||||||||||||||||||||||||||
|
Subroutine
_to_array: called CC=3 SCAR=13.1
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | 0 | ▶ | sub add_file { | ||||||||||||||||||||||||||
|
Subroutine
add_file: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 43 | 0 | my ($self, $file, @arg) = @_; | |||||||||||||||||||||||||||
| 44 | 0 | return $self->_add_hash(XML::Bare->new(file => $file, @arg)->parse()); | |||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | 3 | ▶ | sub add_text { | ||||||||||||||||||||||||||
|
Subroutine
add_text: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 48 | 3 | my ($self, $xml_str, @arg) = @_; | |||||||||||||||||||||||||||
| 49 | 3 | return $self->_add_hash(XML::Bare->new(text => $xml_str, @arg)->parse()); | |||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | # job method, but not present. may be later. | ||||||||||||||||||||||||||||
| 53 | 3 | ▶ | sub _add_hash { | ||||||||||||||||||||||||||
|
Subroutine
_add_hash: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 54 | 3 | my ($self, $hash) = @_; | |||||||||||||||||||||||||||
| 55 | 3 | %$self = %{merge $self, $hash}; | |||||||||||||||||||||||||||
| 56 | 3 | return 1; | |||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | 1 | 1; | |||||||||||||||||||||||||||
| 60 | __END__ | ||||||||||||||||||||||||||||