Commit | Line | Data |
c5f4b6d4 |
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) = @_; |
b1194426 |
15 | if (ref(my $bindir = $self->ezmlm_bindir) eq 'ARRAY') { # prefix list |
16 | return (@{$bindir}, "ezmlm-${command}"); |
17 | } else { |
18 | return io->dir($bindir)->catfile("ezmlm-${command}"); |
19 | } |
c5f4b6d4 |
20 | } |
21 | |
22 | sub _command_args { |
23 | my ($self, $command, @args) = @_; |
24 | return ( |
25 | $self->_command_path($command), |
26 | $self->list_dir, |
27 | $self->sublist_type, |
28 | @args |
29 | ); |
30 | } |
31 | |
32 | sub _call_command { |
33 | my ($self, @cmd) = @_; |
34 | run $self->_command_args(@cmd); |
35 | } |
36 | |
37 | sub _capture_command { |
38 | my ($self, @cmd) = @_; |
39 | map { chomp; $_ } capture $self->_command_args(@cmd); |
40 | } |
41 | |
42 | sub add_member { |
43 | my ($self, $member) = @_; |
44 | $self->_call_command(sub => $member); |
45 | return $member; |
46 | } |
47 | |
48 | sub remove_member { |
49 | my ($self, $member) = @_; |
50 | $self->_call_command(unsub => $member); |
51 | return $member; |
52 | } |
53 | |
54 | sub members { |
55 | my ($self) = @_; |
56 | $self->_capture_command('list'); |
57 | } |
58 | |
59 | 1; |