Skip to content

Instantly share code, notes, and snippets.

@notbenh
Created November 23, 2011 00:35
Show Gist options
  • Save notbenh/1387546 to your computer and use it in GitHub Desktop.
Save notbenh/1387546 to your computer and use it in GitHub Desktop.
dancer multi method dispatch-ish thing
sub multi ($$) {
my $route_templates = shift;
my $route_definition = shift;
foreach my $type (keys %$route_templates) {
foreach my $route ( keys %$route_definition) {
my $action = sub{ $route_templates->{$type}->( $route_definition->{ $route } ) };
Dancer::App->current->registry->universal_add( $type
, $route
, $action
)
}
}
}
multi { get => sub{ template data => {data => shift->()}}
, ajax => sub{ to_json shift->()}
},
{ '/' => sub{{ hello => 'docs go here' }}
, '/:user' => sub{{ user => USER }}
, '/:user/content' => sub{{ content => USER->content_groups}}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment