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