add config object, connect user system up to lists code
[scpubgit/App-EzPz.git] / lib / App / EzPz / UserStore.pm
index 8b0a557..672fec3 100644 (file)
@@ -1,11 +1,16 @@
 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);
+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);
 
@@ -13,7 +18,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 +38,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_config($self->ezmlm_config);
   return $user;
 }
 
@@ -50,8 +56,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_config => $self->ezmlm_config,
   );
 }