Example App
has 'quotes' => (is => 'lazy');
sub _build_quotes { open my $fh, '<mstomatic.raw.txt'; [ <$fh> ] }
sub dispatch_request {
my $self = shift;
sub (GET + /mstomatic) {
my @quotes = @{ $self->quotes };
chomp(my $quote = $quotes[rand @quotes]);
sub (.html) {
return [200, ['Content-Type' => 'text/html'], [<<"EOHTML"]];
<html>
<head><title>The MST-O-MATIC</title></head>
<body><h1><a href="http://shadowcat.co.uk/blog/matt-s-trout">${quote}</a></h1>
</html>
EOHTML
},
sub (.json) {
return [200, ['Content-Type' => 'application/json'], [encode_json({ quote => $quote })]];
}
}
}