blib/lib/Types/DBIx/Class.pm

filter: Statementstmt 92.5% 62 / 67 Branchbran 68.1% 15 / 22 Conditioncond 50.0% 3 / 6 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 100% 16 / 16 Podpod n/a totaltotal 84.2% 96 / 114 CC 15 SCAR 11.7
CC
15
Cov
84%
__ANON__
5.9
__ANON__
5.4
__ANON__
3.4
CRAP 3.2
↑ Summary
1 package Types::DBIx::Class;
2 4 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
3 4 $Types::DBIx::Class::VERSION = '1.000006';
4 }
5  
6 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 4 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 4 ▶use Type::Library -base;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 4 ▶use Type::Utils -all;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 4 ▶use Type::Params;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 4 ▶use Types::Standard qw(Maybe Str RegexpRef ArrayRef Ref InstanceOf);
Subroutine BEGIN: called CC=1 SCAR=0.0
14 4 ▶use Sub::Quote;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 # Create anonymous base types, checks
17 my %base =
18 4 map { ($_ => InstanceOf["DBIx::Class::$_"]) }
19 qw[ResultSet ResultSource Row Schema];
20  
21 # Grep/first shorthand
22 2 ▶sub _eq_array {
Subroutine _eq_array: called CC=3 SCAR=11.1
23 2 my($value, $other) = @_;
24 2 ▶ for (@$other) { return 1 if $value eq $_ }
Branch: 1 branch
BranchTrueFalseTotal
if $value eq $_ 2 1 3
25 0 return 0;
26 }
27  
28  
29 4 my $check_param = Type::Params::compile(ArrayRef|Str|InstanceOf['Type::Tiny']);
30 4 my $check_param_reg = Type::Params::compile(RegexpRef|Str);
31  
32 11 ▶my $get_rs_s_name = sub {$_[0].'->result_source->source_name'};
Subroutine __ANON__: called CC=1 SCAR=0.0
33  
34 my %param_types=
35 4 ▶ (ResultSource => [$base{ResultSource},sub {$_[0].'->source_name'}],
Subroutine __ANON__: called CC=1 SCAR=0.0
36 ResultSet => [$base{ResultSet},$get_rs_s_name],
37 4 Row => [$base{Row},$get_rs_s_name]);
38  
39 4 ▶while (my ($type, $specifics) = each %param_types) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %param_types) 12 4 16
40 12 my ($parent, $get_name) = @$specifics;
41 12 my $pcheck = Type::Params::compile($parent);
42 declare $type,
43 parent => $parent,
44 deep_explanation => sub
45 7 ▶ {
Subroutine __ANON__: called CC=5 SCAR=17.8
46 7 my ($maintype, $r, $varname) = @_;
47 7 ▶ $r //= '';
Condition50%1/2
$r //= ""
l!l
70
MC/DC0%0/1
$r //= ""
$r
Truth table50%1/2
A
A= $r
Aresult
11
00
48 7 my $source_name = $maintype->type_parameter;
49 7 ▶ [sprintf('variable %s type %s is not a '.$type.'%s', $varname,
Branch: 2 branches
BranchTrueFalseTotal
$maintype->check($r) ? : 0 7 7
defined $source_name ? : 7 0 7
Condition50%1/2
$r || ''
l!l
70
MC/DC0%0/1
$r || ''
$r
Truth table50%1/2
A
A= $r
Aresult
11
00
50 ( $maintype->check($r) ? $type.'[' . eval($get_name->('$r')) . ']' : "'".ref($r||'')."'" ),
51 ( defined $source_name ? "[$source_name]" : '' ))
52 ]
53 },
54 constraint_generator => sub
55 15 ▶ {
Subroutine __ANON__: called CC=5 SCAR=16.8
56 15 ▶ return $parent unless @_;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 0 15 15
57 15 my ($source) = eval {$check_param->(@_)};
58 15 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 15 15
59 0 local $Carp::CarpInternal{'Type::Tiny'}=1;
60 0 croak "$@ in $type parameter check called from";
61 }
62 15 ▶ my $check = $source =~ /^\w+$/ ?
Branch: 2 branches
BranchTrueFalseTotal
$source =~ /^\w+$/ ? : 13 2 15
$source =~ /^[\w|]+$/ ? : 1 1 2
63 $get_name->('$_')." eq '$source'" :
64 $source =~ /^[\w|]+$/ ?
65 $get_name->('$_')."=~ /^(?:$source)\$/" :
66 "Types::DBIx::Class::_eq_array(".$get_name->('$_').", \$source)";
67  
68 15 return Sub::Quote::quote_sub
69 "\$pcheck->(\$_) && $check",
70 12 { '$pcheck' => \$pcheck, '$source' => \$source } };
71 }
72  
73  
74 # This one was different enough to pull out of the loop
75 4 my $pcheck = Type::Params::compile($base{Schema});
76 declare 'Schema',
77 parent => $base{Schema},
78 deep_explanation => sub
79 2 ▶ {
Subroutine __ANON__: called CC=3 SCAR=11.4
80 2 my ($maintype, $s, $varname) = @_;
81 2 ▶ $s //= '';
Condition50%1/2
$s //= ""
l!l
20
MC/DC0%0/1
$s //= ""
$s
Truth table50%1/2
A
A= $s
Aresult
11
00
82 2 my $pattern = $maintype->type_parameter;
83 2 ▶ [sprintf('variable %s type %s is not a Schema%s', $varname,
Branch: 1 branch
BranchTrueFalseTotal
$pattern ? : 2 0 2
84 qq('$s'), $pattern ? qq([$pattern]) : '')
85 ]
86 },
87 constraint_generator => sub
88 6 ▶ {
Subroutine __ANON__: called CC=3 SCAR=12.3
89 6 ▶ return $base{Schema} unless @_;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 0 6 6
90 6 my ($pattern) = eval {$check_param_reg->(@_)};
91 6 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 6 6
92 0 local $Carp::CarpInternal{'Type::Tiny'}=1;
93 0 croak "$@ in Schema parameter check called from";
94 }
95 6 return Sub::Quote::quote_sub
96 "\$pcheck->(\$_) &&(!\$pattern || ref(\$_) =~ \$pattern)",
97 { '$pattern' => \$pattern, '$pcheck' => \$pcheck }
98 4 };
99  
100 4 1;
101 __END__
↑ Summary