Name Change
[dbsrgits/DBIx-Class-Schema-RestrictWithObject.git] / lib / DBIx / Class / Schema / RestrictWithObject / RestrictComp / Source.pm
1 package DBIx::Class::Schema::RestrictWithObject::RestrictComp::Source;
2
3 use strict;
4 use warnings;
5
6 =head1 DESCRIPTION
7
8 For general usage please see L<DBIx::Class::Schema::RestrictWithObject>, the information
9 provided here is not meant for general use and is subject to change. In the interest
10 of transparency the functionality presented is documented, but all methods should be
11 considered private and, as such, subject to incompatible changes and removal.
12
13 =head1 PRIVATE METHODS
14
15 =head2 resultset
16
17 Intercept call to C<resultset> and return restricted resultset
18
19 =cut
20
21 sub resultset {
22   my $self = shift;
23   my $rs = $self->next::method(@_);
24   if (my $obj = $self->schema->restricting_object) {
25     my $s = $self->source_name;
26     $s =~ s/::/_/g;
27     my $pre = $self->schema->restricted_prefix;
28     my $meth = "restrict_${s}_resultset";
29
30     #if a prefix was set, try that first
31     if($pre){
32       my $meth_pre = "restrict_${pre}_${s}_resultset";
33       return $obj->$meth_pre($rs) if $obj->can($meth_pre);
34     }
35     $rs = $obj->$meth($rs) if $obj->can($meth);
36   }
37   return $rs;
38 }
39
40 1;
41
42 =head1 SEE ALSO
43
44 L<DBIx::Class::Schema::RestrictWithObject>,
45
46 =cut