Fix the inline-documentation: LiCoM::Person doesn't provide a `group' method.
[licom.git] / lib / LiCoM / Person.pm
index a5bf4e2..4ba1be4 100644 (file)
@@ -47,6 +47,24 @@ our %ExternalNames =
 
 return (1);
 
+sub new
+{
+       my $pkg = shift;
+       my $entry = shift;
+       my $obj = {};
+
+       $obj->{'dn'} = $entry->dn ();
+       $obj->{'ldap'} = $entry;
+
+       for (keys %ValidFields)
+       {
+               my $key = $_;
+               $obj->{$key} = $entry->get_value ($key, asref => $ValidFields{$key});
+       }
+
+       return (bless ($obj, $pkg));
+}
+
 =head1 STATIC FUNCTIONS
 
 =over 4
@@ -87,8 +105,9 @@ sub create
        my %hash = @_;
        my $entry = Net::LDAP::Entry->new ();
        my $dn;
+       my $ou;
 
-       $entry->add (objectClass => [qw(top organizationalUnit person organizationalPerson inetOrgPerson)]);
+       $entry->add (objectClass => [qw(person organizationalPerson inetOrgPerson)]);
 
        for (keys %hash)
        {
@@ -147,8 +166,9 @@ sub create
        }
 
        $dn = "cn=$sn $gn," . get_config ('base_dn');
+       ($ou) = get_config ('base_dn') =~ m/\bou\s*=\s*([^,]+)/i;
        
-       $entry->add (cn => "$sn $gn");
+       $entry->add (cn => "$sn $gn", ou => $ou);
        $entry->dn ($dn);
 
        $entry->changetype ('add');
@@ -411,8 +431,6 @@ sub name
 
 =item I<$obj>-E<gt>B<uri> ([I<@uri>])
 
-=item I<$obj>-E<gt>B<group> ([I<@groups>])
-
 Get or set the attribute. This is the same as calling S<I<$obj>-E<gt>B<set>
 (I<$field>, I<\@values>)> or S<I<$obj>-E<gt>B<get> (I<$field>)>.
 
@@ -472,7 +490,7 @@ sub set
        }
        if (!defined ($ValidFields{$field}))
        {
-               return (undef);
+               return;
        }
 
        if (defined ($value))
@@ -494,7 +512,10 @@ sub set
                $entry->update ($Ldap);
        }
 
-       $obj->{$field} = [] unless (defined ($obj->{$field}));
+       if (!defined ($obj->{$field}) and $ValidFields{$field})
+       {
+               $obj->{$field} = [];
+       }
        
        if (wantarray () and $ValidFields{$field})
        {