1 package Promulger::Web;
2 use Web::Simple 'Promulger::Web';
9 default => sub { 'etc/lists' },
13 sub dispatch_request {
16 redispatch_to '/index';
19 redispatch_to '/index';
22 redispatch_to '/index';
26 [ 200, [ 'Content-type', 'text/html' ], [ $self->render_index(@_) ] ]
28 sub (GET + /list/*/) {
29 my ($self, $list) = @_;
30 redispatch_to "/list/${list}";
33 my ($self, $list) = @_;
34 [ 200, [ 'Content-type', 'text/html' ], [ $self->show_list($list) ] ]
36 sub (GET + /list/*/subscriber/* + .*) {
37 my ($self, $list, $subscriber, $extension) = @_;
40 [ 'Content-type', 'text/html' ],
41 [ $self->show_subscriber($list, $subscriber, $extension) ]
44 sub (POST + /list/*/subscriber/*/unsubscribe) {
45 my ($self, $list, $subscriber) = @_;
48 [ 'Content-type', 'text/html' ],
49 [ $self->unsubscribe($list, $subscriber) ]
52 sub (POST + /list/*/subscribe + %email=) {
53 my ($self, $list, $email) = @_;
56 [ 'Content-type', 'text/html' ],
57 [ $self->subscribe($list, $email) ],
61 [ 405, [ 'Content-type', 'text/plain' ], [ 'Method not allowed' ] ]
67 my @lists = Promulger::List->get_lists;
74 for my $list (@lists) {
75 $html .= qq{<li><a href="/list/${list}">${list}</a></li>};
82 my ($self, $list_name) = @_;
83 my $list = Promulger::List->resolve($list_name);
84 my $name = $list->listname;
85 my $active = $list->active;
86 my @subscribers = keys %{ $list->subscribers };
89 <p>Active: ${active}</p>
90 <form method="POST" action="/list/${list_name}/subscribe">
91 <input type="text" name="email">
96 for my $sub (@subscribers) {
97 $html .= qq{<li><a href="/list/${name}/subscriber/${sub}">${sub}</a></li>};
104 my ($self, $list_name, $email) = @_;
105 my $list = Promulger::List->resolve($list_name);
106 $list->subscribe($email);
107 return "<p>Subscribed ${email} to ${list_name}.</p>";
111 my ($self, $list_name, $email) = @_;
112 my $list = Promulger::List->resolve($list_name);
113 $list->unsubscribe($email);
114 return "<p>Unsubscribed ${email} from ${list_name}.</p>";
117 sub show_subscriber {
118 my ($self, $list_name, $subscriber, $extension) = @_;
119 my $address = "${subscriber}.${extension}";
121 <p>Subscriber ${address}</p>
122 <form method="POST" action="/list/${list_name}/subscriber/${address}/unsubscribe">
123 <input type="submit" value="Unsubscribe">