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';
26 die "Parameterized join can only be used once per relation"
27 if exists(($self->{attrs}{join_parameters} || {})->{$rel});
33 %{$self->{attrs}{join_parameters}||{}},
40 sub _localize_parameters {
41 my ($self, $final, $params, $store, $first, @rest) = @_;
42 return $final->() unless $first;
43 local $store->{$first}{params} = $params->{$first};
44 $self->_localize_parameters($final, $params, $store, @rest);
47 sub call_with_parameters {
48 my ($self, $method, @args) = @_;
49 my %params = %{$self->{attrs}{join_parameters}||{}};
50 my $store = $self->_parameterized_join_store;
51 return $self->_localize_parameters(
52 sub { $self->$method(@args) },
58 sub _resolved_attrs { my $self = shift; $self->call_with_parameters($self->next::can, @_) }
59 sub related_resultset { my $self = shift; $self->call_with_parameters($self->next::can, @_) }
65 DBIx::Class::ResultSet::ParameterizedJoinHack
69 package MySchema::ResultSet::Person;
70 use base qw(DBIx::Class::ResultSet);
72 __PACKAGE__->load_components(qw(ResultSet::ParameterizedJoinHack));
78 This is a ResultSet component allowing you to access the dynamically
79 parameterized relations declared with
80 L<DBIx::Class::ParameterizedJoinHack>.
82 Enable the component as usual with:
84 __PACKAGE__->load_components(qw( ResultSet::ParameterizedJoinHack ));
86 in your ResultSet class.
88 See L<DBIx::Class::ParameterizedJoinHack> for declaration documentation,
89 a general overview, and examples.
93 =head2 with_parameterized_join
95 my $joined_rs = $resultset->with_parameterized_join(
100 This method constructs a ResultSet joined with the given C<$relation_name>
101 by the passed C<$parameters>. The C<$relation_name> is the name as
102 declared on the Result, C<$parameters> is a hash reference with the keys
103 being the parameter names, and the values being the arguments to the join
108 Development of this module was sponsored by
112 =item * Ctrl O L<http://ctrlo.com>
118 Matt S. Trout <mst@shadowcat.co.uk>
126 Copyright (c) 2015 the DBIx::Class::ParameterizedJoinHack L</AUTHOR> and L</CONTRIBUTORS>
131 This library is free software and may be distributed under the same terms