Commit | Line | Data |
a9e4d3d0 |
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 | $list->delete; |
21 | } else { |
22 | die "$listname doesn't exist\n"; |
23 | } |
24 | |
25 | if(@$args == 2) { |
26 | # got the subscriber as an arg |
27 | my $new_sub = $args->[1]; |
28 | $list->subscribe($new_sub); |
29 | } else { |
30 | # reading from stdin |
31 | while(chomp(my $new_sub = <STDIN>)) { |
32 | $list->subscribe($new_sub); |
33 | } |
34 | } |
35 | } |
36 | |
37 | 'Make it so'; |