1 package DBIx::Class::ResultSet::ParameterizedJoinHack;
5 use DBIx::Class::ParameterizedJoinHack;
6 use base qw(DBIx::Class::ResultSet);
8 sub _parameterized_join_store {
9 $_[0]->result_source->result_class
10 ->$DBIx::Class::ParameterizedJoinHack::STORE
13 sub with_parameterized_join {
14 my ($self, $rel, $params) = @_;
15 die "Missing relation name in with_parameterized_join"
18 my $params_ref = ref($params);
19 $params_ref = 'non-reference-value'
21 die "Parameters value must be a hash ref, not ${params_ref}"
22 unless $params_ref eq 'HASH';
28 %{$self->{attrs}{join_parameters}||{}},
35 sub _localize_parameters {
36 my ($self, $final, $params, $store, $first, @rest) = @_;
37 return $final->() unless $first;
38 local $store->{$first}{params} = $params->{$first};
39 $self->_localize_parameters($final, $params, $store, @rest);
42 sub call_with_parameters {
43 my ($self, $method, @args) = @_;
44 my %params = %{$self->{attrs}{join_parameters}||{}};
45 my $store = $self->_parameterized_join_store;
46 return $self->_localize_parameters(
47 sub { $self->$method(@args) },
53 sub _resolved_attrs { my $self = shift; $self->call_with_parameters($self->next::can, @_) }
54 sub related_resultset { my $self = shift; $self->call_with_parameters($self->next::can, @_) }
60 DBIx::Class::ResultSet::ParameterizedJoinHack
64 package MySchema::ResultSet::Person;
65 use base qw(DBIx::Class::ResultSet);
67 __PACKAGE__->load_components(qw(ResultSet::ParameterizedJoinHack));
73 This is a ResultSet component allowing you to access the dynamically
74 parameterized relations declared with
75 L<DBIx::Class::ParameterizedJoinHack>.
77 Enable the component as usual with:
79 __PACKAGE__->load_components(qw( ResultSet::ParameterizedJoinHack ));
81 in your ResultSet class.
83 See L<DBIx::Class::ParameterizedJoinHack> for declaration documentation,
84 a general overview, and examples.
88 =head2 with_parameterized_join
90 my $joined_rs = $resultset->with_parameterized_join(
95 This method constructs a ResultSet joined with the given C<$relation_name>
96 by the passed C<$parameters>. The C<$relation_name> is the name as
97 declared on the Result, C<$parameters> is a hash reference with the keys
98 being the parameter names, and the values being the arguments to the join
103 Development of this module was sponsored by
107 =item * Ctrl O L<http://ctrlo.com>
113 Matt S. Trout <mst@shadowcat.co.uk>
121 Copyright (c) 2015 the DBIx::Class::ParameterizedJoinHack L</AUTHOR> and L</CONTRIBUTORS>
126 This library is free software and may be distributed under the same terms