1 package Promulger::Web;
2 use Web::Simple 'Promulger::Web';
7 use Method::Signatures::Simple;
11 default => sub { 'etc/lists' },
15 sub dispatch_request {
18 redispatch_to '/index';
21 redispatch_to '/index';
24 redispatch_to '/index';
28 [ 200, [ 'Content-type', 'text/html' ], [ $self->render_index(@_) ] ]
30 sub (GET + /list/*/) {
31 my ($self, $list) = @_;
32 redispatch_to "/list/${list}";
35 my ($self, $list) = @_;
36 [ 200, [ 'Content-type', 'text/html' ], [ $self->show_list($list) ] ]
38 sub (GET + /list/*/subscriber/*) {
39 my ($self, $list, $subscriber) = @_;
42 [ 'Content-type', 'text/html' ],
43 [ $self->show_subscriber($list, $subscriber) ]
46 sub (GET + /list/*/subscriber/*/unsubscribe) {
47 my ($self, $list, $subscriber) = @_;
50 [ 'Content-type', 'text/html' ],
51 [ $self->unsubscribe($list, $subscriber) ]
54 sub (POST + /list/*/subscribe + %email=) {
55 my ($self, $list, $email) = @_;
58 [ 'Content-type', 'text/html' ],
59 [ $self->subscribe($list, $email) ],
63 [ 405, [ 'Content-type', 'text/plain' ], [ 'Method not allowed' ] ]
69 my @lists = Promulger::List->get_lists;
76 for my $list (@lists) {
77 $html .= qq{<li><a href="/list/${list}">${list}</a></li>};
83 method show_list($list_name) {
84 my $list = Promulger::List->resolve($list_name);
85 my $name = $list->listname;
86 my $active = $list->active;
87 my @subscribers = keys %{ $list->subscribers };
90 <p>Active: ${active}</p>
91 <form method="POST" action="/list/${list_name}/subscribe">
92 <input type="text" name="email">
97 for my $sub (@subscribers) {
98 $html .= qq{<li><a href="/list/${name}/subscriber/${sub}">${sub}</a></li>};
104 method subscribe($list_name, $email) {
105 my $list = Promulger::List->resolve($list_name);
106 $list->subscribe($email);
107 return "<p>Subscribed ${email} to ${list_name}.</p>";
110 method unsubscribe($list_name, $email) {
111 my $list = Promulger::List->resolve($list_name);
112 $list->unsubscribe($email);
113 return "<p>Unsubscribed ${email} from ${list_name}.</p>";
116 method show_subscriber($list_name, $subscriber) {
118 <p>Subscriber ${subscriber}</p>
119 <a href="/list/${list_name}/subscriber/${subscriber}/unsubscribe">unsubscribe</a>