CGI-Builder-Auth

 view release on metacpan or  search on metacpan

lib/CGI/Builder/Auth/Group.pm  view on Meta::CPAN

   
   ; return if $self->_exists($group);

   ; $self->_group_admin->create($group) or warn "Creation Failed"
   ; return $self->load(id => $group)
   }
   
#---------------------------------------------------------------------
# Instance Methods
#---------------------------------------------------------------------
; sub _exists 
   { defined $_[1] 
      ? $_[0]->_group_admin->exists($_[1]) 
      : $_[0]->_group_admin->exists($_[0]->id) 
   }
; sub delete 
   { defined $_[1] 
      ? $_[0]->_group_admin->remove($_[1]) 
      : $_[0]->_group_admin->remove($_[0]->id) 
   }

# 
# FIXME add_member & remove_member appear to succeed when !exists user
# 
; sub add_member 
   { my ($self, @users) = @_
   ; my $group = $self->id || shift(@users);
   
   ; return if !$self->_exists($group)

   ; my $user_factory = CGI::Builder::Auth::User->new
   ; for my $user (@users) { 
      next unless $user_factory->_exists($user)
      ; $self->_group_admin->add($user, $group)
      }
   ; 1
   }
; sub remove_member 
   { my ($self, @users) = @_
   ; my $group = $self->id || shift(@users)
   
   ; return if !$self->_exists($group)
   
   ; for my $user (@users)
      { $self->_group_admin->delete($user, $group)
      }
   ; 1
   }
; sub member_list
   { my ($self, $group) = @_
   ; $group = $group || $self->id
   
   ; return if !$self->_exists($group)
   
   ; $self->_group_admin->list($group)
   }

; sub DESTROY
   { ref($_group_admin) 
           and !Scalar::Util::isweak($_group_admin) 
           and Scalar::Util::weaken($_group_admin)
   }
 

=head1 NAME

CGI::Builder::Auth::Group - Provide access to a group table and its rows

=head1 DESCRIPTION

This Class provides an API for manipulating a Group table. The implementation
stores the table in a text file, but developers are free to create their own
implementations of this API that wrap SQL databases or other resources.

Developers using the library probably will not need to manipulate the user
objects directly, since the L<context object|CGI::Builder::Auth::Context>
provides a wrapper around all the common functions. However, developers
creating their own user classes need to pay special attention to implementing
this API correctly.

This document describes the default implementation, and includes many notes
about mandatory and optional features for alternate implementations.

WARNING: This interface is experimental. Developers may create their own
implementations, but are advised to subscribe to the mailing list to be
notified of changes. Backward compatibility is a goal, but is not guaranteed
for future releases.


=head1 SPECIAL PROPERTIES

The group object C<overload>'s the string operator so that it prints the group name
in string context rather than the usual reference information. As a result, you
may use the group object in your code as if it were a (read-only) scalar
containing the group name.

This is required behavior for all implementations. See L<overload> for details.


=head1 CONSTRUCTORS


=head2 C<load(id =E<gt> $id)>

Class method, takes a hash where the key is 'id' (literal) and the value is the
group name you wish to load.

Return a group object with the group name of C<$id>. Return C<undef> if the group
does not exist in the database. 

Note that the group name is required to be unique in a given table.


=head2 C<add($name | \%attr)>

Add a group to the group table.

Class method, takes a scalar that is either the name of the group to add, or a
reference to a hash of group attributes. Attributes supported in this
implementation:



( run in 1.518 second using v1.01-cache-2.11-cpan-5a3173703d6 )