Meta/HasMany/ViaFK.pm

filter: Statementstmt 95.5% 43 / 45 Branchbran 100% 2 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 88.8% 8 / 9 Podpod n/a totaltotal 94.6% 53 / 56 SCAR 11.0
CC
3
Cov
96%
_make_iterator_maker
3.0
__ANON__
2.0
BEGIN
1.0
CRAP 3.0
« Meta/Role/Relationship/HasMany.pm ↑ Summary Meta/Attribute/FromSelect.pm »
1 package Fey::Meta::HasMany::ViaFK;
2 {
3 10 $Fey::Meta::HasMany::ViaFK::VERSION = '0.46';
4 }
5  
6 10 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 10 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 10 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 10 ▶use Fey::ORM::Types qw( ArrayRef );
Subroutine BEGIN: called CC=1 SCAR=0.0
11 10 ▶use List::AllUtils qw( any );
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 10 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 10 ▶use MooseX::StrictConstructor;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 10 with 'Fey::Meta::Role::Relationship::HasMany',
17 'Fey::Meta::Role::Relationship::ViaFK';
18  
19 10 has 'order_by' => (
20 is => 'ro',
21 isa => ArrayRef,
22 );
23  
24 sub _make_iterator_maker {
25 7 ▶ my $self = shift;
Subroutine _make_iterator_maker: called CC=3 SCAR=11.0
26  
27 7 my $target_table = $self->foreign_table();
28  
29 7 my $select = $self->associated_class()->schema_class()->SQLFactoryClass()
30 ->new_select();
31 7 $select->select($target_table)->from($target_table);
32  
33 7 my @ph_names;
34  
35 7 my $ph = Fey::Placeholder->new();
36 7 for my $pair ( @{ $self->fk()->column_pairs() } ) {
37 5 my ( $from, $to ) = @{$pair};
38  
39 5 $select->where( $to, '=', $ph );
40  
41 5 push @ph_names, $from->name();
42 }
43  
44 5 ▶ $select->order_by( @{ $self->order_by() } )
Branch: 1 branch
BranchTrueFalseTotal
if $self->order_by 1 4 5
45 if $self->order_by();
46  
47 my $bind_params_sub = sub {
48 0 ▶ return map { $_[0]->$_() } @ph_names;
Subroutine __ANON__: not called CC=1 SCAR=6.9
49 5 };
50  
51 5 return $self->_make_subref_for_sql(
52 $select,
53 $bind_params_sub,
54 );
55 }
56  
57 10 __PACKAGE__->meta()->make_immutable();
58  
59 10 1;
60  
61 # ABSTRACT: A parent for has-one metaclasses based on a L<Fey::FK> object
62  
63 __END__
64  
65 =pod
66  
67 =head1 NAME
68  
69 Fey::Meta::HasMany::ViaFK - A parent for has-one metaclasses based on a L<Fey::FK> object
70  
71 =head1 VERSION
72  
73 version 0.46
74  
75 =head1 DESCRIPTION
76  
77 This class implements a has-one relationship for a class, based on a
78 provided (or deduced) L<Fey::FK> object.
79  
80 =head1 CONSTRUCTOR OPTIONS
81  
82 This class accepts the following constructor options:
83  
84 =over 4
85  
86 =item * fk
87  
88 If you don't provide this, the class looks for foreign keys between
89 C<< $self->table() >> and and C<< $self->foreign_table() >>. If it
90 finds exactly one, it uses that one.
91  
92 =item * order_by
93  
94 This will be appended to the SQL which is generated to select the
95 foreign rows. It should be an arrayref which can be passed to C<<
96 Fey::SQL::Select->order_by() >>.
97  
98 =item * allows_undef
99  
100 This defaults to true if any of the columns in the local table are
101 NULLable, otherwise it defaults to false.
102  
103 =back
104  
105 =head1 METHODS
106  
107 Besides the methods provided by L<Fey::Meta::Role::Relationship::HasMany> and
108 L<Fey::Meta::Role::Relationship::ViaFK>, this class also provides the
109 following methods:
110  
111 =head2 $ho->fk()
112  
113 Corresponds to the value passed to the constructor, or the calculated
114 default.
115  
116 =head2 $ho->order_by()
117  
118 Corresponds to the value passed to the constructor.
119  
120 =head1 AUTHOR
121  
122 Dave Rolsky <autarch@urth.org>
123  
124 =head1 COPYRIGHT AND LICENSE
125  
126 This software is copyright (c) 2011 by Dave Rolsky.
127  
128 This is free software; you can redistribute it and/or modify it under
129 the same terms as the Perl 5 programming language system itself.
130  
131 =cut
« Meta/Role/Relationship/HasMany.pm ↑ Summary Meta/Attribute/FromSelect.pm »