From: Matt S Trout Date: Sat, 14 Jul 2012 20:34:52 +0000 (+0000) Subject: initial sketch of classes X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=scpubgit%2FApp-EzPz.git;a=commitdiff_plain;h=c5f4b6d4439311a9459eddf55085115bfb2b9e0a initial sketch of classes --- diff --git a/bin/ezpz-repl b/bin/ezpz-repl new file mode 100755 index 0000000..fff851c --- /dev/null +++ b/bin/ezpz-repl @@ -0,0 +1,20 @@ +#!/usr/bin/env perl + +use File::Which; +use Email::EzPz::List; +use strictures 1; + +{ + package Eval::WithLexicals::Scratchpad; + + use vars qw($list); + + $list = Email::EzPz::List->new( + ezmlm_bindir => $ARGV[0], + list_dir => $ARGV[1], + ); +} + +do +which('tinyrepl'); + +exit 0; diff --git a/lib/Email/EzPz/List.pm b/lib/Email/EzPz/List.pm new file mode 100644 index 0000000..1b60894 --- /dev/null +++ b/lib/Email/EzPz/List.pm @@ -0,0 +1,26 @@ +package Email::EzPz::List; + +use Module::Runtime qw(use_module); +use Moo; + +with 'Email::EzPz::ListCore'; + +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 + ); +} + +1; diff --git a/lib/Email/EzPz/ListCore.pm b/lib/Email/EzPz/ListCore.pm new file mode 100644 index 0000000..9543e36 --- /dev/null +++ b/lib/Email/EzPz/ListCore.pm @@ -0,0 +1,55 @@ +package Email::EzPz::ListCore; + +use Moo::Role; +use IO::All; +use IPC::System::Simple qw(run capture); + +has list_dir => (is => 'ro', required => 1); + +has ezmlm_bindir => (is => 'ro', required => 1); + +requires 'sublist_type'; + +sub _command_path { + my ($self, $command) = @_; + return io->dir($self->ezmlm_bindir)->catfile("ezmlm-${command}"); +} + +sub _command_args { + my ($self, $command, @args) = @_; + return ( + $self->_command_path($command), + $self->list_dir, + $self->sublist_type, + @args + ); +} + +sub _call_command { + my ($self, @cmd) = @_; + run $self->_command_args(@cmd); +} + +sub _capture_command { + my ($self, @cmd) = @_; + map { chomp; $_ } capture $self->_command_args(@cmd); +} + +sub add_member { + my ($self, $member) = @_; + $self->_call_command(sub => $member); + return $member; +} + +sub remove_member { + my ($self, $member) = @_; + $self->_call_command(unsub => $member); + return $member; +} + +sub members { + my ($self) = @_; + $self->_capture_command('list'); +} + +1; diff --git a/lib/Email/EzPz/SubList.pm b/lib/Email/EzPz/SubList.pm new file mode 100644 index 0000000..8f80726 --- /dev/null +++ b/lib/Email/EzPz/SubList.pm @@ -0,0 +1,9 @@ +package Email::EzPz::SubList; + +use Moo; + +has sublist_type => (is => 'ro', required => 1); + +with 'Email::EzPz::ListCore'; + +1;