blib/lib/DBIx/Class/Schema/Loader/Utils.pm

filter: Statementstmt 79.8% 127 / 159 Branchbran 60.7% 17 / 28 Conditioncond 55.5% 10 / 18 MC/DCmcdc 41.6% 5 / 12 Subroutinesub 76.1% 32 / 42 Podpod 0.0% 0 / 15 totaltotal 69.7% 191 / 274 SCAR 34.9
CC
24
Cov
75%
eval_package_without_redefine_warnings
6.0
no_warnings
6.0
warnings_exist
6.0
CRAP 32.9
« blib/lib/DBIx/Class/Schema/Loader/DBI/SQLite.pm ↑ Summary blib/lib/DBIx/Class/Schema/Loader/DBObject/Informix.pm »
1 package # hide from PAUSE
2 DBIx::Class::Schema::Loader::Utils;
3  
4 57 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 57 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 57 ▶use Test::More;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 57 ▶use String::CamelCase 'wordsplit';
Subroutine BEGIN: called CC=1 SCAR=0.0
8 57 ▶use Carp::Clan qw/^DBIx::Class/;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 57 ▶use List::Util 'all';
Subroutine BEGIN: called CC=1 SCAR=0.0
10 57 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 57 ▶use Exporter 'import';
Subroutine BEGIN: called CC=1 SCAR=0.0
12 57 ▶use Data::Dumper ();
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 57 our @EXPORT_OK = qw/split_name dumper dumper_squashed eval_package_without_redefine_warnings class_path no_warnings warnings_exist warnings_exist_silent slurp_file write_file array_eq sigwarn_silencer apply firstidx uniq/;
15  
16 57 use constant BY_CASE_TRANSITION_V7 =>
17 57 ▶ qr/(?<=[[:lower:]\d])[\W_]*(?=[[:upper:]])|[\W_]+/;
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 57 use constant BY_NON_ALPHANUM =>
20 57 ▶ qr/[\W_]+/;
Subroutine BEGIN: called CC=1 SCAR=0.0
21  
22 57 my $LF = "\x0a";
23 57 my $CRLF = "\x0d\x0a";
24  
25 sub split_name($;$) {
26 5645 ▶ my ($name, $v) = @_;
Subroutine split_name: called CC=5 SCAR=16.1
Pod undocumented
27  
28 5645 ▶ my $is_camel_case = $name =~ /[[:upper:]]/ && $name =~ /[[:lower:]]/;
Condition100%3/3
$name =~ /[[:upper:]]/ && $name =~ /[[:lower:]]/
!ll&&!rl&&r
534224279
MC/DC100%2/2
$name =~ /[[:upper:]]/ && $name =~ /[[:lower:]]/
$name =~ /[[:upper:]]/ $name =~ /[[:lower:]]/
Truth table100%3/3
A && B
A= $name =~ /[[:upper:]]/B= $name =~ /[[:lower:]]/
ABresult
0X0
100
111
29  
30 5645 ▶ if ((not $v) || $v >= 8) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $v or $v >= 8) 33 5612 5645
Condition66%2/3
not $v or $v >= 8
l!l&&r!l&&!r
3305612
MC/DC50%1/2
not $v or $v >= 8
not $v $v >= 8
Truth table66%2/3
not(A) or B
A= not $vB= $v >= 8
ABresult
1X1
011
000
31 33 return map split(BY_NON_ALPHANUM, $_), wordsplit($name);
32 }
33  
34 5612 ▶ return split $is_camel_case ? BY_CASE_TRANSITION_V7 : BY_NON_ALPHANUM, $name;
Branch: 1 branch
BranchTrueFalseTotal
$is_camel_case ? : 273 5339 5612
35 }
36  
37 sub dumper($) {
38 0 ▶ my $val = shift;
Subroutine dumper: not called CC=1 SCAR=6.9
Pod undocumented
39  
40 0 my $dd = Data::Dumper->new([]);
41 0 $dd->Terse(1)->Indent(1)->Useqq(1)->Deparse(1)->Quotekeys(0)->Sortkeys(1);
42 0 return $dd->Values([ $val ])->Dump;
43 }
44  
45 sub dumper_squashed($) {
46 144 ▶ my $val = shift;
Subroutine dumper_squashed: called CC=1 SCAR=0.0
Pod undocumented
47  
48 144 my $dd = Data::Dumper->new([]);
49 144 $dd->Terse(1)->Indent(1)->Useqq(1)->Deparse(1)->Quotekeys(0)->Sortkeys(1)->Indent(0);
50 144 return $dd->Values([ $val ])->Dump;
51 }
52  
53 # copied from DBIx::Class::_Util, import from there once it's released
54 sub sigwarn_silencer {
55 10286 ▶ my $pattern = shift;
Subroutine sigwarn_silencer: called CC=3 SCAR=11.3
Pod undocumented
56  
57 10286 ▶ croak "Expecting a regexp" if ref $pattern ne 'Regexp';
Branch: 1 branch
BranchTrueFalseTotal
if ref $pattern ne "Regexp" 0 10286 10286
58  
59 10286 ▶ my $orig_sig_warn = $SIG{__WARN__} || sub { CORE::warn(@_) };
Subroutine __ANON__: not called CC=1 SCAR=0.6
Condition66%2/3
$SIG{'__WARN__'} || sub { warn @_; }
l!l&&r!l&&!r
801622700
MC/DC0%0/2
$SIG{'__WARN__'} || sub { warn @_; }
$SIG{'__WARN__'} sub { warn @_; }
Truth table66%2/3
A || B
A= $SIG{'__WARN__'}B= sub { warn @_; }
ABresult
1X1
011
000
60  
61 10286 ▶ return sub { &$orig_sig_warn unless $_[0] =~ $pattern };
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
unless $_[0] =~ /$pattern/ 5 87 92
62 }
63  
64 # Copied with stylistic adjustments from List::MoreUtils::PP
65 sub firstidx (&@) {
66 1335 ▶ my $f = shift;
Subroutine firstidx: called CC=3 SCAR=11.1
Pod undocumented
67 1335 foreach my $i (0..$#_) {
68 1349 local *_ = \$_[$i];
69 1349 ▶ return $i if $f->();
Branch: 1 branch
BranchTrueFalseTotal
if &$f() 1335 14 1349
70 }
71 0 return -1;
72 }
73  
74 sub uniq (@) {
75 129 ▶ my %seen = ();
Subroutine uniq: called CC=1 SCAR=0.0
Pod undocumented
76 129 grep { not $seen{$_}++ } @_;
77 }
78  
79 sub apply (&@) {
80 1242 ▶ my $action = shift;
Subroutine apply: called CC=3 SCAR=11.2
Pod undocumented
81 1242 $action->() foreach my @values = @_;
82 1242 ▶ wantarray ? @values : $values[-1];
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 1242 0 1242
83 }
84  
85 sub eval_package_without_redefine_warnings {
86 1644 ▶ my ($pkg, $code) = @_;
Subroutine eval_package_without_redefine_warnings: called CC=6 SCAR=17.9
Pod undocumented
87  
88 1644 local $SIG{__WARN__} = sigwarn_silencer(qr/^Subroutine \S+ redefined/);
89  
90 # This hairiness is to handle people using "use warnings FATAL => 'all';"
91 # in their custom or external content.
92 1644 my @delete_syms;
93 1644 my $try_again = 1;
94  
95 1644 ▶ while ($try_again) {
Branch: 1 branch
BranchTrueFalseTotal
if ($try_again) 1652 1644 3296
96 1652 ▶ eval $code;
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
97  
98 1652 ▶ if (my ($sym) = $@ =~ /^Subroutine (\S+) redefined/) {
Branch: 2 branches
BranchTrueFalseTotal
if (my($sym) = $@ =~ /^Subroutine (\S+) redefined/) { } 8 1644 1652
elsif ($@) { } 0 1644 1644
99 8 delete $INC{ +class_path($pkg) };
100 8 push @delete_syms, $sym;
101  
102 8 foreach my $sym (@delete_syms) {
103 57 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
104 11 undef *{"${pkg}::${sym}"};
105 }
106 }
107 elsif ($@) {
108 0 ▶ die $@ if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
109 }
110 else {
111 1644 $try_again = 0;
112 }
113 }
114 }
115  
116 sub class_path {
117 2591 ▶ my $class = shift;
Subroutine class_path: called CC=1 SCAR=0.0
Pod undocumented
118  
119 2591 my $class_path = $class;
120 2591 $class_path =~ s{::}{/}g;
121 2591 $class_path .= '.pm';
122  
123 2591 return $class_path;
124 }
125  
126 sub no_warnings(&;$) {
127 0 ▶ my ($code, $test_name) = @_;
Subroutine no_warnings: not called CC=2 SCAR=17.9
Pod undocumented
128  
129 0 my $failed = 0;
130  
131 0 ▶ my $warn_handler = $SIG{__WARN__} || sub { warn @_ };
Subroutine __ANON__: not called CC=1 SCAR=6.9
Condition0%0/3
$SIG{'__WARN__'} || sub { warn @_; }
l!l&&r!l&&!r
000
MC/DC0%0/2
$SIG{'__WARN__'} || sub { warn @_; }
$SIG{'__WARN__'} sub { warn @_; }
Truth table0%0/3
A || B
A= $SIG{'__WARN__'}B= sub { warn @_; }
ABresult
1X1
011
000
132 local $SIG{__WARN__} = sub {
133 0 ▶ $failed = 1;
Subroutine __ANON__: not called CC=1 SCAR=6.9
134 0 $warn_handler->(@_);
135 0 };
136  
137 0 $code->();
138  
139 0 ok ((not $failed), $test_name);
140 }
141  
142 sub warnings_exist(&$$) {
143 0 ▶ my ($code, $re, $test_name) = @_;
Subroutine warnings_exist: not called CC=2 SCAR=17.9
Pod undocumented
144  
145 0 my $matched = 0;
146  
147 0 ▶ my $warn_handler = $SIG{__WARN__} || sub { warn @_ };
Subroutine __ANON__: not called CC=1 SCAR=6.9
Condition0%0/3
$SIG{'__WARN__'} || sub { warn @_; }
l!l&&r!l&&!r
000
MC/DC0%0/2
$SIG{'__WARN__'} || sub { warn @_; }
$SIG{'__WARN__'} sub { warn @_; }
Truth table0%0/3
A || B
A= $SIG{'__WARN__'}B= sub { warn @_; }
ABresult
1X1
011
000
148 local $SIG{__WARN__} = sub {
149 0 ▶ if ($_[0] =~ $re) {
Subroutine __ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
if ($_[0] =~ /$re/) { } 0 0 0
150 0 $matched = 1;
151 }
152 else {
153 0 $warn_handler->(@_)
154 }
155 0 };
156  
157 0 $code->();
158  
159 0 ok $matched, $test_name;
160 }
161  
162 sub warnings_exist_silent(&$$) {
163 0 ▶ my ($code, $re, $test_name) = @_;
Subroutine warnings_exist_silent: not called CC=1 SCAR=6.9
Pod undocumented
164  
165 0 my $matched = 0;
166  
167 0 ▶ local $SIG{__WARN__} = sub { $matched = 1 if $_[0] =~ $re; };
Subroutine __ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
if $_[0] =~ /$re/ 0 0 0
168  
169 0 $code->();
170  
171 0 ok $matched, $test_name;
172 }
173  
174 sub slurp_file($) {
175 110 ▶ my $file_name = shift;
Subroutine slurp_file: called CC=2 SCAR=7.0
Pod undocumented
176  
177 110 ▶ open my $fh, '<:encoding(UTF-8)', $file_name,
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, "<:encoding(UTF-8)", $file_name or croak("Can't open '${file_name}' for reading: $!") 0 110 110
178 or croak "Can't open '$file_name' for reading: $!";
179  
180 110 my $data = do { local $/; <$fh> };
181  
182 110 close $fh;
183  
184 110 $data =~ s/$CRLF|$LF/\n/g;
185  
186 110 return $data;
187 }
188  
189 sub write_file($$) {
190 1 ▶ my $file_name = shift;
Subroutine write_file: called CC=2 SCAR=7.0
Pod undocumented
191  
192 1 ▶ open my $fh, '>:encoding(UTF-8)', $file_name,
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, ">:encoding(UTF-8)", $file_name or croak("Can't open '${file_name}' for writing: $!") 0 1 1
193 or croak "Can't open '$file_name' for writing: $!";
194  
195 1 print $fh shift;
196 1 close $fh;
197 }
198  
199 sub array_eq($$) {
200 57 ▶ no warnings 'uninitialized';
Subroutine BEGIN: called CC=1 SCAR=0.0
201 1036 ▶ my ($l, $r) = @_;
Subroutine array_eq: called CC=2 SCAR=6.9
Pod undocumented
202  
203 1036 ▶ return @$l == @$r && all { $l->[$_] eq $r->[$_] } 0..$#$l;
Subroutine __ANON__: called CC=1 SCAR=0.0
Condition100%3/3
@$l == @$r && &all(sub { $l->[$_] eq $r->[$_]; } , 0 .. $l->$#*)
!ll&&!rl&&r
284510242
MC/DC100%2/2
@$l == @$r && &all(sub { $l->[$_] eq $r->[$_]; } , 0 .. $l->$#*)
@$l == @$r &all(sub { $l->[$_] eq $r->[$_]; } , 0 .. $l->$#*)
Truth table100%3/3
A && B
A= @$l == @$rB= &all(sub { $l->[$_] eq $r->[$_]; } , 0 .. $l->$#*)
ABresult
0X0
100
111
204 }
205  
206 57 1;
207 # vim:et sts=4 sw=4 tw=0:
« blib/lib/DBIx/Class/Schema/Loader/DBI/SQLite.pm ↑ Summary blib/lib/DBIx/Class/Schema/Loader/DBObject/Informix.pm »