initial sketch of classes
[scpubgit/App-EzPz.git] / lib / Email / EzPz / ListCore.pm
CommitLineData
c5f4b6d4 1package Email::EzPz::ListCore;
2
3use Moo::Role;
4use IO::All;
5use IPC::System::Simple qw(run capture);
6
7has list_dir => (is => 'ro', required => 1);
8
9has ezmlm_bindir => (is => 'ro', required => 1);
10
11requires 'sublist_type';
12
13sub _command_path {
14 my ($self, $command) = @_;
15 return io->dir($self->ezmlm_bindir)->catfile("ezmlm-${command}");
16}
17
18sub _command_args {
19 my ($self, $command, @args) = @_;
20 return (
21 $self->_command_path($command),
22 $self->list_dir,
23 $self->sublist_type,
24 @args
25 );
26}
27
28sub _call_command {
29 my ($self, @cmd) = @_;
30 run $self->_command_args(@cmd);
31}
32
33sub _capture_command {
34 my ($self, @cmd) = @_;
35 map { chomp; $_ } capture $self->_command_args(@cmd);
36}
37
38sub add_member {
39 my ($self, $member) = @_;
40 $self->_call_command(sub => $member);
41 return $member;
42}
43
44sub remove_member {
45 my ($self, $member) = @_;
46 $self->_call_command(unsub => $member);
47 return $member;
48}
49
50sub members {
51 my ($self) = @_;
52 $self->_capture_command('list');
53}
54
551;