reuse code refs from ->can
[dbsrgits/DBIx-Class-Schema-RestrictWithObject.git] / lib / DBIx / Class / Schema / RestrictWithObject / RestrictComp / Source.pm
CommitLineData
d87edac9 1package DBIx::Class::Schema::RestrictWithObject::RestrictComp::Source;
772c89c1 2
3use strict;
4use warnings;
5
6=head1 DESCRIPTION
7
d87edac9 8For general usage please see L<DBIx::Class::Schema::RestrictWithObject>, the information
772c89c1 9provided here is not meant for general use and is subject to change. In the interest
10of transparency the functionality presented is documented, but all methods should be
11considered private and, as such, subject to incompatible changes and removal.
12
13=head1 PRIVATE METHODS
14
15=head2 resultset
16
17Intercept call to C<resultset> and return restricted resultset
18
19=cut
d87edac9 20
4b2a6da6 21#TODO:
22# - We should really be caching method name hits to avoid the can()
23# unless it really is necessary. This would be done at the restrictor
24# class level. {$source_name} => $restricting_method (undef if n/a)
25
772c89c1 26sub resultset {
27 my $self = shift;
28 my $rs = $self->next::method(@_);
4b2a6da6 29 my $obj = $self->schema->restricting_object;
30 return $rs unless $obj;
31
32 my $s = $self->source_name;
33 $s =~ s/::/_/g;
34 #if a prefix was set, try that first
35 if(my $pre = $self->schema->restricted_prefix) {
36 if(my $coderef = $obj->can("restrict_${pre}_${s}_resultset")) {
37 return $obj->$coderef($rs);
d87edac9 38 }
4b2a6da6 39 }
40 #should this be an elsif?!
41 if(my $coderef = $obj->can("restrict_${s}_resultset")) {
42 return $obj->$coderef($rs);
772c89c1 43 }
44 return $rs;
45}
46
471;
48
49=head1 SEE ALSO
50
d87edac9 51L<DBIx::Class::Schema::RestrictWithObject>,
772c89c1 52
53=cut