| 1 | package DBIO::Test::DynamicForeignCols::TestComputer; | ||||||||||
| 2 | # ABSTRACT: Test result class for dynamic foreign column joining | ||||||||||
| 3 | |||||||||||
| 4 | 3 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | |||||||||||
| 6 | 3 | our $VERSION = '0.900007'; | |||||||||
| 7 | |||||||||||
| 8 | 3 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | |||||||||||
| 10 | 3 | ▶ | use base 'DBIO::Core'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | |||||||||||
| 12 | 3 | __PACKAGE__->table('TestComputer'); | |||||||||
| 13 | 3 | __PACKAGE__->add_columns(qw( test_id )); | |||||||||
| 14 | 3 | __PACKAGE__->_add_join_column({ class => 'DBIO::Test::DynamicForeignCols::Computer', method => 'computer' }); | |||||||||
| 15 | 3 | __PACKAGE__->set_primary_key('test_id', 'computer_id'); | |||||||||
| 16 | 3 | __PACKAGE__->belongs_to(computer => 'DBIO::Test::DynamicForeignCols::Computer', 'computer_id'); | |||||||||
| 17 | |||||||||||
| 18 | ### | ||||||||||
| 19 | ### This is a pathological case lifted from production. Yes, there is code | ||||||||||
| 20 | ### like this in the wild | ||||||||||
| 21 | ### | ||||||||||
| 22 | 3 | ▶ | sub _add_join_column { | ||||||||
|
Subroutine
_add_join_column: called CC=3 SCAR=12.6
| |||||||||||
| 23 | 3 | my ($self, $params) = @_; | |||||||||
| 24 | |||||||||||
| 25 | 3 | my $class = $params->{class}; | |||||||||
| 26 | 3 | my $method = $params->{method}; | |||||||||
| 27 | |||||||||||
| 28 | 3 | $self->ensure_class_loaded($class); | |||||||||
| 29 | |||||||||||
| 30 | 3 | my @class_columns = $class->primary_columns; | |||||||||
| 31 | |||||||||||
| 32 | 3 | ▶ | if (@class_columns = 1) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 33 | 3 | $self->add_columns( "${method}_id" ); | |||||||||
| 34 | } else { | ||||||||||
| 35 | 0 | my $i = 0; | |||||||||
| 36 | 0 | for (@class_columns) { | |||||||||
| 37 | 0 | $i++; | |||||||||
| 38 | 0 | $self->add_columns( "${method}_${i}_id" ); | |||||||||
| 39 | } | ||||||||||
| 40 | } | ||||||||||
| 41 | } | ||||||||||
| 42 | |||||||||||
| 43 | 3 | 1; | |||||||||
| 44 | |||||||||||
| 45 | __END__ | ||||||||||