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"
19 my $params_ref = ref($params);
20 $params_ref = 'non-reference-value'
22 die "Parameters value must be a hash ref, not ${params_ref}"
23 unless $params_ref eq 'HASH';
30 %{$self->{attrs}{join_parameters}||{}},
37 sub _localize_parameters {
38 my ($self, $final, $params, $store, $first, @rest) = @_;
39 return $final->() unless $first;
40 local $store->{$first}{params} = $params->{$first};
41 $self->_localize_parameters($final, $params, $store, @rest);
44 sub call_with_parameters {
45 my ($self, $method, @args) = @_;
46 my %params = %{$self->{attrs}{join_parameters}||{}};
47 my $store = $self->_parameterized_join_store;
48 return $self->_localize_parameters(
49 sub { $self->$method(@args) },
55 sub _resolved_attrs { my $self = shift; $self->call_with_parameters($self->next::can, @_) }
56 sub related_resultset { my $self = shift; $self->call_with_parameters($self->next::can, @_) }
62 DBIx::Class::ResultSet::ParameterizedJoinHack
66 package MySchema::ResultSet::Person;
67 use base qw(DBIx::Class::ResultSet);
69 __PACKAGE__->load_components(qw(ResultSet::ParameterizedJoinHack));
75 This is a ResultSet component allowing you to access the dynamically
76 parameterized relations declared with
77 L<DBIx::Class::ParameterizedJoinHack>.
79 Enable the component as usual with:
81 __PACKAGE__->load_components(qw( ResultSet::ParameterizedJoinHack ));
83 in your ResultSet class.
85 See L<DBIx::Class::ParameterizedJoinHack> for declaration documentation,
86 a general overview, and examples.
90 =head2 with_parameterized_join
92 my $joined_rs = $resultset->with_parameterized_join(
97 This method constructs a ResultSet joined with the given C<$relation_name>
98 by the passed C<$parameters>. The C<$relation_name> is the name as
99 declared on the Result, C<$parameters> is a hash reference with the keys
100 being the parameter names, and the values being the arguments to the join
105 Development of this module was sponsored by
109 =item * Ctrl O L<http://ctrlo.com>
115 Matt S. Trout <mst@shadowcat.co.uk>
123 Copyright (c) 2015 the DBIx::Class::ParameterizedJoinHack L</AUTHOR> and L</CONTRIBUTORS>
128 This library is free software and may be distributed under the same terms