move the --config option to be global, also add a command to unsubscribe a
Chris Nehren [Sun, 4 Sep 2011 02:41:26 +0000 (22:41 -0400)]
member.

lib/App/Promulger.pm
lib/App/Promulger/Command.pm
lib/App/Promulger/Command/rmsub.pm [new file with mode: 0644]
lib/Promulger/Web.pm

index 545f962..1cce07d 100644 (file)
@@ -4,4 +4,12 @@ use warnings;
 
 use App::Cmd::Setup -app;
 
+use Promulger::Config;
+
+sub global_opt_spec {
+  return (
+    [ "config|c=s", "configuration file", { required => 1 } ],
+  );
+}
+
 1;
index 32f6315..1c699c6 100644 (file)
@@ -6,15 +6,9 @@ use App::Cmd::Setup -command;
 
 use Promulger::Config;
 
-sub opt_spec {
-  return (
-    [ "config|c=s", "configuration file", { required => 1 } ],
-  );
-}
-
 sub validate_args {
   my ($self, $opt, $args) = @_;
-  my $cf = $opt->{config};
+  my $cf = $self->app->global_options->{config};
 
   unless(-e $cf) {
     die "Config file $cf doesn't exist\n";
diff --git a/lib/App/Promulger/Command/rmsub.pm b/lib/App/Promulger/Command/rmsub.pm
new file mode 100644 (file)
index 0000000..f081f5b
--- /dev/null
@@ -0,0 +1,27 @@
+package App::Promulger::Command::rmsub;
+use strict;
+use warnings;
+
+use App::Promulger -command;
+use Promulger::List;
+
+sub abstract {
+  return "subscribes a user to a list";
+}
+
+sub run {
+  my ($self, $opt, $args) = @_;
+  @$args >= 2 or die "pmg newsub needs a list name and a departing member\n";
+  
+  my $listname = $args->[0];
+  my $list = Promulger::List->resolve($listname);
+
+  if(!$list) {
+    die "$listname doesn't exist\n";
+  }
+
+  my $ex_sub = $args->[1];
+  $list->unsubscribe($ex_sub);
+}
+
+'Make it so';
index 4698cb5..f549f1d 100644 (file)
@@ -43,7 +43,7 @@ sub dispatch_request {
       [ $self->show_subscriber($list, $subscriber) ] 
     ]
   },
-  sub (GET + /list/*/subscriber/*/unsubscribe) {
+  sub (POST + /list/*/subscriber/*/unsubscribe) {
     my ($self, $list, $subscriber) = @_;
     [ 
       200, 
@@ -116,7 +116,9 @@ method unsubscribe($list_name, $email) {
 method show_subscriber($list_name, $subscriber) {
   my $html = <<"HTML";
 <p>Subscriber ${subscriber}</p>
-<a href="/list/${list_name}/subscriber/${subscriber}/unsubscribe">unsubscribe</a>
+<form method="POST" action="/list/${list_name}/subscriber/${subscriber}/unsubscribe">
+<input type="submit" value="Unsubscribe">
+</form>
 HTML
 }