| 1 | # This class exists to represent a relationship between two ::Source's within | ||||||||||
| 2 | # the Sims. It will have a link back to two ::Source's. | ||||||||||
| 3 | |||||||||||
| 4 | package DBIx::Class::Sims::Relationship; | ||||||||||
| 5 | |||||||||||
| 6 | 54 | ▶ | use 5.010_001; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | |||||||||||
| 8 | 54 | ▶ | use strictures 2; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | |||||||||||
| 10 | 54 | ▶ | use DDP; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | |||||||||||
| 12 | 54 | ▶ | use DBIx::Class::Sims::Util qw( reftype ); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 13 | |||||||||||
| 14 | # Requires the following attributes: | ||||||||||
| 15 | # * source | ||||||||||
| 16 | # * name | ||||||||||
| 17 | # * info | ||||||||||
| 18 | # * constraints | ||||||||||
| 19 | 303 | ▶ | sub new { | ||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 20 | 303 | my $class = shift; | |||||||||
| 21 | 303 | my $self = bless {@_}, $class; | |||||||||
| 22 | 303 | $self->initialize; | |||||||||
| 23 | 303 | return $self; | |||||||||
| 24 | } | ||||||||||
| 25 | |||||||||||
| 26 | # Possible TODO: | ||||||||||
| 27 | # 1. Identify source / target and parent / child | ||||||||||
| 28 | |||||||||||
| 29 | 303 | ▶ | sub initialize { | ||||||||
|
Subroutine
initialize: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 30 | 303 | my $self = shift; | |||||||||
| 31 | |||||||||||
| 32 | 303 | return; | |||||||||
| 33 | } | ||||||||||
| 34 | |||||||||||
| 35 | 1339 | ▶ | sub name { shift->{name} } | ||||||||
|
Subroutine
name: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 36 | 171 | ▶ | sub source { shift->{source} } | ||||||||
|
Subroutine
source: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 37 | |||||||||||
| 38 | 224 | ▶ | sub constraints { shift->{constraints} } | ||||||||
|
Subroutine
constraints: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 39 | |||||||||||
| 40 | 0 | ▶ | sub full_name { | ||||||||
|
Subroutine
full_name: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 41 | 0 | my $self = shift; | |||||||||
| 42 | 0 | return $self->source->name . '->' . $self->name; | |||||||||
| 43 | } | ||||||||||
| 44 | |||||||||||
| 45 | # Yes, this method breaks ::Runner's encapsulation, but this (should) be | ||||||||||
| 46 | # temporary until someone else sets this for ::Relationship or maybe ::Source | ||||||||||
| 47 | # builds its relationships after ::Runner has built all ::Source objects first. | ||||||||||
| 48 | 171 | ▶ | sub target { | ||||||||
|
Subroutine
target: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 49 | 171 | my $self = shift; | |||||||||
| 50 | 171 | return $self->source->runner->{sources}{$self->short_fk_source}; | |||||||||
| 51 | } | ||||||||||
| 52 | |||||||||||
| 53 | 1744 | ▶ | sub is_fk { | ||||||||
|
Subroutine
is_fk: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 54 | 1744 | my $self = shift; | |||||||||
| 55 | 1744 | return exists $self->{info}{attrs}{is_foreign_key_constraint}; | |||||||||
| 56 | } | ||||||||||
| 57 | 239 | ▶ | sub short_fk_source { | ||||||||
|
Subroutine
short_fk_source: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 58 | 239 | my $self = shift; | |||||||||
| 59 | 239 | (my $x = $self->{info}{source}) =~ s/.*:://; | |||||||||
| 60 | 239 | return $x; | |||||||||
| 61 | } | ||||||||||
| 62 | |||||||||||
| 63 | 62 | ▶ | sub is_multi_col { | ||||||||
|
Subroutine
is_multi_col: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 64 | 62 | my $self = shift; | |||||||||
| 65 | 62 | keys %{$self->cond(@_)} > 1; | |||||||||
| 66 | } | ||||||||||
| 67 | |||||||||||
| 68 | 1148 | ▶ | sub cond { | ||||||||
|
Subroutine
cond: called CC=3 SCAR=11.2
Pod
undocumented
| |||||||||||
| 69 | 1148 | my $self = shift; | |||||||||
| 70 | 1148 | my $x = $self->{info}{cond}; | |||||||||
| 71 | 1148 | ▶ | if (reftype($x) eq 'CODE') { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 72 | 7 | $x = $x->({ | |||||||||
| 73 | foreign_alias => 'foreign', | ||||||||||
| 74 | self_alias => 'self', | ||||||||||
| 75 | }); | ||||||||||
| 76 | } | ||||||||||
| 77 | 1148 | ▶ | if (reftype($x) ne 'HASH') { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 78 | 0 | die "cond is not a HASH\n" . np($self->{info}); | |||||||||
| 79 | } | ||||||||||
| 80 | 1148 | return $x; | |||||||||
| 81 | } | ||||||||||
| 82 | |||||||||||
| 83 | 794 | ▶ | sub self_fk_cols { | ||||||||
|
Subroutine
self_fk_cols: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 84 | 794 | my $self = shift; | |||||||||
| 85 | 794 | return map {/^self\.(.*)/; $1} values %{$self->cond(@_)}; | |||||||||
| 86 | } | ||||||||||
| 87 | 481 | ▶ | sub self_fk_col { | ||||||||
|
Subroutine
self_fk_col: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 88 | 481 | my $self = shift; | |||||||||
| 89 | 481 | return ($self->self_fk_cols(@_))[0]; | |||||||||
| 90 | } | ||||||||||
| 91 | 292 | ▶ | sub foreign_fk_cols { | ||||||||
|
Subroutine
foreign_fk_cols: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 92 | 292 | my $self = shift; | |||||||||
| 93 | 292 | return map {/^foreign\.(.*)/; $1} keys %{$self->cond(@_)}; | |||||||||
| 94 | } | ||||||||||
| 95 | 292 | ▶ | sub foreign_fk_col { | ||||||||
|
Subroutine
foreign_fk_col: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 96 | 292 | my $self = shift; | |||||||||
| 97 | 292 | return ($self->foreign_fk_cols(@_))[0]; | |||||||||
| 98 | } | ||||||||||
| 99 | |||||||||||
| 100 | 50 | ▶ | sub foreign_class { | ||||||||
|
Subroutine
foreign_class: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 101 | 50 | my $self = shift; | |||||||||
| 102 | 50 | return $self->{info}{class}; | |||||||||
| 103 | } | ||||||||||
| 104 | |||||||||||
| 105 | 19 | ▶ | sub is_single_accessor { | ||||||||
|
Subroutine
is_single_accessor: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 106 | 19 | my $self = shift; | |||||||||
| 107 | 19 | return $self->{info}{attrs}{accessor} eq 'single'; | |||||||||
| 108 | } | ||||||||||
| 109 | 0 | ▶ | sub is_multi_accessor { | ||||||||
|
Subroutine
is_multi_accessor: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 110 | 0 | return ! $_[0]->is_single_accessor; | |||||||||
| 111 | } | ||||||||||
| 112 | |||||||||||
| 113 | 54 | 1; | |||||||||
| 114 | __END__ | ||||||||||