| 1 | package Class::DBI::Relationship::HasA; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 4 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 4 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 4 | ▶ | use base 'Class::DBI::Relationship'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 3 | ▶ | sub remap_arguments { | ||||||||||||||||||||||||||
|
Subroutine
remap_arguments: called CC=4 SCAR=14.6
Pod
documented
| |||||||||||||||||||||||||||||
| 9 | 3 | my ($proto, $class, $want_col, $a_class, %meths) = @_; | |||||||||||||||||||||||||||
| 10 | 3 | ▶ | $class->_invalid_object_method("has_a") if ref $class; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 11 | 3 | ▶ | my $column = $class->find_column($want_col) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 12 | or return $class->_croak("Column $want_col does not exist in $class"); | ||||||||||||||||||||||||||||
| 13 | 3 | ▶ | $class->_croak("$class $column needs an associated class") unless $a_class; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 14 | 3 | return ($class, $column, $a_class, \%meths); | |||||||||||||||||||||||||||
| 15 | } | ||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | 3 | ▶ | sub triggers { | ||||||||||||||||||||||||||
|
Subroutine
triggers: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 18 | 3 | my $self = shift; | |||||||||||||||||||||||||||
| 19 | 3 | $self->class->_require_class($self->foreign_class); | |||||||||||||||||||||||||||
| 20 | 3 | my $column = $self->accessor; | |||||||||||||||||||||||||||
| 21 | return ( | ||||||||||||||||||||||||||||
| 22 | 3 | select => $self->_inflator, | |||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | # after_create => $self->_inflator, # see t/6 | ||||||||||||||||||||||||||||
| 25 | "after_set_$column" => $self->_inflator, | ||||||||||||||||||||||||||||
| 26 | deflate_for_create => $self->_deflator(1), | ||||||||||||||||||||||||||||
| 27 | deflate_for_update => $self->_deflator, | ||||||||||||||||||||||||||||
| 28 | ); | ||||||||||||||||||||||||||||
| 29 | } | ||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | 6 | ▶ | sub _inflator { | ||||||||||||||||||||||||||
|
Subroutine
_inflator: called CC=1 SCAR=6.1
| |||||||||||||||||||||||||||||
| 32 | 6 | my $rel = shift; | |||||||||||||||||||||||||||
| 33 | 6 | my $col = $rel->accessor; | |||||||||||||||||||||||||||
| 34 | 0 | ▶ | return sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=13 SCAR=52.0
| |||||||||||||||||||||||||||||
| 35 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 36 | 0 | ▶ | defined(my $value = $self->_attrs($col)) or return; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 37 | 0 | my $meta = $self->meta_info($rel->name => $col); | |||||||||||||||||||||||||||
| 38 | 0 | my ($a_class, %meths) = ($meta->foreign_class, %{ $meta->args }); | |||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | 0 | ▶ | return if ref $value and $value->isa($a_class); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
ref $value and $value->isa($a_class)
MC/DC0%0/2
ref $value and $value->isa($a_class)
ref $value
$value->isa($a_class)
Truth table0%0/3
A and B
A= ref $valueB= $value->isa($a_class)
| |||||||||||||||||||||||||||||
| 41 | 0 | my $inflator; | |||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | 0 | ▶ | my $get_new_value = sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 44 | 0 | my ($inflator, $value, $want_class, $obj) = @_; | |||||||||||||||||||||||||||
| 45 | 0 | ▶ | my $new_value = | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 46 | (ref $inflator eq 'CODE') | ||||||||||||||||||||||||||||
| 47 | ? $inflator->($value, $obj) | ||||||||||||||||||||||||||||
| 48 | : $want_class->$inflator($value); | ||||||||||||||||||||||||||||
| 49 | 0 | return $new_value; | |||||||||||||||||||||||||||
| 50 | 0 | }; | |||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | # If we have a custom inflate ... | ||||||||||||||||||||||||||||
| 53 | 0 | ▶ | if (exists $meths{'inflate'}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 54 | 0 | $value = $get_new_value->($meths{'inflate'}, $value, $a_class, $self); | |||||||||||||||||||||||||||
| 55 | 0 | ▶ | return $self->_attribute_store($col, $value) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
ref $value and $value->isa($a_class)
MC/DC0%0/2
ref $value and $value->isa($a_class)
ref $value
$value->isa($a_class)
Truth table0%0/3
A and B
A= ref $valueB= $value->isa($a_class)
| |||||||||||||||||||||||||||||
| 56 | if ref $value | ||||||||||||||||||||||||||||
| 57 | and $value->isa($a_class); | ||||||||||||||||||||||||||||
| 58 | 0 | ▶ | $self->_croak("Inflate method didn't inflate right") if ref $value; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | 0 | ▶ | return $self->_croak("Can't inflate $col to $a_class using '$value': " | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 62 | . ref($value) | ||||||||||||||||||||||||||||
| 63 | . " is not a $a_class") | ||||||||||||||||||||||||||||
| 64 | if ref $value; | ||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | 0 | ▶ | $inflator = $a_class->isa('Class::DBI') ? "_simple_bless" : "new"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 67 | 0 | $value = $get_new_value->($inflator, $value, $a_class); | |||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | 0 | ▶ | return $self->_attribute_store($col, $value) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
ref $value and $value->isa($a_class)
MC/DC0%0/2
ref $value and $value->isa($a_class)
ref $value
$value->isa($a_class)
Truth table0%0/3
A and B
A= ref $valueB= $value->isa($a_class)
| |||||||||||||||||||||||||||||
| 70 | if ref $value | ||||||||||||||||||||||||||||
| 71 | and $value->isa($a_class); | ||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | # use ref as $obj may be overloaded and appear 'false' | ||||||||||||||||||||||||||||
| 74 | 0 | ▶ | return $self->_croak( | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 75 | "Can't inflate $col to $a_class " . "via $inflator using '$value'") | ||||||||||||||||||||||||||||
| 76 | unless ref $value; | ||||||||||||||||||||||||||||
| 77 | 6 | }; | |||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | 6 | ▶ | sub _deflator { | ||||||||||||||||||||||||||
|
Subroutine
_deflator: called CC=1 SCAR=3.8
| |||||||||||||||||||||||||||||
| 81 | 6 | my ($self, $always) = @_; | |||||||||||||||||||||||||||
| 82 | 6 | my $col = $self->accessor; | |||||||||||||||||||||||||||
| 83 | 0 | ▶ | return sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||
| 84 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 85 | 0 | ▶ | return unless $self->_attribute_exists($col); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 86 | $self->_attribute_store($col => $self->_deflated_column($col)) | ||||||||||||||||||||||||||||
| 87 | 0 | ▶ | if ($always or $self->{__Changed}->{$col}); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$always or $self->{"__Changed"}{$col}
MC/DC0%0/2
$always or $self->{"__Changed"}{$col}
$always
$self->{"__Changed"}{$col}
Truth table0%0/3
A or B
A= $alwaysB= $self->{"__Changed"}{$col}
| |||||||||||||||||||||||||||||
| 88 | 6 | }; | |||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | 3 | ▶ | sub _set_up_class_data { | ||||||||||||||||||||||||||
|
Subroutine
_set_up_class_data: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 92 | 3 | my $self = shift; | |||||||||||||||||||||||||||
| 93 | $self->class->_extend_class_data(__hasa_rels => $self->accessor => | ||||||||||||||||||||||||||||
| 94 | 3 | [ $self->foreign_class, %{ $self->args } ]); | |||||||||||||||||||||||||||
| 95 | 3 | $self->SUPER::_set_up_class_data; | |||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | 4 | 1; | |||||||||||||||||||||||||||