rename restrict by user
[dbsrgits/DBIx-Class-Schema-RestrictWithObject.git] / lib / DBIx / Class / Schema / RestrictByUser / RestrictComp / Source.pm
1 package DBIx::Class::Schema::RestrictByUser::RestrictComp::Source;
2
3 use strict;
4 use warnings;
5
6 =head1 DESCRIPTION
7
8 For general usage please see L<DBIx::Class::Schema::RestrictByUser>, 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 $user = $self->schema->user) {
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($pre){
31       my $meth_pre = "restrict_${pre}_${s}_resultset";
32       return $user->$meth_pre($rs) if $user->can($meth_pre);
33     }    
34     $rs = $user->$meth($rs) if $user->can($meth);
35   }
36   return $rs;
37 }
38
39 1;
40
41 =head1 SEE ALSO
42
43 L<DBIx::Class::Schema::RestrictByUser>,
44
45 =cut