Dancer-Plugin-Chain
view release on metacpan or search on metacpan
lib/Dancer/Plugin/Chain.pm view on Meta::CPAN
'/schedule'
=> sub {
return sprintf "schedule of %s in %s\n", map { var $_ }
qw/ event site /;
};
=head1 DESCRIPTION
Implementation of Catalyst-like chained routes. This kind of behavior can
usually be fulfilled by judicious uses of C<prefix>. But hey, diversity is
the spice of life, so there you go.
The plugin exports a single keyword, C<chain>, which creates the chained
routes.
=head2 KNOWN CAVEATS
The plugin only support string-based urls for now (so no regexes).
=head1 EXPORTED FUNCTIONS
=head2 chain @chain_items, $coderef
Create a chain out of the items provided, and assign it the final action coderef.
Each chain item can be
a string representing a path segment, a previously defined chain or an
anonymous function. The chain's final path and action will be the aggregate of
its parts.
For example, the final route declaration of the SYNOPSIS,
get chain $continent,
sub { var temp => var 'site' },
$country,
sub {
var 'site' => join ', ', map { var $_ } qw/ site temp /
},
$event,
'/schedule'
=> sub {
return sprintf "schedule of %s in %s\n", map { var $_ }
qw/ event site /;
};
would be is equivalent to
get '/continent/:continent/country/:country/event/:event/schedule' => sub {
var 'site' => param('continent');
var temp => var 'site';
var 'site' => param('country');
var 'site' => join ', ', map { var $_ } qw/ site temp /
var 'event' => param('event');
return sprintf "schedule of %s in %s\n", map { var $_ }
qw/ event site /;
}
In scalar context, C<chain> returns its underlying object.
In list context, it returns a route / action pair of values (). That's how it
can work transparently with C<get>, C<post> and friends.
# returns the object, that can be used to forge longer chains.
my $foo_chain = chain '/foo', sub { ... };
# returns the pair that makes 'get' happy
get chain $foo_chain;
=head1 SEE ALSO
=over
=item *
Original blog entry: L<http://techblog.babyl.ca/entry/dancer-in-chains>
=item *
L<Dancer-Plugin-Dispatcher>
=back
=head1 AUTHOR
Yanick Champoux <yanick@cpan.org>
=head1 COPYRIGHT AND LICENSE
This software is copyright (c) 2017, 2014 by Yanick Champoux.
This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.
=cut
( run in 1.536 second using v1.01-cache-2.11-cpan-39bf76dae61 )