File Coverage

blib/lib/App/LDAP/Command/Add/Group.pm
Criterion Covered Total %
statement 4 6 66.6
branch n/a
condition n/a
subroutine 2 2 100.0
pod n/a
total 6 8 75.0


line stmt bran cond sub pod time code
1             package App::LDAP::Command::Add::Group;
2              
3 1     1   5 use Modern::Perl;
  1         2  
  1         7  
4              
5 1     1   593 use Moose;
  0            
  0            
6              
7             with qw( App::LDAP::Role::Command
8             App::LDAP::Role::Bindable );
9              
10             has base => (
11             is => "rw",
12             isa => "Str",
13             );
14              
15             has member => (
16             is => "rw",
17             isa => "ArrayRef[Str]",
18             );
19              
20             use App::LDAP::LDIF::Group;
21              
22             # {{{
23             sub run {
24             my ($self) = shift;
25              
26             my $gid = next_gid();
27              
28             my $groupname = $self->extra_argv->[2] or die "no group name specified";
29              
30             die "group $groupname already exists" if App::LDAP::LDIF::Group->search(
31             base => config()->{nss_base_group}->[0],
32             scope => config()->{nss_base_group}->[1],
33             filter => "cn=$groupname",
34             );
35              
36             my $group = App::LDAP::LDIF::Group->new(
37             base => $self->base // config()->{nss_base_group}->[0],
38             cn => [$groupname],
39             gidNumber => $gid->get_value("gidNumber"),
40             );
41              
42             $group->memberUid( $self->member ) if $self->member;
43              
44             $group->save;
45              
46             $gid->replace(gidNumber => $gid->get_value("gidNumber")+1)->update(ldap());
47              
48             $group;
49             }
50             # }}}
51              
52             sub next_gid {
53             ldap()->search(
54             base => config()->{base},
55             filter => "(objectClass=gidnext)",
56             )->entry(0);
57             }
58              
59             __PACKAGE__->meta->make_immutable;
60             no Moose;
61              
62             1;