Skip to content

Commit

Permalink
Use Lingua::EN::Inflexion. Be cleverer at building routes.
Browse files Browse the repository at this point in the history
  • Loading branch information
Dave Cross committed Oct 2, 2015
1 parent 6864f93 commit 0017816
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions Literature/lib/Literature.pm
@@ -1,6 +1,7 @@
package Literature;
use Dancer2;
use Dancer2::Plugin::DBIC;
use Lingua::EN::Inflexion;

our $VERSION = '0.1';

Expand All @@ -16,23 +17,25 @@ my %resources = qw[
fictional_characters FictionalCharacter
];

my $route_re = '/(' . join('|', keys %resources) . ')/';
my $id_re = $route_re . '(\d+)';
my $route_re = '/(' . join('|', keys %resources) . ')/(\d+)?';

get '/' => sub {
template 'index';
};

get qr{^$route_re$} => sub {
my ($resource) = splat;
template $resource,
{ $resource => resultset($resources{$resource}) };
};

get qr{$id_re} => sub {
my ($resource, $id) = splat;
template substr($resource, 0, -1),
{ lc $resources{$resource} => resultset($resources{$resource})->find($id) };

if (defined $id) {
template noun($resource)->singular, {
lc $resources{$resource} =>
resultset($resources{$resource})->find($id)
};
} else {
template $resource, {
$resource => resultset($resources{$resource})
};
}
};

true;

0 comments on commit 0017816

Please sign in to comment.