The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Mango::Provider::Roles - Provider class for user role information

SYNOPSIS

    my $provider = Mango::Provider::Roles->new;
    my $role = $provider->get_by_id(23);

DESCRIPTION

Mango::Provider::Roles is the provider class responsible for creating, deleting, updating and searching user role information.

CONSTRUCTOR

new

Arguments: \%options

Creates a new role provider object. If options are passed to new, those are sent to setup.

    my $provider = Mango::Provider::Roles->new;

See "new" in Mango::Provider and "new" in Mango::Provider::DBIC for a list of other possible options.

METHODS

add_user

Arguments: $role, @users

Adds the specified users to the specified role. users can be user objects or user ids and role can be a role object or a role id.

    my $role = $provider->get_by_id(23);
    $provider->add_users($role, 23, $user);

add_users

Same as "add_user".

create

Arguments: \%data

Creates a new Mango::Role object using the supplied data.

    my $role = $provider->create({
        name => 'Editors',
        description => 'Can edit content'
    });
    
    print $role->name;

delete

Arguments: \%filter

Deletes roles from the provider matching the supplied filter.

    $provider->delete({
        name => 'Editors'
    });

get_by_id

Arguments: $id

Returns a Mango::Role object matching the specified id.

    my $role = $provider->get_by_id(23);

Returns undef if no matching role can be found.

remove_user

Arguments: $role, @users

Removes the specified users from the specified role. users can be user objects or user ids and role can be a role object or a role id.

    my $role = $provider->get_by_id(23);
    $provider->remove_users($role, 23, $user);

remove_users

Same as "remove_user".

Arguments: \%filter, \%options

Returns a list of Mango::Role objects in list context, or a Mango::Iterator in scalar context matching the specified filter.

    my @roles = $provider->search({
        name => 'A%'
    });
    
    my $iterator = $provider->search({
        name => 'A%'
    });

In addition to using the column names, the following special keys are available:

user

This can be a user id, or a user object for which roles are assigned to.

    my @roles = $provider->search({
        user => $user
    });
    
    my $roles = $provider->search({
        user => $user
    });

See "ATTRIBUTES" in DBIx::Class::Resultset for a list of other possible options.

update

Arguments: $role

Sets the 'updated' column to DateTime->now and saves any changes made to the role back to the underlying store.

    my $role = $provider->create(\%data);
    $role->description('My New Role');
    
    $provider->update($role);

SEE ALSO

Mango::Provider, Mango::Provider::DBIC, Mango::Role, DBIx::Class

AUTHOR

    Christopher H. Laco
    CPAN ID: CLACO
    claco@chrislaco.com
    http://today.icantfocus.com/blog/