Helpers/Util.pm

filter: Statementstmt 90.5% 48 / 53 Branchbran 82.3% 28 / 34 Conditioncond 83.3% 15 / 18 MC/DCmcdc 60.0% 6 / 10 Subroutinesub 100% 10 / 10 Podpod 100% 6 / 6 totaltotal 86.2% 113 / 131 CC 25 SCAR 18.6
CC
25
Cov
87%
normalize_connect_info
11.7
order_by_visitor
6.1
assert_similar_namespaces
5.0
CRAP 6.4
↑ Summary Helper/Row/OnColumnChange.pm »
1 package DBIx::Class::Helpers::Util;
2 57 $DBIx::Class::Helpers::Util::VERSION = '2.037000';
3 57 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 57 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 # ABSTRACT: Helper utilities for DBIx::Class components
7  
8 57 ▶use Sub::Exporter::Progressive -setup => {
Subroutine BEGIN: called CC=1 SCAR=0.0
9 exports => [
10 qw(
11 get_namespace_parts is_load_namespaces is_not_load_namespaces
12 assert_similar_namespaces order_by_visitor
13 normalize_connect_info
14 ),
15 ],
16 57 };
17  
18 562 ▶sub get_namespace_parts {
Subroutine get_namespace_parts: called CC=2 SCAR=7.6
Pod documented
19 562 my $package = shift;
20  
21 562 ▶ if ($package =~ m/(^[\w:]+::Result)::([\w:]+)$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($package =~ /(^[\w:]+::Result)::([\w:]+)$/) { } 562 0 562
22 562 return ($1, $2);
23 } else {
24 0 die "$package doesn't look like ".'$namespace::Result::$resultclass';
25 }
26 }
27  
28 683 ▶sub is_load_namespaces {
Subroutine is_load_namespaces: called CC=1 SCAR=0.0
Pod documented
29 683 my $namespace = shift;
30 683 $namespace =~ /^[\w:]+::Result::[\w:]+$/;
31 }
32  
33 7 ▶sub is_not_load_namespaces {
Subroutine is_not_load_namespaces: called CC=2 SCAR=7.2
Pod documented
34 7 my $namespace = shift;
35 7 ▶ $namespace =~ /^([\w:]+)::[\w]+$/ and
Branch: 1 branch
BranchTrueFalseTotal
$namespace =~ /^([\w:]+)::[\w]+$/ and not $1 =~ /::Result/ 7 0 7
36 $1 !~ /::Result/;
37 }
38  
39 341 ▶sub assert_similar_namespaces {
Subroutine assert_similar_namespaces: called CC=5 SCAR=16.1
Pod documented
40 341 my $ns1 = shift;
41 341 my $ns2 = shift;
42  
43 341 ▶ die "Namespaces $ns1 and $ns2 are dissimilar"
Branch: 1 branch
BranchTrueFalseTotal
unless is_load_namespaces($ns1) and is_load_namespaces($ns2) or is_not_load_namespaces($ns1) and is_not_load_namespaces($ns2) 2 339 341
Condition100%9/9
is_load_namespaces($ns1) and is_load_namespaces($ns2) or is_not_load_namespaces($ns1) and is_not_load_namespaces($ns2)
l!l&&r!l&&!r
33812
is_load_namespaces($ns1) and is_load_namespaces($ns2)
!ll&&!rl&&r
21338
is_not_load_namespaces($ns1) and is_not_load_namespaces($ns2)
!ll&&!rl&&r
111
MC/DC75%3/4
is_load_namespaces($ns1) and is_load_namespaces($ns2) or is_not_load_namespaces($ns1) and is_not_load_namespaces($ns2)
is_load_namespaces($ns1) is_load_namespaces($ns2) is_not_load_namespaces($ns1) is_not_load_namespaces($ns2)
Truth table57%4/7
A and B or C and D
A= is_load_namespaces($ns1)B= is_load_namespaces($ns2)C= is_not_load_namespaces($ns1)D= is_not_load_namespaces($ns2)
ABCDresult
11XX1
0X111
10111
0X0X0
0X100
100X0
10100
44 unless is_load_namespaces($ns1) and is_load_namespaces($ns2) or
45 is_not_load_namespaces($ns1) and is_not_load_namespaces($ns2);
46 }
47  
48 4 ▶sub _order_by_visitor_HASHREF {
Subroutine _order_by_visitor_HASHREF: called CC=4 SCAR=14.0
49 4 my ($hash, $callback) = @_;
50  
51 4 my %ret;
52 # there should only be one k/v pair, but DBIC checks for that and I'm not
53 # going to reimplement said check here.
54 4 for my $k (keys %$hash) {
55 4 my $v = $hash->{$k};
56  
57 4 ▶ if (my $v_ref = ref $v) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $v_ref = ref $v) { } 1 3 4
58 1 ▶ if ($v_ref eq 'ARRAY' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($v_ref eq 'ARRAY') { } 1 0 1
59 1 $ret{$k} = [ map $callback->($_), @$v ]
60 } else {
61 0 die 'this should never happen'
62 }
63 } else {
64 3 $ret{$k} = ($callback->($v));
65 }
66 }
67  
68 4 \%ret
69 }
70  
71 4 ▶sub order_by_visitor {
Subroutine order_by_visitor: called CC=6 SCAR=18.1
Pod documented
72 4 my ($order, $callback) = @_;
73  
74 4 ▶ if (my $top_ref = ref $order) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $top_ref = ref $order) { } 3 1 4
75 3 ▶ if ($top_ref eq 'HASH') {
Branch: 2 branches
BranchTrueFalseTotal
if ($top_ref eq 'HASH') { } 1 2 3
elsif ($top_ref eq 'ARRAY') { } 2 0 2
76 1 return _order_by_visitor_HASHREF($order, $callback)
77 } elsif ($top_ref eq 'ARRAY') {
78 return [
79 map {
80 2 ▶ if (my $ref = ref $_) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $ref = ref $_) { } 3 2 5
81 3 ▶ if ($ref eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if ($ref eq 'HASH') { } 3 0 3
82 3 _order_by_visitor_HASHREF($_, $callback)
83 } else {
84 0 die 'this should never happen'
85 }
86 } else {
87 2 $callback->($_)
88 }
89 } @$order
90 ];
91 }
92 } else {
93 1 return $callback->($order)
94 }
95 }
96  
97 67 ▶sub normalize_connect_info {
Subroutine normalize_connect_info: called CC=11 SCAR=24.6
Pod documented
98 67 my %all;
99  
100 67 ▶ if (!ref $_[0]) {
Branch: 2 branches
BranchTrueFalseTotal
if (not ref $_[0]) { } 65 2 67
elsif (ref $_[0] eq 'CODE') { } 2 0 2
101 %all = (
102 dsn => $_[0],
103 ( exists $_[1] ?
104 (user => $_[1],
105  
106 exists $_[2] ?
107 ( password => $_[2],
108  
109 ( exists $_[3] && ref $_[3] ?
110 2 ▶ %{$_[3]}
Branch: 1 branch
BranchTrueFalseTotal
exists $_[4] && ref $_[4] ? : 1 2 3
Condition66%2/3
exists $_[4] and ref $_[4]
!ll&&!rl&&r
201
MC/DC50%1/2
exists $_[4] and ref $_[4]
exists $_[4] ref $_[4]
Truth table66%2/3
A and B
A= exists $_[4]B= ref $_[4]
ABresult
0X0
100
111
111 : ()
112 ),
113  
114 ( exists $_[4] && ref $_[4] ?
115 65 ▶ %{$_[4]}
Branch: 3 branches
BranchTrueFalseTotal
exists $_[1] ? : 4 61 65
exists $_[2] ? : 3 1 4
exists $_[3] && ref $_[3] ? : 2 1 3
Condition66%2/3
exists $_[3] and ref $_[3]
!ll&&!rl&&r
102
MC/DC50%1/2
exists $_[3] and ref $_[3]
exists $_[3] ref $_[3]
Truth table66%2/3
A and B
A= exists $_[3]B= ref $_[3]
ABresult
0X0
100
111
116 : ()
117 ),
118  
119 )
120 : ()
121  
122 )
123  
124 : ()
125 ),
126 )
127 } elsif (ref $_[0] eq 'CODE') {
128 %all = (
129 dbh_maker => $_[0],
130 ( exists $_[1] && ref $_[1] ?
131 2 ▶ %{$_[1]}
Branch: 1 branch
BranchTrueFalseTotal
exists $_[1] && ref $_[1] ? : 1 1 2
Condition66%2/3
exists $_[1] and ref $_[1]
!ll&&!rl&&r
101
MC/DC50%1/2
exists $_[1] and ref $_[1]
exists $_[1] ref $_[1]
Truth table66%2/3
A and B
A= exists $_[1]B= ref $_[1]
ABresult
0X0
100
111
132 : ()
133 ),
134 )
135 } else {
136 0 %all = %{$_[0]}
137 }
138  
139 67 return \%all;
140 }
141  
142 57 1;
143  
144 __END__
↑ Summary Helper/Row/OnColumnChange.pm »