From: Matt S Trout Date: Sun, 15 Jul 2012 16:13:53 +0000 (+0000) Subject: list name management X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=396f4b0bc4a7e5a42cf276de9ff38aaa63748a23;p=scpubgit%2FApp-EzPz.git list name management --- diff --git a/lib/App/EzPz/User.pm b/lib/App/EzPz/User.pm index e3d843b..a4da2f1 100644 --- a/lib/App/EzPz/User.pm +++ b/lib/App/EzPz/User.pm @@ -1,6 +1,6 @@ package App::EzPz::User; -use Authen::Htpasswd::User; +use Module::Runtime qw(use_module); use Moo; has _htpasswd_user => ( @@ -8,14 +8,49 @@ has _htpasswd_user => ( handles => [ qw(username password check_password) ], ); +has ezmlm_bindir => (is => 'rwp'); + around BUILDARGS => sub { my ($orig, $self) = (shift, shift); my $args = $self->$orig(@_); $args->{htpasswd_user} ||= - Authen::Htpasswd::User->new( + use_module('Authen::Htpasswd::User')->new( delete @{$args}{qw(username password)} ); return $args }; +sub list_names { + my ($self) = @_; + if (my $unsplit = ($self->_htpasswd_user->extra_info||[])->[0]) { + return split /\s*,\s*/, $unsplit; + } else { + return (); + } +} + +sub set_list_names { + my ($self, @names) = @_; + my @extra = @{$self->_htpasswd_user->extra_info||[]}; + $extra[0] = join(', ', @names); + $self->_htpasswd_user->extra_info(@extra); + return; +} + +sub add_list_name { + my ($self, $name) = @_; + my %names; @names{my @names = $self->list_names} = (); + $self->set_list_names(@names, $name) unless exists $names{$name}; + return $name; +} + +sub remove_list_name { + my ($self, $name) = @_; + my %names; @names{my @names = $self->list_names} = (); + if (exists $names{$name}) { + $self->set_list_names(grep !($_ eq $name), $self->list_names) + } + return $name; +} + 1; diff --git a/lib/App/EzPz/UserStore.pm b/lib/App/EzPz/UserStore.pm index 8b0a557..73669c5 100644 --- a/lib/App/EzPz/UserStore.pm +++ b/lib/App/EzPz/UserStore.pm @@ -1,8 +1,7 @@ package App::EzPz::UserStore; -use App::EzPz::User; +use Module::Runtime qw(use_module); use Scalar::Util 'blessed'; -use Authen::Htpasswd; use Moo; has ezmlm_bindir => (is => 'ro', required => 1); @@ -13,7 +12,7 @@ has _htpasswd => (is => 'lazy'); sub _build__htpasswd { my ($self) = @_; - return Authen::Htpasswd->new($self->htpasswd_file); + return use_module('Authen::Htpasswd')->new($self->htpasswd_file); } sub all { @@ -33,12 +32,13 @@ sub get { sub add { my ($self, $user) = @_; unless (blessed($user)) { - $user = App::EzPz::User->new($user); + $user = use_module('App::EzPz::User')->new($user); } my $htp_file = $self->_htpasswd; my $htp_user = $user->_htpasswd_user; $htp_file->add_user($htp_user); $htp_user->file($htp_file); + $user->_set_ezmlm_bindir($self->ezmlm_bindir); return $user; } @@ -50,8 +50,9 @@ sub remove { sub _inflate_user { my ($self, $htp_user) = @_; - return App::EzPz::User->new( + return use_module('App::EzPz::User')->new( htpasswd_user => $htp_user, + ezmlm_bindir => $self->ezmlm_bindir, ); }