Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Tree: aa3a7fe403
Fetching contributors…

Cannot retrieve contributors at this time

69 lines (54 sloc) 1.529 kB
package PoliticalWeb;
use Dancer2;
use Dancer2::Plugin::DBIC;
use Dancer2::Plugin::Cache::CHI;
use Data::Dumper;
use PoliticalWeb::Constituency;
our $VERSION = '0.1';
# check_page_cache;
get '/' => sub {
return template 'index' unless keys %{ +params };
if (my $pc = params->{pc}) {
params->{constit} = PoliticalWeb::Constituency->name_from_postcode($pc);
}
if (params->{constit}) {
redirect 'http://' . request->host . '/constituency/' . params->{constit};
}
template 'index', { error => 'Postcode "' . params->{pc} . '"' };
};
get '/about/' => sub {
my $page = template 'about/index';
cache_page $page;
return $page;
};
get '/register' => sub {
my $page = template 'register';
cache_page $page;
return $page;
};
get '/constituency/?' => sub {
template 'index', { error => 'That constituency' };
};
get '/constituency/:constname' => sub {
my $constit = PoliticalWeb::Constituency->new_from_name(params->{constname});
my $mp = $constit->get_mp if $constit;
if ($constit && $mp) {
my $page = template 'constituency', {
constit => $constit,
mp => $mp,
};
cache_page $page;
return $page;
} else {
template 'index', { error => 'Constituency "' . params->{constname} . '"' };
}
};
get '/constituencies/' => sub {
my $con_rs = schema->resultset('Constituency');
my $page = template 'constituencies/index', {
constits => [ $con_rs->search({}, { order_by => 'name'} )->all ]
};
cache_page $page;
return $page;
};
true;
Jump to Line
Something went wrong with that request. Please try again.