test list creation tool
[scpubgit/App-EzPz.git] / lib / App / EzPz / User.pm
CommitLineData
5b26866e 1package App::EzPz::User;
2
396f4b0b 3use Module::Runtime qw(use_module);
5b26866e 4use Moo;
5
6has _htpasswd_user => (
7 is => 'ro', init_arg => 'htpasswd_user', required => 1,
8 handles => [ qw(username password check_password) ],
9);
10
396f4b0b 11has ezmlm_bindir => (is => 'rwp');
12
5b26866e 13around BUILDARGS => sub {
14 my ($orig, $self) = (shift, shift);
15 my $args = $self->$orig(@_);
16 $args->{htpasswd_user} ||=
396f4b0b 17 use_module('Authen::Htpasswd::User')->new(
5b26866e 18 delete @{$args}{qw(username password)}
19 );
20 return $args
21};
22
396f4b0b 23sub list_names {
24 my ($self) = @_;
25 if (my $unsplit = ($self->_htpasswd_user->extra_info||[])->[0]) {
26 return split /\s*,\s*/, $unsplit;
27 } else {
28 return ();
29 }
30}
31
32sub set_list_names {
33 my ($self, @names) = @_;
34 my @extra = @{$self->_htpasswd_user->extra_info||[]};
35 $extra[0] = join(', ', @names);
36 $self->_htpasswd_user->extra_info(@extra);
37 return;
38}
39
40sub add_list_name {
41 my ($self, $name) = @_;
42 my %names; @names{my @names = $self->list_names} = ();
43 $self->set_list_names(@names, $name) unless exists $names{$name};
44 return $name;
45}
46
47sub remove_list_name {
48 my ($self, $name) = @_;
49 my %names; @names{my @names = $self->list_names} = ();
50 if (exists $names{$name}) {
51 $self->set_list_names(grep !($_ eq $name), $self->list_names)
52 }
53 return $name;
54}
55
5b26866e 561;