package Email::EzPz::List;

use Module::Runtime qw(use_module);
use Moo;

with 'Email::EzPz::ListCore';

has name => (is => 'lazy');

sub _build_name { (shift->list_dir =~ m{/([^/]+)$})[0] }

sub sublist_type { () }

foreach my $type (qw(allow deny mod digest)) {
  has $type => (
    is => 'ro',
    lazy => 1,
    default => sub { shift->_build_sublist($type) }
  );
}

sub _build_sublist {
  my ($self, $type) = @_;
  return use_module('Email::EzPz::SubList')->new(
    (map +($_ => $self->$_), qw(list_dir ezmlm_bindir)),
    sublist_type => $type,
    name => $self->name." ${type} list"
  );
}

1;
