command for subscribing users
Chris Nehren [Sat, 26 Jun 2010 12:58:28 +0000 (08:58 -0400)]
lib/App/Promulger/Command/newsub.pm [new file with mode: 0644]

diff --git a/lib/App/Promulger/Command/newsub.pm b/lib/App/Promulger/Command/newsub.pm
new file mode 100644 (file)
index 0000000..567221f
--- /dev/null
@@ -0,0 +1,37 @@
+package App::Promulger::Command::newsub;
+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 >= 1 or die "pmg newsub 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";
+  }
+
+  if(@$args == 2) {
+    # got the subscriber as an arg
+    my $new_sub = $args->[1];
+    $list->subscribe($new_sub);
+  } else {
+    # reading from stdin
+    while(chomp(my $new_sub = <STDIN>)) {
+      $list->subscribe($new_sub);
+    }
+  }
+}
+
+'Make it so';