added role self_check and self_check_any to User store
[catagits/Catalyst-Authentication-Store-DBIx-Class.git] / lib / Catalyst / Authentication / Store / DBIx / Class / User.pm
index 18282a4..675e537 100644 (file)
@@ -116,10 +116,32 @@ sub supported_features {
 
     return {
         session         => 1,
-        roles           => 1,
+        roles           => {
+            self_check      => $self->config->{check_roles} || 0,,
+            self_check_any  => $self->config->{check_roles_any} || 0,
+        },
     };
 }
 
+#will only be used if $config->{check_roles} is set
+sub check_roles {
+    my ( $self, @wanted_roles ) = @_;
+
+    my @roles = $self->roles;
+    my $name = $self->config->{check_roles};
+
+    return $self->_user->$name( \@roles, \@wanted_roles );
+}
+
+#will only be used if $config->{check_roles_any} is set
+sub check_roles_any {
+    my ( $self, @wanted_roles ) = @_;
+
+    my @roles = $self->roles;
+    my $name = $self->config->{check_roles_any};
+
+    return $self->_user->$name( \@roles, \@wanted_roles );
+}
 
 sub roles {
     my ( $self ) = shift;
@@ -394,6 +416,20 @@ Delegates method calls to the underlying user row.
 
 Delegates handling of the C<< can >> method to the underlying user row.
 
+=head2 check_roles
+
+Calls the specified check_roles method on the underlying user row.
+
+Passes \@roles, \@wanted_roles, where @roles is the list of roles,
+and @wanted_roles is the list of wanted roles
+
+=head2 check_roles_any
+
+Calls the specified check_roles_any method on the underlying user row.
+
+Passes \@roles, \@wanted_roles, where @roles is the list of roles,
+and @wanted_roles is the list of wanted roles
+
 =head1 BUGS AND LIMITATIONS
 
 None known currently, please email the author if you find any.