blib/lib/SQL/Translator/Schema/Table.pm

filter: Statementstmt 83.7% 324 / 387 Branchbran 71.9% 131 / 182 Conditioncond 75.6% 28 / 37 MC/DCmcdc 60.8% 14 / 23 Subroutinesub 97.6% 41 / 42 Podpod 100% 22 / 22 totaltotal 80.8% 560 / 693 CC 132 SCAR 44.9
CC
132
Cov
80%
equals
600.0
can_link
21.5
add_constraint
11.0
CRAP 89.4
« blib/lib/SQL/Translator/Producer/POD.pm ↑ Summary blib/lib/SQL/Translator/Producer/Sybase.pm »
1 package SQL::Translator::Schema::Table;
2  
3 =pod
4  
5 =head1 NAME
6  
7 SQL::Translator::Schema::Table - SQL::Translator table object
8  
9 =head1 SYNOPSIS
10  
11 use SQL::Translator::Schema::Table;
12 my $table = SQL::Translator::Schema::Table->new( name => 'foo' );
13  
14 =head1 DESCRIPTION
15  
16 C<SQL::Translator::Schema::Table> is the table object.
17  
18 =head1 METHODS
19  
20 =cut
21  
22 76 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
23 76 ▶use SQL::Translator::Utils qw(parse_list_arg ex2err throw carp_ro);
Subroutine BEGIN: called CC=1 SCAR=0.0
24 76 ▶use SQL::Translator::Types qw(schema_obj);
Subroutine BEGIN: called CC=1 SCAR=0.0
25 76 ▶use SQL::Translator::Role::ListAttr;
Subroutine BEGIN: called CC=1 SCAR=0.0
26 76 ▶use SQL::Translator::Schema::Constants;
Subroutine BEGIN: called CC=1 SCAR=0.0
27 76 ▶use SQL::Translator::Schema::Constraint;
Subroutine BEGIN: called CC=1 SCAR=0.0
28 76 ▶use SQL::Translator::Schema::Field;
Subroutine BEGIN: called CC=1 SCAR=0.0
29 76 ▶use SQL::Translator::Schema::Index;
Subroutine BEGIN: called CC=1 SCAR=0.0
30  
31 76 ▶use Carp::Clan '^SQL::Translator';
Subroutine BEGIN: called CC=1 SCAR=0.0
32 76 ▶use List::Util 'max';
Subroutine BEGIN: called CC=1 SCAR=0.0
33 76 ▶use Sub::Quote qw(quote_sub);
Subroutine BEGIN: called CC=1 SCAR=0.0
34  
35 76 extends 'SQL::Translator::Schema::Object';
36  
37 76 our $VERSION = '1.66';
38  
39 # Stringify to our name, being careful not to pass any args through so we don't
40 # accidentally set it to undef. We also have to tweak bool so the object is
41 # still true when it doesn't have a name (which shouldn't happen!).
42 use overload
43 476 ▶ '""' => sub { shift->name },
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
44 3538 ▶ 'bool' => sub { $_[0]->name || $_[0] },
Subroutine __ANON__: called CC=2 SCAR=7.6
Branch: 1 branch
BranchTrueFalseTotal
$_[0]->name or $_[0] 3538 0 3538
45 76 fallback => 1,
46 76 ;
47  
48 =pod
49  
50 =head2 new
51  
52 Object constructor.
53  
54 my $table = SQL::Translator::Schema::Table->new(
55 schema => $schema,
56 name => 'foo',
57 );
58  
59 =head2 add_constraint
60  
61 Add a constraint to the table. Returns the newly created
62 C<SQL::Translator::Schema::Constraint> object.
63  
64 my $c1 = $table->add_constraint(
65 name => 'pk',
66 type => PRIMARY_KEY,
67 fields => [ 'foo_id' ],
68 );
69  
70 my $c2 = SQL::Translator::Schema::Constraint->new( name => 'uniq' );
71 $c2 = $table->add_constraint( $constraint );
72  
73 =cut
74  
75 76 has _constraints => (
76 is => 'ro',
77 init_arg => undef,
78 default => quote_sub(q{ +[] }),
79 predicate => 1,
80 lazy => 1,
81 );
82  
83 612 ▶sub add_constraint {
Subroutine add_constraint: called CC=11 SCAR=24.0
Pod documented
84 612 my $self = shift;
85 612 my $constraint_class = 'SQL::Translator::Schema::Constraint';
86 612 my $constraint;
87  
88 612 ▶ if (UNIVERSAL::isa($_[0], $constraint_class)) {
Branch: 1 branch
BranchTrueFalseTotal
if (UNIVERSAL::isa($_[0], $constraint_class)) { } 3 609 612
89 3 $constraint = shift;
90 3 $constraint->table($self);
91 } else {
92 609 my %args = @_;
93 609 $args{'table'} = $self;
94 609 ▶ $constraint = $constraint_class->new(\%args)
Branch: 1 branch
BranchTrueFalseTotal
$constraint = $constraint_class->new(\%args) or return $self->error($constraint_class->error) 609 0 609
95 or return $self->error($constraint_class->error);
96 }
97  
98 #
99 # If we're trying to add a PK when one is already defined,
100 # then just add the fields to the existing definition.
101 #
102 612 my $ok = 1;
103 612 my $pk = $self->primary_key;
104 612 ▶ if ($pk && $constraint->type eq PRIMARY_KEY) {
Branch: 2 branches
BranchTrueFalseTotal
if ($pk and $constraint->type eq 'PRIMARY KEY') { } 79 533 612
elsif ($constraint->type eq 'PRIMARY KEY') { } 235 298 533
Condition100%3/3
$pk and $constraint->type eq "PRIMARY KEY"
!ll&&!rl&&r
31821579
MC/DC100%2/2
$pk and $constraint->type eq "PRIMARY KEY"
$pk $constraint->type eq "PRIMARY KEY"
Truth table100%3/3
A and B
A= $pkB= $constraint->type eq "PRIMARY KEY"
ABresult
0X0
100
111
105 79 $self->primary_key($constraint->fields);
106 79 ▶ $pk->name($constraint->name) if $constraint->name;
Branch: 1 branch
BranchTrueFalseTotal
if $constraint->name 0 79 79
107 79 my %extra = $constraint->extra;
108 79 ▶ $pk->extra(%extra) if keys %extra;
Branch: 1 branch
BranchTrueFalseTotal
if keys %extra 17 62 79
109 79 $constraint = $pk;
110 79 $ok = 0;
111 } elsif ($constraint->type eq PRIMARY_KEY) {
112 235 for my $fname ($constraint->fields) {
113 268 ▶ if (my $f = $self->get_field($fname)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $f = $self->get_field($fname)) 268 0 268
114 268 $f->is_primary_key(1);
115 }
116 }
117 }
118 #
119 # See if another constraint of the same type
120 # covers the same fields. -- This doesn't work! ky
121 #
122 # elsif ( $constraint->type ne CHECK_C ) {
123 # my @field_names = $constraint->fields;
124 # for my $c (
125 # grep { $_->type eq $constraint->type }
126 # $self->get_constraints
127 # ) {
128 # my %fields = map { $_, 1 } $c->fields;
129 # for my $field_name ( @field_names ) {
130 # if ( $fields{ $field_name } ) {
131 # $constraint = $c;
132 # $ok = 0;
133 # last;
134 # }
135 # }
136 # last unless $ok;
137 # }
138 # }
139  
140 612 ▶ if ($ok) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ok) 533 79 612
141 533 push @{ $self->_constraints }, $constraint;
142 }
143  
144 612 return $constraint;
145 }
146  
147 =head2 drop_constraint
148  
149 Remove a constraint from the table. Returns the constraint object if the index
150 was found and removed, an error otherwise. The single parameter can be either
151 an index name or an C<SQL::Translator::Schema::Constraint> object.
152  
153 $table->drop_constraint('myconstraint');
154  
155 =cut
156  
157 3 ▶sub drop_constraint {
Subroutine drop_constraint: called CC=4 SCAR=13.9
Pod documented
158 3 my $self = shift;
159 3 my $constraint_class = 'SQL::Translator::Schema::Constraint';
160 3 my $constraint_name;
161  
162 3 ▶ if (UNIVERSAL::isa($_[0], $constraint_class)) {
Branch: 1 branch
BranchTrueFalseTotal
if (UNIVERSAL::isa($_[0], $constraint_class)) { } 1 2 3
163 1 $constraint_name = shift->name;
164 } else {
165 2 $constraint_name = shift;
166 }
167  
168 3 ▶ if (!($self->_has_constraints && grep { $_->name eq $constraint_name } @{ $self->_constraints })) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_has_constraints and grep {$_->name eq $constraint_name;} @{$self->_constraints;}) 1 2 3
Condition66%2/3
$self->_has_constraints and grep {$_->name eq $constraint_name;} @{$self->_constraints;}
!ll&&!rl&&r
012
MC/DC50%1/2
$self->_has_constraints and grep {$_->name eq $constraint_name;} @{$self->_constraints;}
$self->_has_constraints grep {$_->name eq $constraint_name;} @{$self->_constraints;}
Truth table66%2/3
A and B
A= $self->_has_constraintsB= grep {$_->name eq $constraint_name;} @{$self->_constraints;}
ABresult
0X0
100
111
169 1 return $self->error(qq[Can't drop constraint: "$constraint_name" doesn't exist]);
170 }
171  
172 2 my @cs = @{ $self->_constraints };
173 my ($constraint_id)
174 2 = grep { $cs[$_]->name eq $constraint_name } (0 .. $#cs);
175 2 my $constraint = splice(@{ $self->_constraints }, $constraint_id, 1);
176  
177 2 return $constraint;
178 }
179  
180 =head2 add_index
181  
182 Add an index to the table. Returns the newly created
183 C<SQL::Translator::Schema::Index> object.
184  
185 my $i1 = $table->add_index(
186 name => 'name',
187 fields => [ 'name' ],
188 type => 'normal',
189 );
190  
191 my $i2 = SQL::Translator::Schema::Index->new( name => 'id' );
192 $i2 = $table->add_index( $index );
193  
194 =cut
195  
196 76 has _indices => (
197 is => 'ro',
198 init_arg => undef,
199 default => quote_sub(q{ [] }),
200 predicate => 1,
201 lazy => 1,
202 );
203  
204 157 ▶sub add_index {
Subroutine add_index: called CC=5 SCAR=16.1
Pod documented
205 157 my $self = shift;
206 157 my $index_class = 'SQL::Translator::Schema::Index';
207 157 my $index;
208  
209 157 ▶ if (UNIVERSAL::isa($_[0], $index_class)) {
Branch: 1 branch
BranchTrueFalseTotal
if (UNIVERSAL::isa($_[0], $index_class)) { } 3 154 157
210 3 $index = shift;
211 3 $index->table($self);
212 } else {
213 154 my %args = @_;
214 154 $args{'table'} = $self;
215 154 ▶ $index = $index_class->new(\%args)
Branch: 1 branch
BranchTrueFalseTotal
$index = $index_class->new(\%args) or return $self->error($index_class->error) 154 0 154
216 or return $self->error($index_class->error);
217 }
218 157 foreach my $ex_index ($self->get_indices) {
219 89 ▶ return if ($ex_index->equals($index));
Branch: 1 branch
BranchTrueFalseTotal
if $ex_index->equals($index) 0 89 89
220 }
221 157 push @{ $self->_indices }, $index;
222 157 return $index;
223 }
224  
225 =head2 drop_index
226  
227 Remove an index from the table. Returns the index object if the index was
228 found and removed, an error otherwise. The single parameter can be either
229 an index name of an C<SQL::Translator::Schema::Index> object.
230  
231 $table->drop_index('myindex');
232  
233 =cut
234  
235 3 ▶sub drop_index {
Subroutine drop_index: called CC=4 SCAR=13.9
Pod documented
236 3 my $self = shift;
237 3 my $index_class = 'SQL::Translator::Schema::Index';
238 3 my $index_name;
239  
240 3 ▶ if (UNIVERSAL::isa($_[0], $index_class)) {
Branch: 1 branch
BranchTrueFalseTotal
if (UNIVERSAL::isa($_[0], $index_class)) { } 1 2 3
241 1 $index_name = shift->name;
242 } else {
243 2 $index_name = shift;
244 }
245  
246 3 ▶ if (!($self->_has_indices && grep { $_->name eq $index_name } @{ $self->_indices })) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_has_indices and grep {$_->name eq $index_name;} @{$self->_indices;}) 1 2 3
Condition66%2/3
$self->_has_indices and grep {$_->name eq $index_name;} @{$self->_indices;}
!ll&&!rl&&r
012
MC/DC50%1/2
$self->_has_indices and grep {$_->name eq $index_name;} @{$self->_indices;}
$self->_has_indices grep {$_->name eq $index_name;} @{$self->_indices;}
Truth table66%2/3
A and B
A= $self->_has_indicesB= grep {$_->name eq $index_name;} @{$self->_indices;}
ABresult
0X0
100
111
247 1 return $self->error(qq[Can't drop index: "$index_name" doesn't exist]);
248 }
249  
250 2 my @is = @{ $self->_indices };
251 2 my ($index_id) = grep { $is[$_]->name eq $index_name } (0 .. $#is);
252 2 my $index = splice(@{ $self->_indices }, $index_id, 1);
253  
254 2 return $index;
255 }
256  
257 =head2 add_field
258  
259 Add an field to the table. Returns the newly created
260 C<SQL::Translator::Schema::Field> object. The "name" parameter is
261 required. If you try to create a field with the same name as an
262 existing field, you will get an error and the field will not be created.
263  
264 my $f1 = $table->add_field(
265 name => 'foo_id',
266 data_type => 'integer',
267 size => 11,
268 );
269  
270 my $f2 = SQL::Translator::Schema::Field->new(
271 name => 'name',
272 table => $table,
273 );
274 $f2 = $table->add_field( $field2 ) or die $table->error;
275  
276 =cut
277  
278 76 has _fields => (
279 is => 'ro',
280 init_arg => undef,
281 default => quote_sub(q{ +{} }),
282 predicate => 1,
283 lazy => 1
284 );
285  
286 1553 ▶sub add_field {
Subroutine add_field: called CC=8 SCAR=20.8
Pod documented
287 1553 my $self = shift;
288 1553 my $field_class = 'SQL::Translator::Schema::Field';
289 1553 my $field;
290  
291 1553 ▶ if (UNIVERSAL::isa($_[0], $field_class)) {
Branch: 1 branch
BranchTrueFalseTotal
if (UNIVERSAL::isa($_[0], $field_class)) { } 7 1546 1553
292 7 $field = shift;
293 7 $field->table($self);
294 } else {
295 1546 my %args = @_;
296 1546 $args{'table'} = $self;
297 1546 ▶ $field = $field_class->new(\%args)
Branch: 1 branch
BranchTrueFalseTotal
$field = $field_class->new(\%args) or return $self->error($field_class->error) 1545 1 1546
298 or return $self->error($field_class->error);
299 }
300  
301 1552 my $existing_order = { map { $_->order => $_->name } $self->get_fields };
302  
303 # supplied order, possible unordered assembly
304 1552 ▶ if ($field->order) {
Branch: 1 branch
BranchTrueFalseTotal
if ($field->order) { } 203 1349 1552
305 203 ▶ if ($existing_order->{ $field->order }) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$existing_order{$field->order}) 1 202 203
306 croak sprintf
307 "Requested order '%d' for column '%s' conflicts with already existing column '%s'",
308 $field->order,
309 $field->name,
310 1 $existing_order->{ $field->order },
311 ;
312 }
313 } else {
314 1349 ▶ my $last_field_no = max(keys %$existing_order) || 0;
Condition100%2/2
&max(keys %$existing_order) || 0
l!l
1068281
MC/DC100%1/1
&max(keys %$existing_order) || 0
&max(keys %$existing_order)
Truth table100%2/2
A
A= &max(keys %$existing_order)
Aresult
11
00
315 1349 ▶ if ($last_field_no != scalar keys %$existing_order) {
Branch: 1 branch
BranchTrueFalseTotal
if ($last_field_no != scalar keys %$existing_order) 1 1348 1349
316 1 croak sprintf
317 "Table '%s' field order incomplete - unable to auto-determine order for newly added field",
318 $self->name,
319 ;
320 }
321  
322 1348 $field->order($last_field_no + 1);
323 }
324  
325 # We know we have a name as the Field->new above errors if none given.
326 1550 my $field_name = $field->name;
327  
328 1550 ▶ if ($self->get_field($field_name)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->get_field($field_name)) { } 2 1548 1550
329 2 return $self->error(qq[Can't use field name "$field_name": field exists]);
330 } else {
331 1548 $self->_fields->{$field_name} = $field;
332 }
333  
334 1548 return $field;
335 }
336  
337 =head2 drop_field
338  
339 Remove a field from the table. Returns the field object if the field was
340 found and removed, an error otherwise. The single parameter can be either
341 a field name or an C<SQL::Translator::Schema::Field> object.
342  
343 $table->drop_field('myfield');
344  
345 =cut
346  
347 3 ▶sub drop_field {
Subroutine drop_field: called CC=7 SCAR=21.4
Pod documented
348 3 my $self = shift;
349 3 my $field_class = 'SQL::Translator::Schema::Field';
350 3 my $field_name;
351  
352 3 ▶ if (UNIVERSAL::isa($_[0], $field_class)) {
Branch: 1 branch
BranchTrueFalseTotal
if (UNIVERSAL::isa($_[0], $field_class)) { } 1 2 3
353 1 $field_name = shift->name;
354 } else {
355 2 $field_name = shift;
356 }
357 3 my %args = @_;
358 3 my $cascade = $args{'cascade'};
359  
360 3 ▶ if (!($self->_has_fields && exists $self->_fields->{$field_name})) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_has_fields and exists $self->_fields->{$field_name}) 1 2 3
Condition66%2/3
$self->_has_fields and exists $self->_fields->{$field_name}
!ll&&!rl&&r
012
MC/DC50%1/2
$self->_has_fields and exists $self->_fields->{$field_name}
$self->_has_fields exists $self->_fields->{$field_name}
Truth table66%2/3
A and B
A= $self->_has_fieldsB= exists $self->_fields->{$field_name}
ABresult
0X0
100
111
361 1 return $self->error(qq[Can't drop field: "$field_name" doesn't exists]);
362 }
363  
364 2 my $field = delete $self->_fields->{$field_name};
365  
366 2 ▶ if ($cascade) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cascade) 2 0 2
367  
368 # Remove this field from all indices using it
369 2 foreach my $i ($self->get_indices()) {
370 0 my @fs = $i->fields();
371 0 @fs = grep { $_ ne $field->name } @fs;
372 0 $i->fields(@fs);
373 }
374  
375 # Remove this field from all constraints using it
376 2 foreach my $c ($self->get_constraints()) {
377 0 my @cs = $c->fields();
378 0 @cs = grep { $_ ne $field->name } @cs;
379 0 $c->fields(@cs);
380 }
381 }
382  
383 2 return $field;
384 }
385  
386 =head2 comments
387  
388 Get or set the comments on a table. May be called several times to
389 set and it will accumulate the comments. Called in an array context,
390 returns each comment individually; called in a scalar context, returns
391 all the comments joined on newlines.
392  
393 $table->comments('foo');
394 $table->comments('bar');
395 print join( ', ', $table->comments ); # prints "foo, bar"
396  
397 =cut
398  
399 76 has comments => (
400 is => 'rw',
401 coerce => quote_sub(q{ ref($_[0]) eq 'ARRAY' ? $_[0] : [$_[0]] }),
402 default => quote_sub(q{ [] }),
403 );
404  
405 384 ▶around comments => sub {
Subroutine __ANON__: called CC=8 SCAR=20.8
406 384 my $orig = shift;
407 384 my $self = shift;
408 384 ▶ my @comments = ref $_[0] ? @{ $_[0] } : @_;
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] ? : 75 309 384
409  
410 384 for my $arg (@comments) {
411 274 ▶ $arg = $arg->[0] if ref $arg;
Branch: 1 branch
BranchTrueFalseTotal
if ref $arg 0 274 274
412 274 ▶ push @{ $self->$orig }, $arg if defined $arg && $arg;
Branch: 1 branch
BranchTrueFalseTotal
if defined $arg and $arg 167 107 274
Condition66%2/3
defined $arg and $arg
!ll&&!rl&&r
1070167
MC/DC50%1/2
defined $arg and $arg
defined $arg $arg
Truth table66%2/3
A and B
A= defined $argB= $arg
ABresult
0X0
100
111
413 }
414  
415 384 @comments = @{ $self->$orig };
416 return
417 wantarray ? @comments
418 384 ▶ : @comments ? join("\n", @comments)
Branch: 2 branches
BranchTrueFalseTotal
wantarray ? : 59 325 384
@comments ? : 72 253 325
419 : undef;
420 76 };
421  
422 =head2 get_constraints
423  
424 Returns all the constraint objects as an array or array reference.
425  
426 my @constraints = $table->get_constraints;
427  
428 =cut
429  
430 2760 ▶sub get_constraints {
Subroutine get_constraints: called CC=3 SCAR=11.0
Pod documented
431 2760 my $self = shift;
432  
433 2760 ▶ if ($self->_has_constraints) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_has_constraints) { } 2091 669 2760
434 2091 ▶ return wantarray ? @{ $self->_constraints } : $self->_constraints;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 2089 2 2091
435 } else {
436 669 $self->error('No constraints');
437 669 return;
438 }
439 }
440  
441 =head2 get_indices
442  
443 Returns all the index objects as an array or array reference.
444  
445 my @indices = $table->get_indices;
446  
447 =cut
448  
449 624 ▶sub get_indices {
Subroutine get_indices: called CC=3 SCAR=11.0
Pod documented
450 624 my $self = shift;
451  
452 624 ▶ if ($self->_has_indices) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_has_indices) { } 228 396 624
453 return wantarray
454 228 ▶ ? @{ $self->_indices }
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 227 1 228
455 : $self->_indices;
456 } else {
457 396 $self->error('No indices');
458 396 return;
459 }
460 }
461  
462 =head2 get_field
463  
464 Returns a field by the name provided.
465  
466 my $field = $table->get_field('foo');
467  
468 =cut
469  
470 5495 ▶sub get_field {
Subroutine get_field: called CC=7 SCAR=19.5
Pod documented
471 5495 my $self = shift;
472 5495 ▶ my $field_name = shift or return $self->error('No field name');
Branch: 1 branch
BranchTrueFalseTotal
my $field_name = shift() or return $self->error("No field name") 5495 0 5495
473 5495 my $case_insensitive = shift;
474 5495 ▶ return $self->error(qq[Field "$field_name" does not exist])
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_has_fields 366 5129 5495
475 unless $self->_has_fields;
476 5129 ▶ if ($case_insensitive) {
Branch: 1 branch
BranchTrueFalseTotal
if ($case_insensitive) 1 5128 5129
477 1 $field_name = uc($field_name);
478 1 foreach my $field (keys %{ $self->_fields }) {
479 2 ▶ return $self->_fields->{$field} if $field_name eq uc($field);
Branch: 1 branch
BranchTrueFalseTotal
if $field_name eq uc $field 1 1 2
480 }
481 0 return $self->error(qq[Field "$field_name" does not exist]);
482 }
483 return $self->error(qq[Field "$field_name" does not exist])
484 5128 ▶ unless exists $self->_fields->{$field_name};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->_fields->{$field_name} 1278 3850 5128
485 3850 return $self->_fields->{$field_name};
486 }
487  
488 =head2 get_fields
489  
490 Returns all the field objects as an array or array reference.
491  
492 my @fields = $table->get_fields;
493  
494 =cut
495  
496 2454 ▶sub get_fields {
Subroutine get_fields: called CC=4 SCAR=13.9
Pod documented
497 2454 my $self = shift;
498 9281 my @fields = map { $_->[1] }
499 16295 sort { $a->[0] <=> $b->[0] }
500 2454 ▶ map { [ $_->order, $_ ] } values %{ $self->_has_fields ? $self->_fields : {} };
Branch: 1 branch
BranchTrueFalseTotal
$self->_has_fields ? : 2105 349 2454
501  
502 2454 ▶ if (@fields) {
Branch: 1 branch
BranchTrueFalseTotal
if (@fields) { } 2105 349 2454
503 2105 ▶ return wantarray ? @fields : \@fields;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 2048 57 2105
504 } else {
505 349 $self->error('No fields');
506 349 return;
507 }
508 }
509  
510 =head2 is_valid
511  
512 Determine whether the view is valid or not.
513  
514 my $ok = $view->is_valid;
515  
516 =cut
517  
518 59 ▶sub is_valid {
Subroutine is_valid: called CC=5 SCAR=16.1
Pod documented
519 59 my $self = shift;
520 59 ▶ return $self->error('No name') unless $self->name;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->name 0 59 59
521 59 ▶ return $self->error('No fields') unless $self->get_fields;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->get_fields 2 57 59
522  
523 57 for my $object ($self->get_fields, $self->get_indices, $self->get_constraints) {
524 327 ▶ return $object->error unless $object->is_valid;
Branch: 1 branch
BranchTrueFalseTotal
unless $object->is_valid 3 324 327
525 }
526  
527 54 return 1;
528 }
529  
530 =head2 is_trivial_link
531  
532 True if table has no data (non-key) fields and only uses single key joins.
533  
534 =cut
535  
536 76 has is_trivial_link => (is => 'lazy', init_arg => undef);
537  
538 76 around is_trivial_link => carp_ro('is_trivial_link');
539  
540 3 ▶sub _build_is_trivial_link {
Subroutine _build_is_trivial_link: called CC=6 SCAR=17.9
541 3 my $self = shift;
542 3 ▶ return 0 if $self->is_data;
Branch: 1 branch
BranchTrueFalseTotal
if $self->is_data 1 2 3
543  
544 2 my %fk = ();
545  
546 2 foreach my $field ($self->get_fields) {
547 5 ▶ next unless $field->is_foreign_key;
Branch: 1 branch
BranchTrueFalseTotal
unless $field->is_foreign_key 1 4 5
548 4 $fk{ $field->foreign_key_reference->reference_table }++;
549 }
550  
551 2 foreach my $referenced (keys %fk) {
552 3 ▶ if ($fk{$referenced} > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($fk{$referenced} > 1) 1 2 3
553 1 return 0;
554 }
555 }
556  
557 1 return 1;
558 }
559  
560 =head2 is_data
561  
562 Returns true if the table has some non-key fields.
563  
564 =cut
565  
566 76 has is_data => (is => 'lazy', init_arg => undef);
567  
568 76 around is_data => carp_ro('is_data');
569  
570 4 ▶sub _build_is_data {
Subroutine _build_is_data: called CC=4 SCAR=13.9
571 4 my $self = shift;
572  
573 4 foreach my $field ($self->get_fields) {
574 9 ▶ if (!$field->is_primary_key and !$field->is_foreign_key) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($field->is_primary_key or $field->is_foreign_key) 2 7 9
Condition100%3/3
$field->is_primary_key or $field->is_foreign_key
l!l&&r!l&&!r
522
MC/DC100%2/2
$field->is_primary_key or $field->is_foreign_key
$field->is_primary_key $field->is_foreign_key
Truth table100%3/3
A or B
A= $field->is_primary_keyB= $field->is_foreign_key
ABresult
1X1
011
000
575 2 return 1;
576 }
577 }
578  
579 2 return 0;
580 }
581  
582 =head2 can_link
583  
584 Determine whether the table can link two arg tables via many-to-many.
585  
586 my $ok = $table->can_link($table1,$table2);
587  
588 =cut
589  
590 76 has _can_link => (is => 'ro', init_arg => undef, default => quote_sub(q{ +{} }));
591  
592 3 ▶sub can_link {
Subroutine can_link: called CC=15 SCAR=30.7
Pod documented
593 3 my ($self, $table1, $table2) = @_;
594  
595 return $self->_can_link->{ $table1->name }{ $table2->name }
596 3 ▶ if defined $self->_can_link->{ $table1->name }{ $table2->name };
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->_can_link->{$table1->name}{$table2->name} 0 3 3
597  
598 3 ▶ if ($self->is_data == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->is_data == 1) 0 3 3
599 0 $self->_can_link->{ $table1->name }{ $table2->name } = [0];
600 0 $self->_can_link->{ $table2->name }{ $table1->name } = [0];
601 0 return $self->_can_link->{ $table1->name }{ $table2->name };
602 }
603  
604 3 my %fk = ();
605  
606 3 foreach my $field ($self->get_fields) {
607 7 ▶ if ($field->is_foreign_key) {
Branch: 1 branch
BranchTrueFalseTotal
if ($field->is_foreign_key) 6 1 7
608 6 push @{ $fk{ $field->foreign_key_reference->reference_table } }, $field->foreign_key_reference;
609 }
610 }
611  
612 3 ▶ if (!defined($fk{ $table1->name }) or !defined($fk{ $table2->name })) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $fk{$table1->name} and defined $fk{$table2->name}) 1 2 3
Condition66%2/3
defined $fk{$table1->name} and defined $fk{$table2->name}
!ll&&!rl&&r
012
MC/DC50%1/2
defined $fk{$table1->name} and defined $fk{$table2->name}
defined $fk{$table1->name} defined $fk{$table2->name}
Truth table66%2/3
A and B
A= defined $fk{$table1->name}B= defined $fk{$table2->name}
ABresult
0X0
100
111
613 1 $self->_can_link->{ $table1->name }{ $table2->name } = [0];
614 1 $self->_can_link->{ $table2->name }{ $table1->name } = [0];
615 1 return $self->_can_link->{ $table1->name }{ $table2->name };
616 }
617  
618 # trivial traversal, only one way to link the two tables
619 2 ▶ if ( scalar(@{ $fk{ $table1->name } } == 1)
Branch: 4 branches
BranchTrueFalseTotal
if (scalar(@{$fk{$table1->name};} == 1) and scalar(@{$fk{$table2->name};} == 1)) { } 1 1 2
elsif (scalar(@{$fk{$table1->name};} > 1) and scalar(@{$fk{$table2->name};} == 1)) { } 0 1 1
elsif (scalar(@{$fk{$table1->name};} == 1) and scalar(@{$fk{$table2->name};} > 1)) { } 0 1 1
elsif (scalar(@{$fk{$table1->name};} > 1) and scalar(@{$fk{$table2->name};} > 1)) { } 1 0 1
Condition100%2/2
scalar(@{$fk{$table1->name};} == 1) and scalar(@{$fk{$table2->name};} == 1)
!ll
11
MC/DC100%1/1
scalar(@{$fk{$table1->name};} == 1) and scalar(@{$fk{$table2->name};} == 1)
scalar(@{$fk{$table1->name};} == 1)
Truth table100%2/2
A
A= scalar(@{$fk{$table1->name};} == 1)
Aresult
00
11
620 1 and scalar(@{ $fk{ $table2->name } } == 1)) {
621 1 $self->_can_link->{ $table1->name }{ $table2->name } = [ 'one2one', $fk{ $table1->name }, $fk{ $table2->name } ];
622 1 $self->_can_link->{ $table1->name }{ $table2->name } = [ 'one2one', $fk{ $table2->name }, $fk{ $table1->name } ];
623  
624 # non-trivial traversal. one way to link table2,
625 # many ways to link table1
626 1 ▶ } elsif (scalar(@{ $fk{ $table1->name } } > 1)
Condition50%1/2
scalar(@{$fk{$table1->name};} > 1) and scalar(@{$fk{$table2->name};} == 1)
!ll
01
MC/DC0%0/1
scalar(@{$fk{$table1->name};} > 1) and scalar(@{$fk{$table2->name};} == 1)
scalar(@{$fk{$table1->name};} > 1)
Truth table50%1/2
A
A= scalar(@{$fk{$table1->name};} > 1)
Aresult
00
11
627 1 and scalar(@{ $fk{ $table2->name } } == 1)) {
628 0 $self->_can_link->{ $table1->name }{ $table2->name } = [ 'many2one', $fk{ $table1->name }, $fk{ $table2->name } ];
629 0 $self->_can_link->{ $table2->name }{ $table1->name } = [ 'one2many', $fk{ $table2->name }, $fk{ $table1->name } ];
630  
631 # non-trivial traversal. one way to link table1,
632 # many ways to link table2
633 1 ▶ } elsif (scalar(@{ $fk{ $table1->name } } == 1)
Condition50%1/2
scalar(@{$fk{$table1->name};} == 1) and scalar(@{$fk{$table2->name};} > 1)
!ll
10
MC/DC0%0/1
scalar(@{$fk{$table1->name};} == 1) and scalar(@{$fk{$table2->name};} > 1)
scalar(@{$fk{$table1->name};} == 1)
Truth table50%1/2
A
A= scalar(@{$fk{$table1->name};} == 1)
Aresult
00
11
634 0 and scalar(@{ $fk{ $table2->name } } > 1)) {
635 0 $self->_can_link->{ $table1->name }{ $table2->name } = [ 'one2many', $fk{ $table1->name }, $fk{ $table2->name } ];
636 0 $self->_can_link->{ $table2->name }{ $table1->name } = [ 'many2one', $fk{ $table2->name }, $fk{ $table1->name } ];
637  
638 # non-trivial traversal. many ways to link table1 and table2
639 1 ▶ } elsif (scalar(@{ $fk{ $table1->name } } > 1)
Condition50%1/2
scalar(@{$fk{$table1->name};} > 1) and scalar(@{$fk{$table2->name};} > 1)
!ll
01
MC/DC0%0/1
scalar(@{$fk{$table1->name};} > 1) and scalar(@{$fk{$table2->name};} > 1)
scalar(@{$fk{$table1->name};} > 1)
Truth table50%1/2
A
A= scalar(@{$fk{$table1->name};} > 1)
Aresult
00
11
640 1 and scalar(@{ $fk{ $table2->name } } > 1)) {
641 1 $self->_can_link->{ $table1->name }{ $table2->name } = [ 'many2many', $fk{ $table1->name }, $fk{ $table2->name } ];
642 1 $self->_can_link->{ $table2->name }{ $table1->name } = [ 'many2many', $fk{ $table2->name }, $fk{ $table1->name } ];
643  
644 # one of the tables didn't export a key
645 # to this table, no linking possible
646 } else {
647 0 $self->_can_link->{ $table1->name }{ $table2->name } = [0];
648 0 $self->_can_link->{ $table2->name }{ $table1->name } = [0];
649 }
650  
651 2 return $self->_can_link->{ $table1->name }{ $table2->name };
652 }
653  
654 =head2 name
655  
656 Get or set the table's name.
657  
658 Errors ("No table name") if you try to set a blank name.
659  
660 If provided an argument, checks the schema object for a table of
661 that name and disallows the change if one exists (setting the error to
662 "Can't use table name "%s": table exists").
663  
664 my $table_name = $table->name('foo');
665  
666 =cut
667  
668 has name => (
669 is => 'rw',
670 369 ▶ isa => sub { throw("No table name") unless $_[0] },
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
unless $_[0] 2 367 369
671 76 );
672  
673 6628 ▶around name => sub {
Subroutine __ANON__: called CC=4 SCAR=13.9
674 6628 my $orig = shift;
675 6628 my $self = shift;
676  
677 6628 ▶ if (my ($arg) = @_) {
Branch: 1 branch
BranchTrueFalseTotal
if (my($arg) = ) 5 6623 6628
678 5 ▶ if (my $schema = $self->schema) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $schema = $self->schema) 4 1 5
679 4 ▶ return $self->error(qq[Can't use table name "$arg": table exists])
Branch: 1 branch
BranchTrueFalseTotal
if $schema->get_table($arg) 1 3 4
680 if $schema->get_table($arg);
681 }
682 }
683  
684 6627 return ex2err($orig, $self, @_);
685 76 };
686  
687 =head2 schema
688  
689 Get or set the table's schema object.
690  
691 my $schema = $table->schema;
692  
693 =cut
694  
695 76 has schema => (is => 'rw', isa => schema_obj('Schema'), weak_ref => 1);
696  
697 76 around schema => \&ex2err;
698  
699 1662 ▶sub primary_key {
Subroutine primary_key: called CC=11 SCAR=24.0
Pod documented
700  
701 =pod
702  
703 =head2 primary_key
704  
705 Gets or sets the table's primary key(s). Takes one or more field
706 names (as a string, list or array[ref]) as an argument. If the field
707 names are present, it will create a new PK if none exists, or it will
708 add to the fields of an existing PK (and will unique the field names).
709 Returns the C<SQL::Translator::Schema::Constraint> object representing
710 the primary key.
711  
712 These are equivalent:
713  
714 $table->primary_key('id');
715 $table->primary_key(['name']);
716 $table->primary_key('id','name']);
717 $table->primary_key(['id','name']);
718 $table->primary_key('id,name');
719 $table->primary_key(qw[ id name ]);
720  
721 my $pk = $table->primary_key;
722  
723 =cut
724  
725 1662 my $self = shift;
726 1662 my $fields = parse_list_arg(@_);
727  
728 1662 my $constraint;
729 1662 ▶ if (@$fields) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$fields) 211 1451 1662
730 211 for my $f (@$fields) {
731 220 ▶ return $self->error(qq[Invalid field "$f"])
Branch: 1 branch
BranchTrueFalseTotal
unless $self->get_field($f) 6 214 220
732 unless $self->get_field($f);
733 }
734  
735 205 my $has_pk;
736 205 for my $c ($self->get_constraints) {
737 98 ▶ if ($c->type eq PRIMARY_KEY) {
Branch: 1 branch
BranchTrueFalseTotal
if ($c->type eq "PRIMARY KEY") 88 10 98
738 88 $has_pk = 1;
739 88 $c->fields(@{ $c->fields }, @$fields);
740 88 $constraint = $c;
741 }
742 }
743  
744 205 ▶ unless ($has_pk) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($has_pk) 117 88 205
745 117 ▶ $constraint = $self->add_constraint(
Branch: 1 branch
BranchTrueFalseTotal
$constraint = $self->add_constraint("type", "PRIMARY KEY", "fields", $fields) or return 117 0 117
746 type => PRIMARY_KEY,
747 fields => $fields,
748 ) or return;
749 }
750 }
751  
752 1656 ▶ if ($constraint) {
Branch: 1 branch
BranchTrueFalseTotal
if ($constraint) { } 205 1451 1656
753 205 return $constraint;
754 } else {
755 1451 for my $c ($self->get_constraints) {
756 1217 ▶ return $c if $c->type eq PRIMARY_KEY;
Branch: 1 branch
BranchTrueFalseTotal
if $c->type eq "PRIMARY KEY" 977 240 1217
757 }
758 }
759  
760 474 return;
761 }
762  
763 =head2 options
764  
765 Get or append to the table's options (e.g., table types for MySQL).
766 Returns an array or array reference.
767  
768 my @options = $table->options;
769  
770 =cut
771  
772 76 with ListAttr options => (append => 1);
773  
774 =head2 order
775  
776 Get or set the table's order.
777  
778 my $order = $table->order(3);
779  
780 =cut
781  
782 76 has order => (is => 'rw', default => quote_sub(q{ 0 }));
783  
784 1271 ▶around order => sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
785 1271 my ($orig, $self, $arg) = @_;
786  
787 1271 ▶ if (defined $arg && $arg =~ /^\d+$/) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $arg and $arg =~ /^\d+$/) 358 913 1271
Condition66%2/3
defined $arg and $arg =~ /^\d+$/
!ll&&!rl&&r
9130358
MC/DC50%1/2
defined $arg and $arg =~ /^\d+$/
defined $arg $arg =~ /^\d+$/
Truth table66%2/3
A and B
A= defined $argB= $arg =~ /^\d+$/
ABresult
0X0
100
111
788 358 return $self->$orig($arg);
789 }
790  
791 913 return $self->$orig;
792 76 };
793  
794 =head2 field_names
795  
796 Read-only method to return a list or array ref of the field names. Returns undef
797 or an empty list if the table has no fields set. Useful if you want to
798 avoid the overload magic of the Field objects returned by the get_fields method.
799  
800 my @names = $constraint->field_names;
801  
802 =cut
803  
804 3 ▶sub field_names {
Subroutine field_names: called CC=3 SCAR=12.3
Pod documented
805 3 my $self = shift;
806 3 my @fields = map { $_->name } $self->get_fields;
807  
808 3 ▶ if (@fields) {
Branch: 1 branch
BranchTrueFalseTotal
if (@fields) { } 3 0 3
809 3 ▶ return wantarray ? @fields : \@fields;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 3 0 3
810 } else {
811 0 $self->error('No fields');
812 0 return;
813 }
814 }
815  
816 0 ▶sub equals {
Subroutine equals: not called CC=24 SCAR=64.0
Pod documented
817  
818 =pod
819  
820 =head2 equals
821  
822 Determines if this table is the same as another
823  
824 my $isIdentical = $table1->equals( $table2 );
825  
826 =cut
827  
828 0 my $self = shift;
829 0 my $other = shift;
830 0 my $case_insensitive = shift;
831  
832 0 ▶ return 0 unless $self->SUPER::equals($other);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->SUPER::equals($other) 0 0 0
833 0 ▶ return 0
Branch: 2 branches
BranchTrueFalseTotal
unless $case_insensitive ? uc $self->name eq uc $other->name : $self->name eq $other->name 0 0 0
$case_insensitive ? : 0 0 0
834 unless $case_insensitive
835 ? uc($self->name) eq uc($other->name)
836 : $self->name eq $other->name;
837 0 ▶ return 0
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_compare_objects(scalar $self->options, scalar $other->options) 0 0 0
838 unless $self->_compare_objects(scalar $self->options, scalar $other->options);
839 0 ▶ return 0
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_compare_objects(scalar $self->extra, scalar $other->extra) 0 0 0
840 unless $self->_compare_objects(scalar $self->extra, scalar $other->extra);
841  
842 # Fields
843 # Go through our fields
844 0 my %checkedFields;
845 0 foreach my $field ($self->get_fields) {
846 0 my $otherField = $other->get_field($field->name, $case_insensitive);
847 0 ▶ return 0 unless $field->equals($otherField, $case_insensitive);
Branch: 1 branch
BranchTrueFalseTotal
unless $field->equals($otherField, $case_insensitive) 0 0 0
848 0 $checkedFields{ $field->name } = 1;
849 }
850  
851 # Go through the other table's fields
852 0 foreach my $otherField ($other->get_fields) {
853 0 ▶ next if $checkedFields{ $otherField->name };
Branch: 1 branch
BranchTrueFalseTotal
if $checkedFields{$otherField->name} 0 0 0
854 0 return 0;
855 }
856  
857 # Constraints
858 # Go through our constraints
859 0 my %checkedConstraints;
860 CONSTRAINT:
861 0 foreach my $constraint ($self->get_constraints) {
862 0 foreach my $otherConstraint ($other->get_constraints) {
863 0 ▶ if ($constraint->equals($otherConstraint, $case_insensitive)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($constraint->equals($otherConstraint, $case_insensitive)) 0 0 0
864 0 $checkedConstraints{$otherConstraint} = 1;
865 0 next CONSTRAINT;
866 }
867 }
868 0 return 0;
869 }
870  
871 # Go through the other table's constraints
872 CONSTRAINT2:
873 0 foreach my $otherConstraint ($other->get_constraints) {
874 0 ▶ next if $checkedFields{$otherConstraint};
Branch: 1 branch
BranchTrueFalseTotal
if $checkedFields{$otherConstraint} 0 0 0
875 0 foreach my $constraint ($self->get_constraints) {
876 0 ▶ if ($otherConstraint->equals($constraint, $case_insensitive)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($otherConstraint->equals($constraint, $case_insensitive)) 0 0 0
877 0 next CONSTRAINT2;
878 }
879 }
880 0 return 0;
881 }
882  
883 # Indices
884 # Go through our indices
885 0 my %checkedIndices;
886 INDEX:
887 0 foreach my $index ($self->get_indices) {
888 0 foreach my $otherIndex ($other->get_indices) {
889 0 ▶ if ($index->equals($otherIndex, $case_insensitive)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($index->equals($otherIndex, $case_insensitive)) 0 0 0
890 0 $checkedIndices{$otherIndex} = 1;
891 0 next INDEX;
892 }
893 }
894 0 return 0;
895 }
896  
897 # Go through the other table's indices
898 INDEX2:
899 0 foreach my $otherIndex ($other->get_indices) {
900 0 ▶ next if $checkedIndices{$otherIndex};
Branch: 1 branch
BranchTrueFalseTotal
if $checkedIndices{$otherIndex} 0 0 0
901 0 foreach my $index ($self->get_indices) {
902 0 ▶ if ($otherIndex->equals($index, $case_insensitive)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($otherIndex->equals($index, $case_insensitive)) 0 0 0
903 0 next INDEX2;
904 }
905 }
906 0 return 0;
907 }
908  
909 0 return 1;
910 }
911  
912 =head1 LOOKUP METHODS
913  
914 The following are a set of shortcut methods for getting commonly used lists of
915 fields and constraints. They all return lists or array refs of Field or
916 Constraint objects.
917  
918 =over 4
919  
920 =item pkey_fields
921  
922 The primary key fields.
923  
924 =item fkey_fields
925  
926 All foreign key fields.
927  
928 =item nonpkey_fields
929  
930 All the fields except the primary key.
931  
932 =item data_fields
933  
934 All non key fields.
935  
936 =item unique_fields
937  
938 All fields with unique constraints.
939  
940 =item unique_constraints
941  
942 All this tables unique constraints.
943  
944 =item fkey_constraints
945  
946 All this tables foreign key constraints. (See primary_key method to get the
947 primary key constraint)
948  
949 =back
950  
951 =cut
952  
953 3 ▶sub pkey_fields {
Subroutine pkey_fields: called CC=2 SCAR=7.0
Pod documented
954 3 my $me = shift;
955 3 my @fields = grep { $_->is_primary_key } $me->get_fields;
956 3 ▶ return wantarray ? @fields : \@fields;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 3 0 3
957 }
958  
959 1 ▶sub fkey_fields {
Subroutine fkey_fields: called CC=3 SCAR=11.1
Pod documented
960 1 my $me = shift;
961 1 my @fields;
962 1 push @fields, $_->fields foreach $me->fkey_constraints;
963 1 ▶ return wantarray ? @fields : \@fields;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 1 0 1
964 }
965  
966 1 ▶sub nonpkey_fields {
Subroutine nonpkey_fields: called CC=2 SCAR=7.0
Pod documented
967 1 my $me = shift;
968 1 my @fields = grep { !$_->is_primary_key } $me->get_fields;
969 1 ▶ return wantarray ? @fields : \@fields;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 1 0 1
970 }
971  
972 3 ▶sub data_fields {
Subroutine data_fields: called CC=3 SCAR=11.0
Pod documented
973 3 my $me = shift;
974 3 ▶ my @fields = grep { !$_->is_foreign_key and !$_->is_primary_key } $me->get_fields;
Condition100%3/3
$_->is_foreign_key || $_->is_primary_key
l!l&&r!l&&!r
239
MC/DC100%2/2
$_->is_foreign_key || $_->is_primary_key
$_->is_foreign_key $_->is_primary_key
Truth table100%3/3
A || B
A= $_->is_foreign_keyB= $_->is_primary_key
ABresult
1X1
011
000
975 3 ▶ return wantarray ? @fields : \@fields;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 3 0 3
976 }
977  
978 1 ▶sub unique_fields {
Subroutine unique_fields: called CC=3 SCAR=11.1
Pod documented
979 1 my $me = shift;
980 1 my @fields;
981 1 push @fields, $_->fields foreach $me->unique_constraints;
982 1 ▶ return wantarray ? @fields : \@fields;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 1 0 1
983 }
984  
985 2 ▶sub unique_constraints {
Subroutine unique_constraints: called CC=2 SCAR=7.0
Pod documented
986 2 my $me = shift;
987 2 my @cons = grep { $_->type eq UNIQUE } $me->get_constraints;
988 2 ▶ return wantarray ? @cons : \@cons;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 2 0 2
989 }
990  
991 2 ▶sub fkey_constraints {
Subroutine fkey_constraints: called CC=2 SCAR=7.0
Pod documented
992 2 my $me = shift;
993 2 my @cons = grep { $_->type eq FOREIGN_KEY } $me->get_constraints;
994 2 ▶ return wantarray ? @cons : \@cons;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 2 0 2
995 }
996  
997 # Must come after all 'has' declarations
998 76 around new => \&ex2err;
999  
1000 76 1;
1001  
1002 =pod
1003  
1004 =head1 AUTHORS
1005  
1006 Ken Youens-Clark E<lt>kclark@cpan.orgE<gt>,
1007 Allen Day E<lt>allenday@ucla.eduE<gt>.
1008  
1009 =cut
« blib/lib/SQL/Translator/Producer/POD.pm ↑ Summary blib/lib/SQL/Translator/Producer/Sybase.pm »