# In MyApp::Schema::Class =item B Takes a role object, an id, or a name. =cut sub has_role : method { my $self = shift; my $role = shift || return; if ( blessed $role ) { return first { $role->id == $_->id } $self->roles; } elsif ( $role =~ /\A\d+\z/ ) { return first { $role == $_->id } $self->roles; } else { return first { $role eq $_->name } $self->roles; } return; } #### # in MyApp::Schema::Role use overload '""' => sub { return +shift->name; }, fallback => 1; #### if ( $user->has_role("admin") ) { # authorized for admin stuff... } #### MyApp::Schema::Result::User MyApp::Schema::Result::Role MyApp::Schema::Result::UserRole