From: Matt S Trout Date: Sun, 15 Jul 2012 17:59:37 +0000 (+0000) Subject: add config object, connect user system up to lists code X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=fda55d3e18008b847db5b383dc94e3fde8dcdf1e;p=scpubgit%2FApp-EzPz.git add config object, connect user system up to lists code --- diff --git a/bin/ezpz-admin-repl b/bin/ezpz-admin-repl index 22850c6..c26e8ac 100755 --- a/bin/ezpz-admin-repl +++ b/bin/ezpz-admin-repl @@ -5,8 +5,8 @@ use File::Which; use App::EzPz::UserStore; use strictures 1; -die "Usage: ezpz-admin-repl ezmlm-bindir htpasswd-file" - unless @ARGV == 2; +die "Usage: ezpz-admin-repl htpasswd-file [ezmlm-bindir list-base-dir]" + unless @ARGV == 1 or @ARGV == 3; { package Eval::WithLexicals::Scratchpad; @@ -14,8 +14,13 @@ die "Usage: ezpz-admin-repl ezmlm-bindir htpasswd-file" use vars qw($users); $users = App::EzPz::UserStore->new( - ezmlm_bindir => $ARGV[0], - htpasswd_file => $ARGV[1], + htpasswd_file => $ARGV[0], + (@ARGV > 1) + ? (ezmlm_config => { + bindir => $ARGV[1], + list_base_dir => $ARGV[2], + }) + : () ); } diff --git a/lib/App/EzPz/EzmlmConfig.pm b/lib/App/EzPz/EzmlmConfig.pm new file mode 100644 index 0000000..089f8a6 --- /dev/null +++ b/lib/App/EzPz/EzmlmConfig.pm @@ -0,0 +1,24 @@ +package App::EzPz::EzmlmConfig; + +use IO::All; +use Module::Runtime qw(use_module); +use Moo; + +has bindir => ( + is => 'ro', required => 1, +); + +has list_base_dir => ( + is => 'ro', required => 1, +); + +sub new_list_object { + my ($self, $args) = @_; + my $list_dir = io->dir($self->list_base_dir)->catdir($args->{list_name}); + use_module('Email::EzPz::List')->new( + list_dir => $list_dir, + ezmlm_bindir => $self->bindir, + ); +} + +1; diff --git a/lib/App/EzPz/User.pm b/lib/App/EzPz/User.pm index a4da2f1..770fc36 100644 --- a/lib/App/EzPz/User.pm +++ b/lib/App/EzPz/User.pm @@ -8,7 +8,12 @@ has _htpasswd_user => ( handles => [ qw(username password check_password) ], ); -has ezmlm_bindir => (is => 'rwp'); +has ezmlm_config => ( + is => 'rwp', + handles => { + _new_list_object => 'new_list_object' + } +); around BUILDARGS => sub { my ($orig, $self) = (shift, shift); @@ -37,20 +42,32 @@ sub set_list_names { return; } -sub add_list_name { +sub has_list_name { my ($self, $name) = @_; my %names; @names{my @names = $self->list_names} = (); - $self->set_list_names(@names, $name) unless exists $names{$name}; + return exists $names{$name}; +} + +sub add_list_name { + my ($self, $name) = @_; + unless ($self->has_list_name($name)) { + $self->set_list_names($self->list_names, $name); + } return $name; } sub remove_list_name { my ($self, $name) = @_; - my %names; @names{my @names = $self->list_names} = (); - if (exists $names{$name}) { + if ($self->has_list_name($name)) { $self->set_list_names(grep !($_ eq $name), $self->list_names) } return $name; } +sub get_list { + my ($self, $name) = @_; + return undef unless $self->has_list_name($name); + return $self->_new_list_object({ list_name => $name }); +} + 1; diff --git a/lib/App/EzPz/UserStore.pm b/lib/App/EzPz/UserStore.pm index 73669c5..672fec3 100644 --- a/lib/App/EzPz/UserStore.pm +++ b/lib/App/EzPz/UserStore.pm @@ -4,7 +4,13 @@ use Module::Runtime qw(use_module); use Scalar::Util 'blessed'; use Moo; -has ezmlm_bindir => (is => 'ro', required => 1); +has ezmlm_config => ( + is => 'ro', + coerce => sub { + return $_[0] if blessed($_[0]); + return use_module('App::EzPz::EzmlmConfig')->new($_[0]); + } +); has htpasswd_file => (is => 'ro', required => 1); @@ -38,7 +44,7 @@ sub add { my $htp_user = $user->_htpasswd_user; $htp_file->add_user($htp_user); $htp_user->file($htp_file); - $user->_set_ezmlm_bindir($self->ezmlm_bindir); + $user->_set_ezmlm_config($self->ezmlm_config); return $user; } @@ -52,7 +58,7 @@ sub _inflate_user { my ($self, $htp_user) = @_; return use_module('App::EzPz::User')->new( htpasswd_user => $htp_user, - ezmlm_bindir => $self->ezmlm_bindir, + ezmlm_config => $self->ezmlm_config, ); }