| 1 | package Mojolicious::Plugin::Kavorka; | ||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||
| 3 | 1 | ▶ | use Mojo::Base 'Mojolicious::Plugin'; | ||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||
| 5 | 1 | our $VERSION = '0.01'; | |||||||||||||||||||||||||
| 6 | 1 | $VERSION = eval $VERSION; | |||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||
| 8 | 1 | ▶ | use Kavorka; | ||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||
| 10 | 1 | ▶ | method register ($app, $config) { | ||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.1
Subroutine
register: called CC=5 SCAR=16.6
Branch: 4 branches
| |||||||||||||||||||||||||||
| 11 | 1 | $app->hook(around_action => \&_around_action); | |||||||||||||||||||||||||
| 12 | } | ||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||
| 14 | 1 | ▶ | fun _around_action ($next, $c, $action, $last) { | ||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.2
Subroutine
_around_action: called CC=9 SCAR=23.0
Branch: 5 branches
| |||||||||||||||||||||||||||
| 15 | 2 | ▶ | if (my $info = Kavorka->info($action)) { | ||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||
| 16 | 2 | my $sig = $info->signature; | |||||||||||||||||||||||||
| 17 | 2 | my @args; | |||||||||||||||||||||||||
| 18 | 2 | for my $param ($sig->positional_params, $sig->named_params) { | |||||||||||||||||||||||||
| 19 | 2 | my $name = $param->name; | |||||||||||||||||||||||||
| 20 | 2 | my $sigil = $param->sigil; | |||||||||||||||||||||||||
| 21 | 2 | $name =~ s/^\Q$sigil//; | |||||||||||||||||||||||||
| 22 | 2 | ▶ | push @args, $name if $param->named; | ||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||
| 23 | 2 | push @args, $c->stash($name); | |||||||||||||||||||||||||
| 24 | } | ||||||||||||||||||||||||||
| 25 | 2 | $c->$action(@args); | |||||||||||||||||||||||||
| 26 | } else { | ||||||||||||||||||||||||||
| 27 | 0 | $next->(); | |||||||||||||||||||||||||
| 28 | } | ||||||||||||||||||||||||||
| 29 | } | ||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||
| 31 | 1 | 1; | |||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||
| 33 | =head1 NAME | ||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||
| 35 | Mojolicious::Plugin::Kavorka - Signature sugar for your Mojolicious controller actions | ||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||
| 37 | =head1 SYNOPSIS | ||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||
| 39 | use Mojolicious::Lite; | ||||||||||||||||||||||||||
| 40 | use Kavorka; | ||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||
| 42 | plugin 'Kavorka'; | ||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||
| 44 | get '/:name' => method ($name) { | ||||||||||||||||||||||||||
| 45 | $self->render("Hello $name!"); | ||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||
| 48 | app->start; | ||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||
| 50 | =head1 DESCRIPTION | ||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||
| 52 | L<Kavorka> lets you define methods with introspectable signatures. | ||||||||||||||||||||||||||
| 53 | Using that extra knowledge can make your controller methods clearer and friendlier. | ||||||||||||||||||||||||||
| 54 | L<Mojolicious::Plugin::Kavorka> sits in your dispatch layer and if a target controller method (action) was declared with L<Kavorka> it will extract stash variables of the same name and pass them to the method. | ||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||
| 56 | This plugin is a very rough release, I'm not sure what functionality should be added nor what semantics it should have. | ||||||||||||||||||||||||||
| 57 | Consider it very experimental. | ||||||||||||||||||||||||||
| 58 | That said, this is a rich testbed for future functionality; if you have ideas or suggestions, please let me know! | ||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||
| 60 | =head1 SEE ALSO | ||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||
| 62 | =over | ||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||
| 64 | =item L<Kavorka> | ||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||
| 66 | =item L<Moops> | ||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||
| 68 | =back | ||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||
| 70 | =head1 SOURCE REPOSITORY | ||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||
| 72 | L<http://github.com/jberger/Mojolicious-Plugin-Kavorka> | ||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||
| 74 | =head1 AUTHOR | ||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||
| 76 | Joel Berger, E<lt>joel.a.berger@gmail.comE<gt> | ||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||
| 78 | =head1 COPYRIGHT AND LICENSE | ||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||
| 80 | Copyright (C) 2015 by Joel Berger | ||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||
| 82 | This library is free software; you can redistribute it and/or modify | ||||||||||||||||||||||||||
| 83 | it under the same terms as Perl itself. | ||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||