blib/lib/YATT/Lite/WebMVC0/DBSchema/DBIC.pm

filter: Statementstmt 71.3% 187 / 262 Branchbran 42.1% 43 / 102 Conditioncond 39.2% 11 / 28 MC/DCmcdc 11.7% 2 / 17 Subroutinesub 79.0% 34 / 43 Podpod 0.0% 0 / 12 totaltotal 59.7% 277 / 464 CC 64 SCAR 32.7
CC
64
Cov
61%
to_find
126.5
startup
30.0
build_dbic
27.0
CRAP 26.3
« blib/lib/YATT/Lite/Test/LangServerClient.pm ↑ Summary blib/lib/YATT/Lite/WebMVC0/SiteApp.pm »
1 package YATT::Lite::WebMVC0::DBSchema::DBIC; sub MY () {__PACKAGE__}
2 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 2 ▶use warnings qw(FATAL all NONFATAL misc);
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 2 ▶use base qw(YATT::Lite::WebMVC0::DBSchema);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use YATT::Lite::MFields qw(_DBIC DBIC);
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 2 ▶use YATT::Lite::Util::AsBase qw/_import_as_base/;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 2 ▶use Scalar::Util qw/weaken/;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 2 require DBIx::Class::Core;
13  
14 4 ▶sub DBIC_SCHEMA {'YATT::Lite::WebMVC0::DBSchema::DBIC::DBIC_SCHEMA'}
Subroutine DBIC_SCHEMA: called CC=1 SCAR=0.0
Pod undocumented
15  
16 use YATT::Lite::Types
17 2 ▶ ([Table => -fields => [qw(package components)]]
Subroutine BEGIN: called CC=1 SCAR=0.0
18 , [Column => -fields => [qw(dbic_opts)]]
19 2 );
20  
21 2 ▶use YATT::Lite::Util qw(globref define_const lexpand terse_dump);
Subroutine BEGIN: called CC=1 SCAR=0.0
22  
23 5 ▶sub dbic {
Subroutine dbic: called CC=3 SCAR=11.4
Pod undocumented
24 5 (my MY $schema) = @_;
25 5 ▶ $schema->{_DBIC} //= do {
Condition66%2/3
$schema->{"_DBIC"} //= do { if ($schema->{"debug"}) { print STDERR "INFO: DBSchema($schema) DBIC->connect", qq[, class = $schema->{"DBIC"}\n]; } ; builtin::weaken($schema); $schema->{"DBIC"}->connect(sub { $schema->make_connection; } ) }
l!l&&r!l&&!r
410
MC/DC0%0/2
$schema->{"_DBIC"} //= do { if ($schema->{"debug"}) { print STDERR "INFO: DBSchema($schema) DBIC->connect", qq[, class = $schema->{"DBIC"}\n]; } ; builtin::weaken($schema); $schema->{"DBIC"}->connect(sub { $schema->make_connection; } ) }
$schema->{"_DBIC"} do { if ($schema->{"debug"}) { print STDERR "INFO: DBSchema($schema) DBIC->connect", qq[, class = $schema->{"DBIC"}\n]; } ; builtin::weaken($schema); $schema->{"DBIC"}->connect(sub { $schema->make_connection; } ) }
Truth table66%2/3
A //= B
A= $schema->{"_DBIC"}B= do { if ($schema->{"debug"}) { print STDERR "INFO: DBSchema($schema) DBIC->connect", qq[, class = $schema->{"DBIC"}\n]; } ; builtin::weaken($schema); $schema->{"DBIC"}->connect(sub { $schema->make_connection; } ) }
ABresult
1X1
011
000
26 1 ▶ if ($schema->{debug}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($schema->{"debug"}) 0 1 1
27 0 print STDERR "INFO: DBSchema($schema) DBIC->connect"
28 , ", class = $schema->{DBIC}\n";
29 }
30 1 weaken($schema); # !! This is very important to avoid memleak!
31 1 ▶ $schema->{DBIC}->connect(sub {$schema->make_connection});
Subroutine __ANON__: called CC=1 SCAR=0.0
32 };
33 }
34  
35 0 ▶sub connect {
Subroutine connect: not called CC=3 SCAR=24.8
Pod undocumented
36 0 ▶ my MY $schema = ref $_[0] ? shift->clone : shift->new;
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] ? : 0 0 0
37 0 $schema->{_DBIC} = $schema->{DBIC}->connect(@_);
38 0 ▶ if ($schema->{debug}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($schema->{"debug"}) 0 0 0
39 0 print STDERR "INFO: DBSchema($schema)::connect"
40 ,", class = $schema->{DBIC}\n";
41 }
42 0 $schema;
43 }
44  
45 1 ▶sub disconnect {
Subroutine disconnect: called CC=1 SCAR=0.0
Pod undocumented
46 1 (my MY $schema, my ($msg)) = @_;
47 1 $schema->reset;
48 1 $schema->SUPER::disconnect($msg);
49 }
50  
51 2 ▶sub reset {
Subroutine reset: called CC=1 SCAR=0.0
Pod undocumented
52 2 (my MY $self) = @_;
53 2 $self->SUPER::reset;
54 2 delete $self->{_DBIC};
55 }
56  
57 0 ▶sub txn_do {
Subroutine txn_do: not called CC=2 SCAR=17.9
Pod undocumented
58 0 (my MY $schema, my $sub) = splice @_, 0, 2;
59 0 ▶ $schema->dbic->txn_do($sub, @_ ? @_ : $schema->{_DBIC});
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 0 0 0
60 }
61  
62 0 ▶sub startup {
Subroutine startup: not called CC=5 SCAR=34.0
Pod undocumented
63 0 (my MY $schema, my (@apps)) = @_;
64 0 ▶ unless ($schema->{DBIC}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($schema->{"DBIC"}) 0 0 0
65 0 croak "DBIC classname parameter is empty!";
66 }
67 0 ▶ unless ($schema->{DBIC} =~ /::/) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($schema->{"DBIC"} =~ /::/) 0 0 0
68 0 croak "DBIC classname MUST has '::'! $schema->{DBIC}";
69 }
70 0 $schema->SUPER::startup(@apps);
71 0 $schema->build_dbic($schema->{DBIC});
72 0 ▶ if (my (@args) = $schema->{DBH}
Branch: 1 branch
BranchTrueFalseTotal
if (my(@args) = $schema->{"DBH"} || lexpand($schema->{"connection_spec"})) 0 0 0
Condition0%0/3
$schema->{'DBH'} || lexpand($schema->{'connection_spec'})
l!l&&r!l&&!r
000
MC/DC0%0/2
$schema->{'DBH'} || lexpand($schema->{'connection_spec'})
$schema->{'DBH'} lexpand($schema->{'connection_spec'})
Truth table0%0/3
A || B
A= $schema->{'DBH'}B= lexpand($schema->{'connection_spec'})
ABresult
1X1
011
000
73 || lexpand($schema->{connection_spec})) {
74 0 $schema->connect(@args);
75 }
76 }
77  
78 1 ▶sub default_dbi_attr {
Subroutine default_dbi_attr: called CC=1 SCAR=0.0
Pod undocumented
79 1 (shift->SUPER::default_dbi_attr, AutoCommit => 1);
80 }
81  
82 4 ▶sub import {
Subroutine import: called CC=2 SCAR=7.1
83 4 YATT::Lite::Util::AsBase::parse_args(\@_, scalar caller);
84 4 ▶ return unless @_ >= 2;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ >= 2 0 4 4
85 4 goto &build_dbic;
86 }
87  
88 # use YATT::Lite::WebMVC0::DBSchema::DBIC $pkg => @desc;
89 #
90 # $pkg ISA DBIC_SCHEMA (ISA DBIx::Class::Schema)
91 # ${pkg}::Result::$tab ISA DBIx::Class::Core
92  
93 # XXX: Make sure build_dbic is callable many times.
94 4 ▶sub build_dbic {
Subroutine build_dbic: called CC=23 SCAR=33.0
Pod undocumented
95 4 my ($class_or_obj, $DBIC) = splice @_, 0, 2;
96 4 (my $myPkg, my MY $schema) = do {
97 4 ▶ if (ref $class_or_obj) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $class_or_obj) { } 0 4 4
98 0 (ref $class_or_obj, $class_or_obj);
99 } else {
100 4 ($class_or_obj, $class_or_obj->new(@_));
101 }
102 };
103  
104 4 ▶ $DBIC //= caller() . '::DBIC';
Condition50%1/2
$DBIC //= (caller()) . '::DBIC'
l!l
40
MC/DC0%0/1
$DBIC //= (caller()) . '::DBIC'
$DBIC
Truth table50%1/2
A
A= $DBIC
Aresult
11
00
105 {
106 4 my $sym = globref($DBIC, undef);
107 4 ▶ unless (*{$sym}{CODE}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (*{$sym;}{"CODE"}) 4 0 4
108 4 define_const($sym, $DBIC);
109 }
110 }
111  
112 # DBIC->YATT_DBSchema holds YATT::Lite::WebMVC0::DBSchema::DBIC instance.
113 {
114 4 my $sym = globref($DBIC, 'YATT_DBSchema');
115 4 ▶ unless (*{$sym}{CODE}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (*{$sym;}{"CODE"}) 4 0 4
116 10 ▶ *$sym = sub {
Subroutine __ANON__: called CC=5 SCAR=16.6
117 10 my $dbic = shift;
118 print STDERR "DEBUG: DBIC->YATT_DBSchema is called\n"
119 10 ▶ if $schema->{debug};
Branch: 1 branch
BranchTrueFalseTotal
if $schema->{"debug"} 0 10 10
120 # Class method として呼んだときは, schema に set しない。
121 10 ▶ $schema->{_DBIC} ||= $dbic
Branch: 1 branch
BranchTrueFalseTotal
if defined $dbic and ref $dbic 9 1 10
Condition66%4/6
defined $dbic and ref $dbic
!ll&&!rl&&r
019
$schema->{"_DBIC"} ||= $dbic
l!l&&r!l&&!r
540
MC/DC50%1/2
defined $dbic and ref $dbic
defined $dbic ref $dbic
MC/DC0%0/2
$schema->{"_DBIC"} ||= $dbic
$schema->{"_DBIC"} $dbic
Truth table66%2/3
A and B
A= defined $dbicB= ref $dbic
ABresult
0X0
100
111
Truth table66%2/3
A ||= B
A= $schema->{"_DBIC"}B= $dbic
ABresult
1X1
011
000
122 if defined $dbic and ref $dbic; # XXX: weaken??
123 10 $schema;
124 4 };
125 }
126 }
127 4 $schema->{DBIC} = $DBIC;
128  
129 4 *{globref($DBIC, 'ISA')} = [$myPkg->DBIC_SCHEMA];
130 4 $myPkg->add_inc($DBIC);
131  
132 4 foreach my Table $tab (@{$schema->{_table_list}}) {
133 # XXX: 正確には rowClass よね、これって。
134 # XXX: じゃぁ ResultSet の方は作らなくてよいのか?
135 my $tabClass = $tab->{package}
136 11 = join('::', $DBIC, Result => $tab->{name});
137 11 *{globref($tabClass, 'ISA')} = ['DBIx::Class::Core'];
138 11 $myPkg->add_inc($tabClass);
139  
140 11 my Column $pk;
141 11 my @comp = (qw/Core/, lexpand($tab->{components}));
142  
143 11 ▶ if ($tab->{view}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tab->{'view'}) { } 1 10 11
144 1 $tabClass->load_components(@comp);
145 1 $tabClass->table_class('DBIx::Class::ResultSource::View');
146 # ------------- (order is important!) ----------------
147 1 $tabClass->table($tab->{name});
148 1 $tabClass->result_source_instance->view_definition($tab->{view});
149 1 ▶ $tabClass->result_source_instance->is_virtual($tab->{virtual} ? 1 : 0);
Branch: 1 branch
BranchTrueFalseTotal
$tab->{'virtual'} ? : 0 1 1
150 } else {
151 10 $pk = $schema->get_table_pk($tab);
152 10 ▶ push @comp, qw(PK::Auto) if $pk and $pk->{autoincrement};
Branch: 1 branch
BranchTrueFalseTotal
if $pk and $pk->{"autoincrement"} 9 1 10
Condition66%2/3
$pk and $pk->{"autoincrement"}
!ll&&!rl&&r
019
MC/DC50%1/2
$pk and $pk->{"autoincrement"}
$pk $pk->{"autoincrement"}
Truth table66%2/3
A and B
A= $pkB= $pk->{"autoincrement"}
ABresult
0X0
100
111
153 10 $tabClass->load_components(@comp);
154 10 $tabClass->table($tab->{name});
155 }
156  
157 11 my @constraints = lexpand($tab->{_chk_unique});
158 {
159 11 my @colSpecs;
160 11 foreach my Column $col (@{$tab->{_col_list}}) {
161 # dbic_opts;
162 my %dbic_opts = (data_type => $col->{type}
163 , ($col->{autoincrement} ? (is_auto_increment => 1) : ())
164 42 ▶ , map(defined $_ ? %$_ : (), $col->{dbic_opts}));
Branch: 2 branches
BranchTrueFalseTotal
$col->{'autoincrement'} ? : 9 33 42
defined $_ ? : 0 42 42
165 42 push @colSpecs, $col->{name} => \%dbic_opts;
166 42 ▶ push @constraints, [$col->{name}] if $col->{unique};
Branch: 1 branch
BranchTrueFalseTotal
if $col->{"unique"} 0 42 42
167 }
168 11 $tabClass->add_columns(@colSpecs);
169 }
170 11 ▶ $tabClass->set_primary_key($schema->get_table_pk($tab)) if $pk;
Branch: 1 branch
BranchTrueFalseTotal
if $pk 10 1 11
171 11 foreach my $uniq (@constraints) {
172 0 my $ixname = join("_", $tabClass, @$uniq);
173 0 ▶ print STDERR <<END if $schema->{verbose};
Branch: 1 branch
BranchTrueFalseTotal
if $schema->{"verbose"} 0 0 0
174 0 -- $tabClass->add_unique_constraint($ixname, [@{[join ", ", @$uniq]}])
175 END
176 0 $tabClass->add_unique_constraint($ixname, $uniq);
177 }
178 }
179 # Relationship の設定と、 register_class の呼び出し。
180 4 foreach my Table $tab (@{$schema->{_table_list}}) {
181 11 my $tabClass = $tab->{package};
182 11 foreach my $rel ($schema->list_relations($tab->{name})) {
183 12 my ($relType, @relOpts) = @$rel;
184 12 ▶ if (my $sub = $myPkg->can("add_relation_$relType")) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $sub = $myPkg->can("add_relation_$relType")) 2 10 12
185 2 $sub->($myPkg, $schema, $tab, @relOpts);
186 2 next;
187 }
188  
189 10 my ($relName, $fkName, $fTabName) = @relOpts;
190 10 ▶ unless (defined $fTabName) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $fTabName) 0 10 10
191 0 croak "Foreign table is empty for $tab->{name} $relType $relName $fkName";
192 }
193 10 my $fTab = $schema->{_table_dict}{$fTabName};
194 # table の package 名が確定するまで、relation の設定を遅延させたいから。
195 10 ▶ print STDERR <<END if $schema->{verbose};
Branch: 1 branch
BranchTrueFalseTotal
if $schema->{"verbose"} 0 10 10
196 0 -- $tabClass->$relType($relName, $fTab->{package}, @{[terse_dump($fkName)]})
197 END
198 10 eval {
199 10 $tabClass->$relType($relName, $fTab->{package}, $fkName);
200 };
201 10 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 10 10
202 die "Relationship Error in: $relType $relName, foreign="
203 0 .$fTab->{package}.": $@";
204 }
205 }
206 # register_class は Relationship 設定が済んでからじゃないとダメ?
207 11 $DBIC->register_class($tab->{name}, $tabClass);
208 }
209  
210 4 $schema;
211 }
212  
213 # XXX: 上と被っているので、まとめるべし。
214 2 ▶sub add_relation_many_to_many {
Subroutine add_relation_many_to_many: called CC=3 SCAR=11.8
Pod undocumented
215 2 (my $myPkg, my MY $schema, my Table $tab
216 , my ($relName, $fkName, $tabName)) = @_;
217 2 my $relType = 'many_to_many';
218 2 my $tabClass = $tab->{package};
219 2 ▶ print STDERR <<END if $schema->{verbose};
Branch: 1 branch
BranchTrueFalseTotal
if $schema->{"verbose"} 0 2 2
220 0 -- $tabClass->$relType($relName, $tabName, @{[terse_dump($fkName)]})
221 END
222 2 eval {
223 2 $tabClass->$relType($relName, $tabName, $fkName)
224 };
225 2 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 2 2
226 0 die "Relationship Error in: $relType ($relName, $tabName, $fkName)".$@;
227 }
228 }
229  
230 2 *deploy = *ensure_created; *deploy = *ensure_created;
231 4 ▶sub ensure_created {
Subroutine ensure_created: called CC=2 SCAR=7.2
Pod undocumented
232 4 (my MY $self, my $dbic) = @_;
233 4 ▶ $dbic ||= $self->{_DBIC};
Condition33%1/3
$dbic ||= $self->{"_DBIC"}
l!l&&r!l&&!r
040
MC/DC0%0/2
$dbic ||= $self->{"_DBIC"}
$dbic $self->{"_DBIC"}
Truth table33%1/3
A ||= B
A= $dbicB= $self->{"_DBIC"}
ABresult
1X1
011
000
234 $dbic->storage->dbh_do
235 4 ▶ (sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
236 4 (my ($storage, $dbh), my MY $self) = @_;
237 4 $self->ensure_created_on($dbh);
238 4 }, $self)
239 }
240  
241 # XXX: delegate は、やりすぎだったかもしれない。
242 76 ▶sub add_delegate {
Subroutine add_delegate: called CC=2 SCAR=6.9
Pod undocumented
243 76 my ($pack) = shift;
244 76 my ($alias, $dbic_method) = do {
245 76 ▶ if (@_ == 2) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ == 2) { } 2 74 76
246 2 @_;
247 } else {
248 74 ($_[0], $_[0]);
249 }
250 };
251 76 ▶ *{globref($pack, $alias)} = sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
252 4 my MY $self = shift;
253 4 $self->dbic->$dbic_method(@_);
254 76 };
255 }
256  
257 2 foreach my $name (keys %DBIx::Class::Schema::) {
258 152 ▶ next unless $name =~ /^[a-z]\w*$/;
Branch: 1 branch
BranchTrueFalseTotal
unless $name =~ /^[a-z]\w*$/ 52 100 152
259 100 ▶ next unless *{$DBIx::Class::Schema::{$name}}{CODE};
Branch: 1 branch
BranchTrueFalseTotal
unless *{$DBIx::Class::Schema::{$name};}{"CODE"} 18 82 100
260 82 ▶ next if MY->can($name);
Branch: 1 branch
BranchTrueFalseTotal
if "YATT::Lite::WebMVC0::DBSchema::DBIC"->can($name) 8 74 82
261 74 MY->add_delegate($name);
262 }
263  
264 2 MY->add_delegate(model => 'resultset');
265  
266 {
267 package YATT::Lite::WebMVC0::DBSchema::DBIC::DBIC_SCHEMA;
268 2 ▶ use base qw(DBIx::Class::Schema);
Subroutine BEGIN: called CC=1 SCAR=0.0
269 2 ▶ use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
270 # XXX: Should this hold (weakened) ref to DBSchema?
271  
272 # Aid to migrate from YATT_DBSchema->to_zzz methods.
273 3 ▶ sub to_find {
Subroutine to_find: called CC=14 SCAR=48.4
274 3 my ($dbic, $tabName, $keyCol, $rowidCol) = @_;
275 3 my $rs = $dbic->resultset($tabName);
276 3 my $dbh = $dbic->storage->dbh;
277 3 ▶ unless (defined $keyCol) {
Branch: 3 branches
BranchTrueFalseTotal
if (defined $keyCol) { } 3 0 3
if (do { ref $keyCol eq 'ARRAY' }) { } 0 3 3
elsif (not defined $rowidCol) { } 3 0 3
278 0 ▶ sub { $rs->find(@_) }
Subroutine __ANON__: not called CC=1 SCAR=6.9
279 0 } elsif (ref $keyCol eq 'ARRAY') {
280 0 my (@sql, @cols, @atts);
281 0 foreach (@$keyCol) {
282 0 ▶ push @atts, $_ and next if ref $_ eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
if ref $_ eq "HASH" 0 0 0
Condition0%0/5
ref $_ eq 'HASH' && (push(@atts, $_) && (next))
!ll&&!rl&&r
000
push @atts, $_ and next
!ll
00
MC/DC0%0/2
ref $_ eq 'HASH' && (push(@atts, $_) && (next))
ref $_ eq 'HASH' push @atts, $_
Truth table0%0/3
A && B
A= ref $_ eq 'HASH'B= push @atts, $_
ABresult
0X0
100
111
283 0 push @sql, do {
284 0 ▶ if (ref $_) {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $_) { } 0 0 0
elsif (/\?/) { } 0 0 0
285 0 my ($col, @comp) = @$_;
286 0 ▶ unless (@comp) {
Branch: 3 branches
BranchTrueFalseTotal
if (@comp) { } 0 0 0
if (do { @comp == 1 }) { } 0 0 0
elsif (@comp % 2 == 0) { } 0 0 0
287 0 push @cols, $col;
288 0 $col . ' = ?';
289 } elsif (@comp == 1) {
290 0 $dbh->quote_identifier($col) . ' = ' . $dbh->quote($comp[0]);
291 } elsif (@comp % 2 == 0) {
292 0 my @sql = $dbh->quote_identifier($col);
293 0 ▶ while (my ($kw, $value) = splice @comp, 0, 2) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = splice(@comp, 0, 2)) 0 0 0
294 0 push @sql, $kw, $dbh->quote($value);
295 }
296 0 join " ", @sql;
297 } else {
298 0 croak "Invalid column spec: $col, @comp";
299 }
300 } elsif (/\?/) {
301 0 ▶ my ($col) = /^(\w+)/
Branch: 1 branch
BranchTrueFalseTotal
my($col) = /^(\w+)/ or croak("Can't extract colname from colspec: $_") 0 0 0
302 or croak "Can't extract colname from colspec: $_";
303 0 push @cols, $col;
304 0 $_;
305 } else {
306 0 push @cols, $_;
307 0 $dbh->quote_identifier($_) . ' = ?';
308 }
309 }
310 }
311 0 my $sql = join " AND ", @sql;
312 0 ▶ sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
313 0 my (@value) = @_;
314 0 ▶ unless (@value == @cols) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@value == @cols) 0 0 0
315 0 croak "bind param length mismatch for $sql!(@{[scalar @value]})";
316 }
317 0 ▶ my $row = $rs->search(\ [$sql, zip(\@cols, \@value)], @atts)->single
Branch: 1 branch
BranchTrueFalseTotal
my $row = $rs->search(\[$sql, zip(\@cols, \@value)], @atts)->single or return undef 0 0 0
318 or return undef;
319 0 $row->id;
320 0 };
321 } elsif (not defined $rowidCol) {
322 4 ▶ sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
323 4 my ($value) = @_;
324 4 ▶ my $row = $rs->find({$keyCol => $value})
Branch: 1 branch
BranchTrueFalseTotal
my $row = $rs->find({$keyCol, $value}) or return undef 3 1 4
325 or return undef;
326 3 $row->id;
327 3 };
328 } else {
329 0 ▶ sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
330 0 my ($value) = @_;
331 0 ▶ my $row = $rs->find({$keyCol => $value})
Branch: 1 branch
BranchTrueFalseTotal
my $row = $rs->find({$keyCol, $value}) or return undef 0 0 0
332 or return undef;
333 0 $row->get_column($rowidCol);
334 0 };
335 }
336 }
337  
338 3 ▶ sub to_insert {
Subroutine to_insert: called CC=3 SCAR=11.7
339 3 my ($dbic, $tabName, @fields) = @_;
340 3 my $rs = $dbic->resultset($tabName);
341 3 ▶ unless (my ($pkCol, @morePkCol) = $rs->result_source->primary_columns) {
Branch: 2 branches
BranchTrueFalseTotal
if (() = $rs->result_source->primary_columns) { } 3 0 3
if (do { @morePkCol }) { } 0 3 3
342 # If primary key is not defined, row obj is returned.
343 0 $dbic->to_insert_obj($tabName, @fields);
344 } elsif (@morePkCol) {
345 0 croak "table '$tabName' has multiple pk col, use to_insert_obj() please!";
346 } else {
347 4 ▶ sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
348 4 my %rec;
349 4 @rec{@fields} = @_;
350 4 my $row = $rs->new(\%rec)->insert;
351 4 $row->get_column($pkCol);
352 }
353 3 }
354 }
355  
356 # This returns row object, not primary key.
357 0 ▶ sub to_insert_obj {
Subroutine to_insert_obj: not called CC=1 SCAR=6.9
358 0 my ($dbic, $tabName, @fields) = @_;
359 0 my $rs = $dbic->resultset($tabName);
360 0 ▶ sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
361 0 my %rec;
362 0 @rec{@fields} = @_;
363 0 $rs->new(\%rec)->insert;
364 0 };
365 }
366  
367 1 ▶ sub to_encode {
Subroutine to_encode: called CC=1 SCAR=0.0
368 1 my ($dbic, $tabName, $keyCol, @otherCols) = @_;
369 1 my $to_find = $dbic->to_find($tabName, $keyCol);
370 1 my $to_ins = $dbic->to_insert($tabName, $keyCol, @otherCols);
371  
372 2 ▶ sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
373 2 my ($value, @rest) = @_;
374 2 ▶ $to_find->($value) || $to_ins->($value, @rest);
Branch: 1 branch
BranchTrueFalseTotal
&$to_find($value) or &$to_ins($value, @rest) 1 1 2
375 1 };
376 }
377  
378 2 ▶ sub to_fetch {
Subroutine to_fetch: called CC=1 SCAR=0.0
379 2 my ($dbic, $tabName, $keyColList, $resColList, @rest) = @_;
380 2 my $sql = $dbic->YATT_DBSchema
381 ->sql_to_fetch($tabName, $keyColList, $resColList, @rest);
382 2 my $storage = $dbic->storage;
383 # XXX: dbh_do
384 2 my $sth;
385 2 ▶ sub {
Subroutine __ANON__: called CC=2 SCAR=7.4
386 2 my (@value) = @_;
387 2 ▶ $sth ||= $storage->dbh->prepare($sql);
Condition33%1/3
$sth ||= $storage->dbh->prepare($sql)
l!l&&r!l&&!r
020
MC/DC0%0/2
$sth ||= $storage->dbh->prepare($sql)
$sth $storage->dbh->prepare($sql)
Truth table33%1/3
A ||= B
A= $sthB= $storage->dbh->prepare($sql)
ABresult
1X1
011
000
388 2 $sth->execute(@value);
389 2 $sth;
390 }
391 2 }
392  
393 0 ▶ sub zip {
Subroutine zip: not called CC=3 SCAR=24.8
394 0 my @res;
395 0 ▶ for (my $i = 0; $i < @{$_[0]}; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @{$_[0];}) 0 0 0
396 0 push @res, [map {$_->[$i]} @_];
397 }
398 0 ▶ wantarray ? @res : \@res;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
399 }
400 }
401  
402 2 ▶use YATT::Lite::Breakpoint ();
Subroutine BEGIN: called CC=1 SCAR=0.0
403 2 YATT::Lite::Breakpoint::break_load_dbschema_dbic();
404  
405 2 1;
« blib/lib/YATT/Lite/Test/LangServerClient.pm ↑ Summary blib/lib/YATT/Lite/WebMVC0/SiteApp.pm »