Class/Types.pm

filter: Statementstmt 83.8% 52 / 62 Branchbran 50.0% 9 / 18 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 68.7% 11 / 16 Podpod n/a totaltotal 71.2% 72 / 101 CC 13 SCAR 21.8
CC
13
Cov
73%
_coerce_connect_info_from_arrayref
18.8
__ANON__
2.0
_coerce_connect_info_from_str
2.0
CRAP 8.8
« Class/FixtureCommand/Populate.pm ↑ Summary Class/SchemaManager.pm »
1 package Test::DBIx::Class::Types;
2  
3 17 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 17 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 17 ▶use Class::MOP;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 17 ▶use Scalar::Util qw(reftype);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 17 ▶use MooseX::Types::Moose qw(Str Int ClassName ArrayRef HashRef);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 17 ▶use MooseX::Types -declare => [qw/
Subroutine BEGIN: called CC=1 SCAR=0.0
10 TestBuilder SchemaManagerClass ConnectInfo FixtureClass
11 ReplicantsConnectInfo
12 17 /];
13 17 ▶use Module::Runtime qw(use_module);
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 17 subtype TestBuilder,
16 as class_type('Test::Builder');
17  
18 17 subtype SchemaManagerClass,
19 as ClassName;
20  
21 coerce SchemaManagerClass,
22 from Str,
23 13 ▶ via {
Subroutine __ANON__: called CC=1 SCAR=0.0
24 13 my $type = $_;
25 13 return use_module($type);
26 17 };
27  
28 17 subtype FixtureClass,
29 as ClassName;
30  
31 coerce FixtureClass,
32 from Str,
33 23 ▶ via {
Subroutine __ANON__: called CC=2 SCAR=7.1
34 23 my $type = $_;
35 23 ▶ $type = "Test::DBIx::Class::FixtureCommand".$type if $type =~m/^::/;
Branch: 1 branch
BranchTrueFalseTotal
if $type =~ /^::/ 23 0 23
36 23 return use_module($type);
37 17 };
38  
39 ## ConnectInfo cargo culted from "Catalyst::Model::DBIC::Schema::Types"
40 subtype ConnectInfo,
41 as HashRef,
42 28 ▶ where { exists $_->{dsn} },
Subroutine __ANON__: called CC=1 SCAR=0.0
43 0 ▶ message { 'Does not look like a valid connect_info' };
Subroutine __ANON__: not called CC=1 SCAR=1.2
44  
45 17 coerce ConnectInfo,
46 from Str,
47 via(\&_coerce_connect_info_from_str),
48 from ArrayRef,
49 via(\&_coerce_connect_info_from_arrayref);
50  
51  
52 28 ▶sub _coerce_connect_info_from_arrayref {
Subroutine _coerce_connect_info_from_arrayref: called CC=12 SCAR=29.3
53 28 my %connect_info;
54  
55 # make a copy
56 28 $_ = [ @$_ ];
57  
58 28 ▶ if (!ref $_->[0]) { # array style
Branch: 2 branches
BranchTrueFalseTotal
if (not ref $_->[0]) { } 28 0 28
elsif (@$_ == 1 and builtin::reftype($_->[0]) eq 'HASH') { } 0 0 0
59 28 $connect_info{dsn} = shift @$_;
60 28 ▶ $connect_info{user} = shift @$_ if !ref $_->[0];
Branch: 1 branch
BranchTrueFalseTotal
unless ref $_->[0] 28 0 28
61 28 ▶ $connect_info{password} = shift @$_ if !ref $_->[0];
Branch: 1 branch
BranchTrueFalseTotal
unless ref $_->[0] 28 0 28
62  
63 28 for my $i (0..1) {
64 32 my $extra = shift @$_;
65 32 ▶ last unless $extra;
Branch: 1 branch
BranchTrueFalseTotal
unless $extra 28 4 32
66 4 ▶ die "invalid connect_info" unless reftype $extra eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::reftype($extra) eq "HASH" 0 4 4
67  
68 4 %connect_info = (%connect_info, %$extra);
69 }
70  
71 28 ▶ die "invalid connect_info" if @$_;
Branch: 1 branch
BranchTrueFalseTotal
if @$_ 0 28 28
72 ▶ } elsif (@$_ == 1 && reftype $_->[0] eq 'HASH') {
Condition0%0/3
@$_ == 1 and builtin::reftype($_->[0]) eq "HASH"
!ll&&!rl&&r
000
MC/DC0%0/2
@$_ == 1 and builtin::reftype($_->[0]) eq "HASH"
@$_ == 1 builtin::reftype($_->[0]) eq "HASH"
Truth table0%0/3
A and B
A= @$_ == 1B= builtin::reftype($_->[0]) eq "HASH"
ABresult
0X0
100
111
73 0 return $_->[0];
74 } else {
75 0 die "invalid connect_info";
76 }
77  
78 28 for my $key (qw/user password/) {
79 $connect_info{$key} = ''
80 56 ▶ if not defined $connect_info{$key};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $connect_info{$key} 0 56 56
81 }
82  
83 28 \%connect_info;
84 }
85  
86 0 ▶sub _coerce_connect_info_from_str {
Subroutine _coerce_connect_info_from_str: not called CC=1 SCAR=6.9
87 0 +{ dsn => $_, user => '', password => '' }
88 }
89  
90  
91 17 subtype ReplicantsConnectInfo,
92 as ArrayRef[ConnectInfo];
93  
94 coerce ReplicantsConnectInfo,
95 from Int,
96 0 ▶ via { [map { +{dsn=>'', user=>'', password=>''} } (1..$_)] },
Subroutine __ANON__: not called CC=1 SCAR=6.9
97 from ArrayRef[Str],
98 0 ▶ via {
Subroutine __ANON__: not called CC=1 SCAR=6.9
99 0 [map { &_coerce_connect_info_from_str($_) } @$_];
100 },
101 from ArrayRef[ArrayRef],
102 0 ▶ via {
Subroutine __ANON__: not called CC=1 SCAR=6.9
103 0 [map { &_coerce_connect_info_from_arrayref($_) } @$_];
104 17 };
105  
106 17 1;
107  
108 =head1 NAME
109  
110 Test::DBIx::Class::Types - Type Constraint Library
111  
112 =head1 DESCRIPTION
113  
114 L<MooseX::Types> based type constraint library
115  
116 =head1 AUTHOR
117  
118 John Napiorkowski C<< <jjnapiork@cpan.org> >>
119  
120 Code gratuitously cargo culted from L<Catalyst::Model::DBIC::Schema::Types>
121  
122 =head1 COPYRIGHT & LICENSE
123  
124 Copyright 2009, John Napiorkowski C<< <jjnapiork@cpan.org> >>
125  
126 This program is free software; you can redistribute it and/or modify
127 it under the same terms as Perl itself.
128  
129 =cut
130  
« Class/FixtureCommand/Populate.pm ↑ Summary Class/SchemaManager.pm »