--- /dev/null
+package App::Promulger::Command::rmlist;
+use strict;
+use warnings;
+
+use App::Promulger -command;
+use Promulger::List;
+
+sub abstract {
+ return "removes a list";
+}
+
+sub run {
+ my ($self, $opt, $args) = @_;
+ @$args == 1 or die "pmg rmlist needs a list name\n";
+
+ my $listname = $args->[0];
+ my $list = Promulger::List->resolve($listname);
+
+ if($list) {
+ $list->delete;
+ } else {
+ die "$listname doesn't exist\n";
+ }
+}
+
+'Make it so';
+
use Carp;
use Path::Class;
use Fcntl ':flock';
+use Tie::File;
use Promulger::Config;
);
sub resolve {
- my($proto) = @_;
+ my ($self, $proto) = @_;
$proto =~ s/-request$//;
my $path = find_path_for($proto);
my $maybe_list;
}
sub subscribe {
- my($self, $new) = @_;
+ my ($self, $new) = @_;
return if $self->subscribers->at($new);
$self->subscribers->put($new, 1);
$self->store(find_path_for($self->name));
}
sub unsubscribe {
- my($self, $ex) = @_;
+ my ($self, $ex) = @_;
return unless $self->subscribers->at($ex);
$self->subscribers->delete($ex);
$self->store(find_path_for($self->name));
# XXX implement ACLs and other shinies -- apeiron, 2010-03-13
sub accept_posts_from {
- my($self, $sender) = @_;
+ my ($self, $sender) = @_;
return grep { $sender eq $_ } @{$self->subscribers};
}
sub setup {
- my($self) = @_;
+ my ($self) = @_;
my $config = Promulger::Config->config;
my $name = $self->listname;
- croak "${name} already a known list" if resolve($name);
+ croak "${name} already a known list" if $self->resolve($name);
my $path = find_path_for($name);
- open my $fh, '+<', $config->{aliases};
- flock $fh, LOCK_EX;
- my @current_contents = <$fh>;
- my @aliases = ($name, "${name}-request");
+ my $tie = tie my @aliases, 'Tie::File', $config->{aliases};
+ $tie->flock;
+ my @list_aliases = ($name, "${name}-request");
- for my $alias (@aliases) {
- if(grep { /^${alias}:/ } @current_contents) {
- croak "${alias} already in $config->{aliases}";
+ for my $list_alias (@list_aliases) {
+ if(grep { /^${list_alias}:/ } @aliases) {
+ croak "${list_alias} already in $config->{aliases}";
}
- push @current_contents,
- qq(${alias}: "|$config->{bin_root}/pmg msg -c $config->{config_file}"\n);
+ push @aliases,
+ qq(${list_alias}: "|$config->{bin_root}/pmg msg -c $config->{config_file}"\n);
}
$self->store($path->stringify);
- print $fh @current_contents;
- flock $fh, LOCK_UN;
+}
+
+sub delete {
+ my ($self) = @_;
+ my $config = Promulger::Config->config;
+ my $name = $self->listname;
+
+ my $tie = tie my @aliases, 'Tie::File', $config->{aliases};
+ $tie->flock;
+
+ my @list_aliases = ($name, "${name}-request");
+ @aliases = grep {
+ $_ !~ /^$list_aliases[0]:/ &&
+ $_ !~ /^$list_aliases[1]:/
+ } @aliases;
+
+ unlink find_path_for($self->listname);
}
sub find_path_for {
my ($proto) = @_;
my $path = file(Promulger::Config->config->{list_home}, $proto . ".list");
+ return $path;
}
'http://mitpress.mit.edu/sicp/';