line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Fey::Meta::HasOne::ViaFK; |
2
|
|
|
|
|
|
|
|
3
|
10
|
|
|
10
|
|
58
|
use strict; |
|
10
|
|
|
|
|
19
|
|
|
10
|
|
|
|
|
375
|
|
4
|
10
|
|
|
10
|
|
57
|
use warnings; |
|
10
|
|
|
|
|
19
|
|
|
10
|
|
|
|
|
373
|
|
5
|
10
|
|
|
10
|
|
51
|
use namespace::autoclean; |
|
10
|
|
|
|
|
19
|
|
|
10
|
|
|
|
|
132
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = '0.47'; |
8
|
|
|
|
|
|
|
|
9
|
10
|
|
|
10
|
|
1068
|
use List::AllUtils qw( any ); |
|
10
|
|
|
|
|
18
|
|
|
10
|
|
|
|
|
739
|
|
10
|
|
|
|
|
|
|
|
11
|
10
|
|
|
10
|
|
65
|
use Moose; |
|
10
|
|
|
|
|
22
|
|
|
10
|
|
|
|
|
118
|
|
12
|
10
|
|
|
10
|
|
60661
|
use MooseX::StrictConstructor; |
|
10
|
|
|
|
|
21
|
|
|
10
|
|
|
|
|
101
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
with 'Fey::Meta::Role::Relationship::HasOne', |
15
|
|
|
|
|
|
|
'Fey::Meta::Role::Relationship::ViaFK'; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub _build_allows_undef { |
18
|
7
|
|
|
7
|
|
12
|
my $self = shift; |
19
|
|
|
|
|
|
|
|
20
|
7
|
|
|
5
|
|
33
|
return any { $_->is_nullable() } @{ $self->fk()->source_columns() }; |
|
5
|
|
|
|
|
171
|
|
|
7
|
|
|
|
|
219
|
|
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
## no critic (Subroutines::ProhibitUnusedPrivateSubroutines) |
24
|
|
|
|
|
|
|
sub _make_subref { |
25
|
7
|
|
|
7
|
|
14
|
my $self = shift; |
26
|
|
|
|
|
|
|
|
27
|
7
|
|
|
|
|
14
|
my %column_map; |
28
|
7
|
|
|
|
|
11
|
for my $pair ( @{ $self->fk()->column_pairs() } ) { |
|
7
|
|
|
|
|
188
|
|
29
|
7
|
|
|
|
|
467
|
my ( $from, $to ) = @{$pair}; |
|
7
|
|
|
|
|
18
|
|
30
|
|
|
|
|
|
|
|
31
|
7
|
|
|
|
|
173
|
$column_map{ $from->name() } = [ $to->name(), $to->is_nullable() ]; |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
7
|
|
|
|
|
538
|
my $target_table = $self->foreign_table(); |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
return sub { |
37
|
0
|
|
|
0
|
|
|
my $self = shift; |
38
|
|
|
|
|
|
|
|
39
|
0
|
|
|
|
|
|
my %new_p; |
40
|
|
|
|
|
|
|
|
41
|
0
|
|
|
|
|
|
for my $from ( keys %column_map ) { |
42
|
0
|
|
|
|
|
|
my $target_name = $column_map{$from}[0]; |
43
|
|
|
|
|
|
|
|
44
|
0
|
|
|
|
|
|
$new_p{$target_name} = $self->$from(); |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
return |
47
|
0
|
0
|
0
|
|
|
|
unless defined $new_p{$target_name} || $column_map{$from}[1]; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
0
|
|
|
|
|
|
return $self->meta()->ClassForTable($target_table)->new(%new_p); |
51
|
7
|
|
|
|
|
224
|
}; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
## use critic |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
__PACKAGE__->meta()->make_immutable(); |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
1; |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
# ABSTRACT: A parent for has-one metaclasses based on a L<Fey::FK> object |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
__END__ |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
=pod |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
=head1 NAME |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
Fey::Meta::HasOne::ViaFK - A parent for has-one metaclasses based on a L<Fey::FK> object |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
=head1 VERSION |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
version 0.47 |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
=head1 DESCRIPTION |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
This class implements a has-one relationship for a class, based on a |
76
|
|
|
|
|
|
|
provided (or deduced) L<Fey::FK> object. |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
=head1 CONSTRUCTOR OPTIONS |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
This class accepts the following constructor options: |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
=over 4 |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
=item * fk |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
If you don't provide this, the class looks for foreign keys between |
87
|
|
|
|
|
|
|
C<< $self->table() >> and and C<< $self->foreign_table() >>. If it |
88
|
|
|
|
|
|
|
finds exactly one, it uses that one. |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=item * allows_undef |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
This defaults to true if any of the columns in the local table are |
93
|
|
|
|
|
|
|
NULLable, otherwise it defaults to false. |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=back |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=head1 METHODS |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
Besides the methods provided by L<Fey::Meta::Role::Relationship::HasOne> and |
100
|
|
|
|
|
|
|
L<Fey::Meta::Role::Relationship::ViaFK>, this class also provides the |
101
|
|
|
|
|
|
|
following methods: |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=head2 $ho->fk() |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
Corresponds to the value passed to the constructor, or the calculated |
106
|
|
|
|
|
|
|
default. |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=head1 AUTHOR |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
Dave Rolsky <autarch@urth.org> |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
This software is copyright (c) 2011 - 2015 by Dave Rolsky. |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
117
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
=cut |