Object/Metadata/Util.pm

filter: Statementstmt 14.4% 14 / 97 Branchbran 0.0% 0 / 72 Conditioncond 0.0% 0 / 19 MC/DCmcdc 0.0% 0 / 12 Subroutinesub 20.0% 2 / 10 Podpod 0.0% 0 / 6 totaltotal 7.4% 16 / 216 CC 49 SCAR 53.8
CC
49
Cov
7%
perl_hashref
420.0
perl_arrayref
240.0
perl_value
30.0
CRAP 216.1
« Object/Metadata/Auto/MySQL.pm ↑ Summary Object/Metadata/Relationship/ManyToMany.pm »
1 package Rose::DB::Object::Metadata::Util;
2  
3 61 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 61 ▶use Carp();
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 61 require Exporter;
8 61 our @ISA = qw(Exporter);
9  
10 61 our @EXPORT_OK =
11 qw(perl_hashref perl_arrayref perl_quote_key perl_quote_value
12 hash_key_padding);
13 61 our %EXPORT_TAGS = (all => \@EXPORT_OK);
14  
15 61 our $DEFAULT_PERL_INDENT = 4;
16 61 our $DEFAULT_PERL_BRACES = 'k&r';
17  
18 61 our $VERSION = '0.817';
19  
20 sub perl_hashref
21 0 ▶{
Subroutine perl_hashref: not called CC=20 SCAR=60.4
Pod undocumented
22 0 ▶ my(%args) = (@_ == 1 ? (hash => $_[0]) : @_);
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 ? : 0 0 0
23  
24 0 ▶ my $inline = defined $args{'inline'} ? $args{'inline'} : ($args{'inline'} = 1);
Branch: 1 branch
BranchTrueFalseTotal
defined $args{'inline'} ? : 0 0 0
25 0 ▶ my $indent = defined $args{'indent'} ? $args{'indent'} : ($args{'indent'} = $DEFAULT_PERL_INDENT);
Branch: 1 branch
BranchTrueFalseTotal
defined $args{'indent'} ? : 0 0 0
26 0 ▶ my $braces = defined $args{'braces'} ? $args{'braces'} : ($args{'braces'} = $DEFAULT_PERL_BRACES);
Branch: 1 branch
BranchTrueFalseTotal
defined $args{'braces'} ? : 0 0 0
27 0 ▶ my $level = defined $args{'level'} ? $args{'level'} : ($args{'level'} = 0);
Branch: 1 branch
BranchTrueFalseTotal
defined $args{'level'} ? : 0 0 0
28 0 my $no_curlies = delete $args{'no_curlies'};
29 0 ▶ my $key_padding = $args{'key_padding'} || 0;
Condition0%0/2
$args{'key_padding'} || 0
l!l
00
MC/DC0%0/1
$args{'key_padding'} || 0
$args{'key_padding'}
Truth table0%0/2
A
A= $args{'key_padding'}
Aresult
11
00
30 0 my $inline_limit = $args{'inline_limit'};
31  
32 0 ▶ my $sort_keys = $args{'sort_keys'} || sub { lc $_[0] cmp lc $_[1] };
Subroutine __ANON__: not called CC=1 SCAR=6.9
Condition0%0/3
$args{'sort_keys'} || sub { lc $_[0] cmp lc $_[1]; }
l!l&&r!l&&!r
000
MC/DC0%0/2
$args{'sort_keys'} || sub { lc $_[0] cmp lc $_[1]; }
$args{'sort_keys'} sub { lc $_[0] cmp lc $_[1]; }
Truth table0%0/3
A || B
A= $args{'sort_keys'}B= sub { lc $_[0] cmp lc $_[1]; }
ABresult
1X1
011
000
33  
34 0 my $hash = delete $args{'hash'};
35  
36 0 my $indent_txt = ' ' x ($indent * ($level + 1));
37 0 my $sub_indent = ' ' x ($indent * $level);
38  
39 0 my @pairs;
40  
41 0 foreach my $key (sort { $sort_keys->($a, $b) } keys %$hash)
42 {
43 push(@pairs, sprintf('%-*s => ', $key_padding, perl_quote_key($key)) .
44 0 perl_value(value => $hash->{$key}, %args));
45 }
46  
47 0 my($inline_perl, $perl);
48  
49 0 ▶ $inline_perl = ($no_curlies ? '' : '{ ') . join(', ', @pairs) . ($no_curlies ? '' : ' }');
Branch: 2 branches
BranchTrueFalseTotal
$no_curlies ? : 0 0 0
$no_curlies ? : 0 0 0
50  
51 0 ▶ if($braces eq 'bsd')
Branch: 2 branches
BranchTrueFalseTotal
if ($braces eq 'bsd') { } 0 0 0
elsif ($braces eq 'k&r') { } 0 0 0
52 {
53 0 ▶ $perl = "\n${sub_indent}" . ($no_curlies ? '' : "{\n");
Branch: 1 branch
BranchTrueFalseTotal
$no_curlies ? : 0 0 0
54 }
55 elsif($braces eq 'k&r')
56 {
57 0 ▶ $perl = "{\n" unless($no_curlies);
Branch: 1 branch
BranchTrueFalseTotal
unless $no_curlies 0 0 0
58 }
59 else
60 {
61 0 ▶ Carp::croak 'Invalid ', (defined $args{'braces'} ? '' : 'default '),
Branch: 1 branch
BranchTrueFalseTotal
defined $args{'braces'} ? : 0 0 0
62 "brace style: '$braces'";
63 }
64  
65 0 ▶ $perl .= join(",\n", map { "$indent_txt$_" } @pairs) . ',' .
Branch: 1 branch
BranchTrueFalseTotal
$no_curlies ? : 0 0 0
66 ($no_curlies ? '' : "\n$sub_indent}");
67  
68 0 ▶ if(defined $inline_limit && length($inline_perl) > $inline_limit)
Branch: 1 branch
BranchTrueFalseTotal
if (defined $inline_limit and length $inline_perl > $inline_limit) 0 0 0
Condition0%0/3
defined $inline_limit and length $inline_perl > $inline_limit
!ll&&!rl&&r
000
MC/DC0%0/2
defined $inline_limit and length $inline_perl > $inline_limit
defined $inline_limit length $inline_perl > $inline_limit
Truth table0%0/3
A and B
A= defined $inline_limitB= length $inline_perl > $inline_limit
ABresult
0X0
100
111
69 {
70 0 return $perl;
71 }
72  
73 0 ▶ return $inline ? $inline_perl : $perl;
Branch: 1 branch
BranchTrueFalseTotal
$inline ? : 0 0 0
74 }
75  
76 sub perl_arrayref
77 0 ▶{
Subroutine perl_arrayref: not called CC=15 SCAR=54.8
Pod undocumented
78 0 ▶ my(%args) = (@_ == 1 ? (array => $_[0]) : @_);
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 ? : 0 0 0
79  
80 0 ▶ my $inline = defined $args{'inline'} ? $args{'inline'} : ($args{'inline'} = 1);
Branch: 1 branch
BranchTrueFalseTotal
defined $args{'inline'} ? : 0 0 0
81 0 ▶ my $indent = defined $args{'indent'} ? $args{'indent'} : ($args{'indent'} = $DEFAULT_PERL_INDENT);
Branch: 1 branch
BranchTrueFalseTotal
defined $args{'indent'} ? : 0 0 0
82 0 ▶ my $braces = defined $args{'braces'} ? $args{'braces'} : ($args{'braces'} = $DEFAULT_PERL_BRACES);
Branch: 1 branch
BranchTrueFalseTotal
defined $args{'braces'} ? : 0 0 0
83 0 ▶ my $level = defined $args{'level'} ? $args{'level'} : ($args{'level'} = 0);
Branch: 1 branch
BranchTrueFalseTotal
defined $args{'level'} ? : 0 0 0
84 0 ▶ my $key_padding = $args{'key_padding'} || 0;
Condition0%0/2
$args{'key_padding'} || 0
l!l
00
MC/DC0%0/1
$args{'key_padding'} || 0
$args{'key_padding'}
Truth table0%0/2
A
A= $args{'key_padding'}
Aresult
11
00
85 0 my $inline_limit = $args{'inline_limit'};
86  
87 0 ▶ my $sort_keys = $args{'sort_keys'} || sub { lc $_[0] cmp lc $_[1] };
Subroutine __ANON__: not called CC=1 SCAR=6.9
Condition0%0/3
$args{'sort_keys'} || sub { lc $_[0] cmp lc $_[1]; }
l!l&&r!l&&!r
000
MC/DC0%0/2
$args{'sort_keys'} || sub { lc $_[0] cmp lc $_[1]; }
$args{'sort_keys'} sub { lc $_[0] cmp lc $_[1]; }
Truth table0%0/3
A || B
A= $args{'sort_keys'}B= sub { lc $_[0] cmp lc $_[1]; }
ABresult
1X1
011
000
88  
89 0 my $array = delete $args{'array'};
90  
91 0 my $indent_txt = ' ' x ($indent * ($level + 1));
92 0 my $sub_indent = ' ' x ($indent * $level);
93  
94 0 my @items;
95  
96 0 foreach my $item (@$array)
97 {
98 0 push(@items, perl_value(value => $item, %args));
99 }
100  
101 0 my($inline_perl, $perl);
102  
103 0 $inline_perl = '[ ' . join(', ', @items) . ' ]';
104  
105 0 ▶ if($braces eq 'bsd')
Branch: 2 branches
BranchTrueFalseTotal
if ($braces eq 'bsd') { } 0 0 0
elsif ($braces eq 'k&r') { } 0 0 0
106 {
107 0 $perl = "\n${sub_indent}\[\n";
108 }
109 elsif($braces eq 'k&r')
110 {
111 0 $perl = "[\n";
112 }
113 else
114 {
115 0 ▶ Carp::croak 'Invalid ', (defined $args{'braces'} ? '' : 'default '),
Branch: 1 branch
BranchTrueFalseTotal
defined $args{'braces'} ? : 0 0 0
116 "brace style: '$braces'";
117 }
118  
119 0 $perl .= join(",\n", map { "$indent_txt$_" } @items) . ",\n$sub_indent]";
120  
121 0 ▶ if(defined $inline_limit && length($inline_perl) > $inline_limit)
Branch: 1 branch
BranchTrueFalseTotal
if (defined $inline_limit and length $inline_perl > $inline_limit) 0 0 0
Condition0%0/3
defined $inline_limit and length $inline_perl > $inline_limit
!ll&&!rl&&r
000
MC/DC0%0/2
defined $inline_limit and length $inline_perl > $inline_limit
defined $inline_limit length $inline_perl > $inline_limit
Truth table0%0/3
A and B
A= defined $inline_limitB= length $inline_perl > $inline_limit
ABresult
0X0
100
111
122 {
123 0 return $perl;
124 }
125  
126 0 ▶ return $inline ? $inline_perl : $perl;
Branch: 1 branch
BranchTrueFalseTotal
$inline ? : 0 0 0
127 }
128  
129 sub perl_value
130 0 ▶{
Subroutine perl_value: not called CC=5 SCAR=34.0
Pod undocumented
131 0 ▶ my(%args) = (@_ == 1 ? (value => $_[0]) : @_);
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 ? : 0 0 0
132  
133 0 my $value = delete $args{'value'};
134  
135 0 $args{'level'}++;
136  
137 0 ▶ if(my $ref = ref $value)
Branch: 1 branch
BranchTrueFalseTotal
if (my $ref = ref $value) 0 0 0
138 {
139 0 ▶ if($ref eq 'ARRAY')
Branch: 2 branches
BranchTrueFalseTotal
if ($ref eq 'ARRAY') { } 0 0 0
elsif ($ref eq 'HASH') { } 0 0 0
140 {
141 0 return perl_arrayref(array => $value, %args);
142 }
143 elsif($ref eq 'HASH')
144 {
145 0 $args{'key_padding'} = hash_key_padding($value);
146 0 delete $args{'inline'};
147 0 return perl_hashref(hash => $value, %args);
148 }
149 else
150 {
151 0 return $value;
152 }
153 }
154  
155 0 return perl_quote_value($value)
156 }
157  
158 sub hash_key_padding
159 0 ▶{
Subroutine hash_key_padding: not called CC=5 SCAR=34.0
Pod undocumented
160 0 my($hash) = shift;
161  
162 0 my $max_len = 0;
163 0 my $min_len = -1;
164  
165 0 foreach my $name (keys %$hash)
166 {
167 0 ▶ $max_len = length($name) if(length $name > $max_len);
Branch: 1 branch
BranchTrueFalseTotal
if length $name > $max_len 0 0 0
168 0 ▶ $min_len = length($name) if(length $name < $min_len || $min_len < 0);
Branch: 1 branch
BranchTrueFalseTotal
if length $name < $min_len or $min_len < 0 0 0 0
Condition0%0/3
length $name < $min_len or $min_len < 0
l!l&&r!l&&!r
000
MC/DC0%0/2
length $name < $min_len or $min_len < 0
length $name < $min_len $min_len < 0
Truth table0%0/3
A or B
A= length $name < $min_lenB= $min_len < 0
ABresult
1X1
011
000
169 }
170  
171 0 return $max_len;
172 }
173  
174 sub perl_quote_key
175 0 ▶{
Subroutine perl_quote_key: not called CC=5 SCAR=34.0
Pod undocumented
176 0 my($key) = shift;
177  
178 0 ▶ return $key if($key =~ /^\d+$/);
Branch: 1 branch
BranchTrueFalseTotal
if $key =~ /^\d+$/ 0 0 0
179  
180 0 for($key)
181 {
182 0 ▶ s/'/\\'/g if(/'/);
Branch: 1 branch
BranchTrueFalseTotal
if /'/ 0 0 0
183 0 ▶ $_ = "'$_'" if(/\W/);
Branch: 1 branch
BranchTrueFalseTotal
if /\W/ 0 0 0
184 }
185  
186 0 return $key;
187 }
188  
189 sub perl_quote_value
190 0 ▶{
Subroutine perl_quote_value: not called CC=4 SCAR=30.0
Pod undocumented
191 0 my($val) = shift;
192  
193 0 for($val)
194 {
195 0 ▶ s/'/\\'/g if(/'/);
Branch: 1 branch
BranchTrueFalseTotal
if /'/ 0 0 0
196 0 ▶ $_ = "'$_'" unless(/^(?:[1-9]\d*\.?\d*|\.\d+)$/);
Branch: 1 branch
BranchTrueFalseTotal
unless /^(?:[1-9]\d*\.?\d*|\.\d+)$/ 0 0 0
197 }
198  
199 0 return $val;
200 }
201  
202 61 1;
« Object/Metadata/Auto/MySQL.pm ↑ Summary Object/Metadata/Relationship/ManyToMany.pm »