package Net::LDAP::posixGroup;

use warnings;
use strict;
use Net::LDAP::Entry;

=head1 NAME

Net::LDAP::posixGroup - Creates new Net::LDAP::Entry objects for a posixGroup entry.

=head1 VERSION

Version 0.0.2


our $VERSION = '0.0.2';


    use Net::LDAP::posixGroup;

    my $foo = Net::LDAP::posixGroup->new({baseDN=>'ou=group,dc=foo'});
    #creates a new entry with the minimum requirements
    my $entry = $foo->create({name=>'vvelox', gid=>'404'}, ['user1', 'user2']);


=head2 new


sub new {
	my %args;
		%args= %{$_[1]};

	#returns undef if the baseDN is not set
	if (!defined($args{baseDN})) {
		warn('Net-LDAP-postixGroup new:0: "baseDN" is not defined');
		return undef;

	my $self={error=>undef, set=>undef, baseDN=>$args{baseDN}};
	bless $self;

	#if it is defined it sets the topless setting to what ever it is
	if (defined($args{topless})) {
	}else {

	return $self;

=head2 create

Creates a new Net::LDAP::Entry object. The first value is a
hash. See the below for avialble values. The second is a array
with the group members.

=head3 name

The group name. This is required.

=head3 gid

The numeric GID of a group. This is required.

=head3 description

A optional LDAP desciption. This is optional.

=head3 primary

The accepted values are 'cn' and 'gidNumber'.


sub create{
	my $self=$_[0];
	my %args;
		%args= %{$_[1]};
	my @members;
	if (defined($_[2])) {

	#error if name is not defined
	if (!defined($args{name})) {
		warn('Net-LDAP-posixGroup create:1: name not defined');
		$self->{errorString}='name not defined';
 		return undef;

	#error if name is not defined
	if (!defined($args{name})) {
		warn('Net-LDAP-posixGroup create:2: gid not defined');
		$self->{errorString}='gid not defined';
 		return undef;

	#sets the primary if it is not defined
	if (!defined($args{primary})) {

	#verifies the primary
	my @primary=('gid', 'cn');
	my $dn=undef;
	my $primaryInt=0;
	while (defined($primary[$primaryInt])) {
		#when a match is found, use it to begin forming the the DN
		if ($args{primary} eq $primary[$primaryInt]) {

	#error if none is matched
	if (!defined($dn)) {
		warn('Net-LDAP-posixGroup create:3: primary is a invalid value');
		$self->{errorString}='primary is a invalid value';
		return undef;
	#forms the DN if it is using the gidNumber
	if ($args{primary} eq 'gidNumber') {

	#forms the DN if it is using the CN
	if ($args{primary} eq 'cn') {

	#full forms the DN

	#creates a new object
	my $entry = Net::LDAP::Entry->new;

	#sets the dn

	#adds the various attributes
	$entry->add(objectClass=>['posixGroup', 'top'],
				gidNumber=>[$args{gid}], cn=>[$args{name}]);

	#adds the description if needed
	if (defined($args{description})) {

	my $membersInt=0;
	while (defined($members[$membersInt])) {


	return $entry;


=head2 errorBlank

A internal function user for clearing an error.


#blanks the error flags
sub errorBlank{
	my $self=$_[0];

	#error handling

	return 1;

=head1 Error Codes

=head2 0

Missing baseDN.

=head2 1

No group name specified.

=head2 2

No GID specified.

=head2 3

The primary is a invalid value.

=head1 AUTHOR

Zane C. Bowers, C<< <vvelox at> >>

=head1 BUGS

Please report any bugs or feature requests to C<bug-net-ldap-posixgroup at>, or through
the web interface at L<>.  I will be notified, and then you'll
automatically be notified of progress on your bug as I make changes.

=head1 SUPPORT

You can find documentation for this module with the perldoc command.

    perldoc Net::LDAP::posixGroup

You can also look for information at:

=over 4

=item * RT: CPAN's request tracker


=item * AnnoCPAN: Annotated CPAN documentation


=item * CPAN Ratings


=item * Search CPAN





Copyright 2008 Zane C. Bowers, all rights reserved.

This program is free software; you can redistribute it and/or modify it
under the same terms as Perl itself.


1; # End of Net::LDAP::posixGroup