| 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
| |||||||||||||||||||||||||||||
| 17 | { | ||||||||||||||||||||||||||||
| 18 | 0 | my $yaml_file = $args{properties_file}; | |||||||||||||||||||||||||||
| 19 | 0 | ▶ | open my $ifh, '<', $yaml_file | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 20 | or die "Cannot open '$yaml_file': $!"; | ||||||||||||||||||||||||||||
| 21 | 0 | my $data = ''; | |||||||||||||||||||||||||||
| 22 | 0 | ▶ | while( my $line = <$ifh> ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 23 | { | ||||||||||||||||||||||||||||
| 24 | 0 | ▶ | $line =~ s/\t/ / | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 39 | { | ||||||||||||||||||||||||||||
| 40 | 4 | foreach my $key ( keys(%{ $s->{data} }) ) | |||||||||||||||||||||||||||
| 41 | { | ||||||||||||||||||||||||||||
| 42 | 7 | ▶ | next unless ref($s->{data}->{$key}); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
Condition100%3/3
exists $s->{$name} or exists $s->{"data"}{$name}
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}
| |||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | 19 | ▶ | return $s->{$name} || $s->{data}->{$name}; | ||||||||||||||||||||||||||
|
Condition66%2/3
$s->{$name} || $s->{'data'}{$name}
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}
| |||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||