AsObject.pm

filter: Statementstmt 94.7% 54 / 57 Branchbran 70.0% 14 / 20 Conditioncond 58.3% 7 / 12 MC/DCmcdc 16.6% 1 / 6 Subroutinesub 100% 13 / 13 Podpod n/a totaltotal 82.4% 89 / 108 CC 16 SCAR 16.4
CC
16
Cov
84%
__ANON__
10.7
__bless_dao
5.1
__ANON__
3.1
CRAP 5.2
« AsObject/Array.pm ↑ Summary
1 package Data::AsObject;
2 7 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
3 7 $Data::AsObject::VERSION = '0.07';
4 }
5  
6 # ABSTRACT: Easy OO access to complex perl data structures
7  
8 7 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 7 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 7 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 7 ▶use Scalar::Util qw(reftype blessed);
Subroutine BEGIN: called CC=1 SCAR=0.0
12 7 ▶use Data::AsObject::Hash;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 7 ▶use Data::AsObject::Array;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 7 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 43 ▶our $__check_type = sub {
Subroutine __ANON__: called CC=9 SCAR=23.7
17 43 my $data = shift;
18 43 ▶ return unless $data;
Branch: 1 branch
BranchTrueFalseTotal
unless $data 0 43 43
19  
20 43 my $type = reftype($data);
21  
22 43 ▶ if (defined $type) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $type) { } 16 27 43
23 16 ▶ if ( $type eq "ARRAY" && ( !blessed($data) || ref($data) =~ /^Data::AsObject::Array::(Strict|Loose|Silent)/ ) ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($type eq 'ARRAY' and !builtin::blessed($data) || ref($data) =~ /^Data::AsObject::Array::(Strict|Loose|Silent)/) { } 9 7 16
elsif ($type eq 'HASH' and !builtin::blessed($data) || ref($data) =~ /^Data::AsObject::Hash::(Strict|Loose|Silent)/) { } 7 0 7
Condition66%4/6
$type eq "ARRAY" and !builtin::blessed($data) || ref($data) =~ /^Data::AsObject::Array::(Strict|Loose|Silent)/
!ll&&!rl&&r
709
not builtin::blessed($data) or ref($data) =~ /^Data::AsObject::Array::(Strict|Loose|Silent)/
l!l&&r!l&&!r
540
MC/DC33%1/3
$type eq "ARRAY" and !builtin::blessed($data) || ref($data) =~ /^Data::AsObject::Array::(Strict|Loose|Silent)/
$type eq "ARRAY" not builtin::blessed($data) ref($data) =~ /^Data::AsObject::Array::(Strict|Loose|Silent)/
Truth table75%3/4
A and not(B) or C
A= $type eq "ARRAY"B= not builtin::blessed($data)C= ref($data) =~ /^Data::AsObject::Array::(Strict|Loose|Silent)/
ABCresult
0XX0
1000
11X1
1011
24 9 return "ARRAY";
25 ▶ } elsif ( $type eq "HASH" && ( !blessed($data) || ref($data) =~ /^Data::AsObject::Hash::(Strict|Loose|Silent)/ ) ) {
Condition50%3/6
$type eq "HASH" and !builtin::blessed($data) || ref($data) =~ /^Data::AsObject::Hash::(Strict|Loose|Silent)/
!ll&&!rl&&r
007
not builtin::blessed($data) or ref($data) =~ /^Data::AsObject::Hash::(Strict|Loose|Silent)/
l!l&&r!l&&!r
610
MC/DC0%0/3
$type eq "HASH" and !builtin::blessed($data) || ref($data) =~ /^Data::AsObject::Hash::(Strict|Loose|Silent)/
$type eq "HASH" not builtin::blessed($data) ref($data) =~ /^Data::AsObject::Hash::(Strict|Loose|Silent)/
Truth table50%2/4
A and not(B) or C
A= $type eq "HASH"B= not builtin::blessed($data)C= ref($data) =~ /^Data::AsObject::Hash::(Strict|Loose|Silent)/
ABCresult
0XX0
1000
11X1
1011
26 7 return "HASH";
27 } else {
28 0 return "";
29 }
30 } else {
31 27 return "";
32 }
33 7 };
34  
35 sub __build_dao
36 6 ▶{
Subroutine __build_dao: called CC=2 SCAR=7.1
37 6 my ($class, $sub, $arg) = @_;
38 6 ▶ my $mode = $arg->{mode} if $arg;
Branch: 1 branch
BranchTrueFalseTotal
if $arg 6 0 6
39  
40 return sub
41 8 ▶ {
Subroutine __ANON__: called CC=3 SCAR=11.2
42 8 my @result;
43 8 push @result, __bless_dao($_, $mode) for @_;
44 8 ▶ return wantarray ? @result : $result[0];
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 8 8
45 }
46 6 }
47  
48 sub __bless_dao
49 11 ▶{
Subroutine __bless_dao: called CC=5 SCAR=16.4
50 11 my ($data, $mode) = @_;
51  
52 11 ▶ if ($mode)
Branch: 1 branch
BranchTrueFalseTotal
if ($mode) { } 6 5 11
53 {
54 6 ▶ croak "Unknown mode '$mode' for dao construction" unless $mode =~/^strict|loose|silent$/;
Branch: 1 branch
BranchTrueFalseTotal
unless $mode =~ /^strict|loose|silent$/ 0 6 6
55 6 $mode = ucfirst($mode);
56 }
57 else
58 {
59 5 $mode = 'Strict';
60 }
61  
62 11 my $array_class = "Data::AsObject::Array::$mode";
63 11 my $hash_class = "Data::AsObject::Hash::$mode";
64  
65 11 my $type = reftype($data);
66  
67 11 my $dao;
68  
69 11 ▶ if ($type eq "ARRAY")
Branch: 2 branches
BranchTrueFalseTotal
if ($type eq 'ARRAY') { } 1 10 11
elsif ($type eq 'HASH') { } 10 0 10
70 {
71 1 $dao = bless $data, $array_class;
72 }
73 elsif ($type eq "HASH")
74 {
75 10 $dao = bless $data, $hash_class;
76 }
77 else
78 {
79 0 carp "Invalid argument to dao: must be hashref or arrayref!";
80 0 $dao = undef;
81 }
82 11 return $dao;
83 }
84  
85 7 ▶use Sub::Exporter -setup => { exports => [ dao => \'__build_dao' ] };
Subroutine BEGIN: called CC=1 SCAR=0.0
86  
87 7 1;
88  
89  
90  
91  
92 __END__
« AsObject/Array.pm ↑ Summary