distarification
[dbsrgits/DBIx-Class-ParameterizedJoinHack.git] / lib / DBIx / Class / ResultSet / ParameterizedJoinHack.pm
CommitLineData
638c1533 1package DBIx::Class::ResultSet::ParameterizedJoinHack;
2
3use strict;
4use warnings;
5use DBIx::Class::ParameterizedJoinHack;
6use base qw(DBIx::Class::ResultSet);
7
8sub _parameterized_join_store {
9 $_[0]->result_source->result_class
10 ->$DBIx::Class::ParameterizedJoinHack::STORE
11}
12
13sub 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
26sub 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
36sub _resolved_attrs { my $self = shift; $self->call_with_parameters($self->next::can, @_) }
37sub related_resultset { my $self = shift; $self->call_with_parameters($self->next::can, @_) }
38
391;
40
41=head1 NAME
42
43DBIx::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
56This is a ResultSet component allowing you to access the dynamically
57parameterized relations declared with
58L<DBIx::Class::ParameterizedJoinHack>.
59
60Enable the component as usual with:
61
62 __PACKAGE__->load_components(qw( ResultSet::ParameterizedJoinHack ));
63
64in your ResultSet class.
65
66See L<DBIx::Class::ParameterizedJoinHack> for declaration documentation,
67a 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
78This method constructs a ResultSet joined with the given C<$relation_name>
79by the passed C<$parameters>. The C<$relation_name> is the name as
80declared on the Result, C<$parameters> is a hash reference with the keys
81being the parameter names, and the values being the arguments to the join
82builder.
83
84=head1 SPONSORS
85
86Development 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
100None yet.
101
102=head1 COPYRIGHT
103
104Copyright (c) 2015 the DBIx::Class::ParameterizedJoinHack L</AUTHOR> and L</CONTRIBUTORS>
105as listed above.
106
107=head1 LICENSE
108
109This library is free software and may be distributed under the same terms
110as perl itself.
111
112=cut