6afce388e5ab6050b83cdb72c905c3761981036e
[p5sagit/Promulger.git] / lib / App / Promulger / Command / newsub.pm
1 package App::Promulger::Command::newsub;
2 use strict;
3 use warnings;
4
5 use App::Promulger -command;
6 use Promulger::List;
7
8 sub abstract {
9   return "subscribes a user to a list";
10 }
11
12 sub run {
13   my ($self, $opt, $args) = @_;
14   @$args >= 1 or die "pmg newsub needs a list name\n";
15   
16   my $listname = $args->[0];
17   my $list = Promulger::List->resolve($listname);
18
19   if(!$list) {
20     die "$listname doesn't exist\n";
21   }
22
23   if(@$args == 2) {
24     # got the subscriber as an arg
25     my $new_sub = $args->[1];
26     $list->subscribe($new_sub);
27   } else {
28     # reading from stdin
29     while(chomp(my $new_sub = <STDIN>)) {
30       $list->subscribe($new_sub);
31     }
32   }
33 }
34
35 'Make it so';