From: Chris Nehren Date: Sat, 3 Sep 2011 22:24:16 +0000 (-0400) Subject: Fix list creation, add a method to enumerate a list's subscribers. X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=0456162d259639d660e8d24de30c226a7fd9ad9b;p=p5sagit%2FPromulger.git Fix list creation, add a method to enumerate a list's subscribers. --- diff --git a/lib/App/Promulger/Command/members.pm b/lib/App/Promulger/Command/members.pm new file mode 100644 index 0000000..3499540 --- /dev/null +++ b/lib/App/Promulger/Command/members.pm @@ -0,0 +1,28 @@ +package App::Promulger::Command::members; +use strict; +use warnings; + +use App::Promulger -command; +use Promulger::List; + +sub abstract { + return "shows the subscribers to a list"; +} + +sub run { + my ($self, $opt, $args) = @_; + @$args >= 1 or die "pmg members needs a list name\n"; + + my $listname = $args->[0]; + my $list = Promulger::List->resolve($listname); + + if(!$list) { + die "$listname doesn't exist\n"; + } + + for my $subscriber (keys %{ $list->subscribers } ) { + print "$subscriber\n"; + } +} + +'Make it so'; diff --git a/lib/App/Promulger/Command/newlist.pm b/lib/App/Promulger/Command/newlist.pm index d9338fb..2b79775 100644 --- a/lib/App/Promulger/Command/newlist.pm +++ b/lib/App/Promulger/Command/newlist.pm @@ -16,6 +16,8 @@ sub run { my $listname = $args->[0]; my $list = Promulger::List->new( listname => $listname, + active => 1, + subscribers => {}, ); $list->setup; } diff --git a/lib/Promulger/List.pm b/lib/Promulger/List.pm index 9e0e969..ad79fbf 100644 --- a/lib/Promulger/List.pm +++ b/lib/Promulger/List.pm @@ -6,8 +6,9 @@ use Carp; use Path::Class; use Fcntl ':flock'; use Tie::File; -use File::Slurp qw/read_file, write_file/; +use File::Slurp qw/read_file write_file/; use Data::Dumper; +use Try::Tiny; $Data::Dumper::Purity = 1; use Promulger::Config; @@ -37,8 +38,10 @@ sub resolve { $proto =~ s/-request$//; my $path = find_path_for($proto); my $maybe_list; - eval { + try { $maybe_list = __PACKAGE__->load($path->stringify); + } catch { + die "oh noes: $_"; }; return $maybe_list; } @@ -121,4 +124,13 @@ sub load { return do $path; } +sub get_lists { + my ($self) = @_; + my $config = Promulger::Config->config; + my @lists = map { $_->basename} + grep { -f } dir($config->{list_home})->children; + s/\.list//g for @lists; + return @lists; +} + 'http://mitpress.mit.edu/sicp/';