blib/lib/Data/Properties/YAML.pm

filter: Statementstmt 77.1% 27 / 35 Branchbran 50.0% 8 / 16 Conditioncond 83.3% 5 / 6 MC/DCmcdc 50.0% 2 / 4 Subroutinesub 83.3% 5 / 6 Podpod 100% 1 / 1 totaltotal 70.5% 48 / 68 CC 12 SCAR 23.8
CC
12
Cov
70%
new
18.2
AUTOLOAD
4.0
BEGIN
1.0
CRAP 10.8
↑ Summary
1
2 package Data::Properties::YAML;
3
4 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use warnings 'all';
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use YAML 'Load';
Subroutine BEGIN: called CC=1 SCAR=0.0
7
8 1 our $VERSION = 0.04;
9
10
11 #====================================================================
12 sub new
13 4 ▶{
Subroutine new: called CC=9 SCAR=29.0
Pod documented
14 4 my ($class, %args) = @_;
15
16 4 ▶ if( $args{properties_file} )
Branch: 2 branches
BranchTrueFalseTotal
if ($args{'properties_file'}) { } 0 4 4
elsif ($args{'yaml_data'}) { } 1 3 4
17 {
18 0 my $yaml_file = $args{properties_file};
19 0 ▶ open my $ifh, '<', $yaml_file
Branch: 1 branch
BranchTrueFalseTotal
open my $ifh, "<", $yaml_file or die "Cannot open '${yaml_file}': $!" 0 0 0
20 or die "Cannot open '$yaml_file': $!";
21 0 my $data = '';
22 0 ▶ while( my $line = <$ifh> )
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $line = readline $ifh)) 0 0 0
23 {
24 0 ▶ $line =~ s/\t/ /
Branch: 1 branch
BranchTrueFalseTotal
$line =~ /\t/ and do { $line =~ s/\t/ / } 0 0 0
25 while $line =~ m/\t/;
26 0 $data .= $line;
27 }# end while()
28 0 $args{data} = Load( $data );
29 0 $args{__name} = 'root';
30 }
31 elsif( $args{yaml_data} )
32 {
33 1 $args{data} = Load( $args{yaml_data} );
34 1 $args{__name} = 'root';
35 }# end if()
36
37 4 my $s = bless \%args, $class;
38 4 ▶ if( ref($s->{data}) )
Branch: 1 branch
BranchTrueFalseTotal
if (ref $s->{"data"}) 4 0 4
39 {
40 4 foreach my $key ( keys(%{ $s->{data} }) )
41 {
42 7 ▶ next unless ref($s->{data}->{$key});
Branch: 1 branch
BranchTrueFalseTotal
unless ref $s->{"data"}{$key} 4 3 7
43 $s->{$key} = ref($s)->new(
44 __name => "$s->{__name}.$key",
45 3 data => $s->{data}->{$key},
46 );
47 }# end foreach()
48 }# end if()
49
50 # Finally:
51 4 return $s;
52 }# end new()
53
54
55 #====================================================================
56 sub AUTOLOAD
57 20 ▶{
Subroutine AUTOLOAD: called CC=4 SCAR=13.9
58 20 my $s = shift;
59 20 our $AUTOLOAD;
60
61 20 my ($name) = $AUTOLOAD =~ m/::([^:]+)$/;
62 die "Node $s->{__name} has no property named '$name'"
63 20 ▶ unless exists( $s->{$name} ) || exists( $s->{data}->{$name} );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $s->{$name} or exists $s->{"data"}{$name} 1 19 20
Condition100%3/3
exists $s->{$name} or exists $s->{"data"}{$name}
l!l&&r!l&&!r
1541
MC/DC100%2/2
exists $s->{$name} or exists $s->{"data"}{$name}
exists $s->{$name} exists $s->{"data"}{$name}
Truth table100%3/3
A or B
A= exists $s->{$name}B= exists $s->{"data"}{$name}
ABresult
1X1
011
000
64
65 19 ▶ return $s->{$name} || $s->{data}->{$name};
Condition66%2/3
$s->{$name} || $s->{'data'}{$name}
l!l&&r!l&&!r
1540
MC/DC0%0/2
$s->{$name} || $s->{'data'}{$name}
$s->{$name} $s->{'data'}{$name}
Truth table66%2/3
A || B
A= $s->{$name}B= $s->{'data'}{$name}
ABresult
1X1
011
000
66 }# end AUTOLOAD()
67
68 0 ▶sub DESTROY { }
Subroutine DESTROY: not called CC=1 SCAR=0.0
69
70 1 1;# return true:
71
72 __END__
↑ Summary