Commit | Line | Data |
638c1533 |
1 | package DBIx::Class::ResultSet::ParameterizedJoinHack; |
2 | |
3 | use strict; |
4 | use warnings; |
5 | use DBIx::Class::ParameterizedJoinHack; |
6 | use base qw(DBIx::Class::ResultSet); |
7 | |
8 | sub _parameterized_join_store { |
9 | $_[0]->result_source->result_class |
10 | ->$DBIx::Class::ParameterizedJoinHack::STORE |
11 | } |
12 | |
13 | sub with_parameterized_join { |
14 | my ($self, $rel, $params) = @_; |
15 | $self->search_rs( |
16 | {}, |
17 | { join => $rel, |
18 | join_parameters => { |
19 | %{$self->{attrs}{join_parameters}||{}}, |
20 | $rel => $params |
21 | } |
22 | }, |
23 | ); |
24 | } |
25 | |
26 | sub call_with_parameters { |
27 | my ($self, $method, @args) = @_; |
28 | my %params = %{$self->{attrs}{join_parameters}||{}}; |
29 | my $store = $self->_parameterized_join_store; |
30 | local @{$store}{keys %params} = map { |
31 | +{ %{$store->{$_}}, params => $params{$_} } |
32 | } keys %params; |
33 | return $self->$method(@args); |
34 | } |
35 | |
36 | sub _resolved_attrs { my $self = shift; $self->call_with_parameters($self->next::can, @_) } |
37 | sub related_resultset { my $self = shift; $self->call_with_parameters($self->next::can, @_) } |
38 | |
39 | 1; |
40 | |
41 | =head1 NAME |
42 | |
43 | DBIx::Class::ResultSet::ParameterizedJoinHack |
44 | |
45 | =head1 SYNOPSIS |
46 | |
47 | package MySchema::ResultSet::Person; |
48 | use base qw(DBIx::Class::ResultSet); |
49 | |
50 | __PACKAGE__->load_components(qw(ResultSet::ParameterizedJoinHack)); |
51 | |
52 | 1; |
53 | |
54 | =head1 DESCRIPTION |
55 | |
56 | This is a ResultSet component allowing you to access the dynamically |
57 | parameterized relations declared with |
58 | L<DBIx::Class::ParameterizedJoinHack>. |
59 | |
60 | Enable the component as usual with: |
61 | |
62 | __PACKAGE__->load_components(qw( ResultSet::ParameterizedJoinHack )); |
63 | |
64 | in your ResultSet class. |
65 | |
66 | See L<DBIx::Class::ParameterizedJoinHack> for declaration documentation, |
67 | a general overview, and examples. |
68 | |
69 | =head1 METHODS |
70 | |
71 | =head2 with_parameterized_join |
72 | |
73 | my $joined_rs = $resultset->with_parameterized_join( |
74 | $relation_name, |
75 | $parameters, |
76 | ); |
77 | |
78 | This method constructs a ResultSet joined with the given C<$relation_name> |
79 | by the passed C<$parameters>. The C<$relation_name> is the name as |
80 | declared on the Result, C<$parameters> is a hash reference with the keys |
81 | being the parameter names, and the values being the arguments to the join |
82 | builder. |
83 | |
84 | =head1 SPONSORS |
85 | |
86 | Development of this module was sponsored by |
87 | |
88 | =over |
89 | |
90 | =item * Ctrl O L<http://ctrlo.com> |
91 | |
92 | =back |
93 | |
94 | =head1 AUTHOR |
95 | |
96 | Matt S. Trout <mst@shadowcat.co.uk> |
97 | |
98 | =head1 CONTRIBUTORS |
99 | |
100 | None yet. |
101 | |
102 | =head1 COPYRIGHT |
103 | |
104 | Copyright (c) 2015 the DBIx::Class::ParameterizedJoinHack L</AUTHOR> and L</CONTRIBUTORS> |
105 | as listed above. |
106 | |
107 | =head1 LICENSE |
108 | |
109 | This library is free software and may be distributed under the same terms |
110 | as perl itself. |
111 | |
112 | =cut |