line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mojolicious::Plugin::Kavorka; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
654
|
use Mojo::Base 'Mojolicious::Plugin'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
5
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
our $VERSION = '0.01'; |
6
|
|
|
|
|
|
|
$VERSION = eval $VERSION; |
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
251
|
use Kavorka; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
12
|
|
9
|
|
|
|
|
|
|
|
10
|
1
|
50
|
|
1
|
|
2899
|
method register ($app, $config) { |
|
1
|
50
|
|
1
|
|
1
|
|
|
1
|
50
|
|
|
|
220
|
|
|
1
|
50
|
|
|
|
41
|
|
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
1
|
|
11
|
1
|
|
|
|
|
7
|
$app->hook(around_action => \&_around_action); |
12
|
|
|
|
|
|
|
} |
13
|
|
|
|
|
|
|
|
14
|
1
|
50
|
|
1
|
|
2289
|
fun _around_action ($next, $c, $action, $last) { |
|
1
|
50
|
|
2
|
|
2
|
|
|
1
|
50
|
|
|
|
345
|
|
|
2
|
50
|
|
|
|
16472
|
|
|
2
|
50
|
|
|
|
7
|
|
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
7
|
|
|
2
|
|
|
|
|
2
|
|
15
|
2
|
50
|
|
|
|
12
|
if (my $info = Kavorka->info($action)) { |
16
|
2
|
|
|
|
|
30
|
my $sig = $info->signature; |
17
|
2
|
|
|
|
|
3
|
my @args; |
18
|
2
|
|
|
|
|
11
|
for my $param ($sig->positional_params, $sig->named_params) { |
19
|
2
|
|
|
|
|
59
|
my $name = $param->name; |
20
|
2
|
|
|
|
|
62
|
my $sigil = $param->sigil; |
21
|
2
|
|
|
|
|
31
|
$name =~ s/^\Q$sigil//; |
22
|
2
|
50
|
|
|
|
46
|
push @args, $name if $param->named; |
23
|
2
|
|
|
|
|
9
|
push @args, $c->stash($name); |
24
|
|
|
|
|
|
|
} |
25
|
2
|
|
|
|
|
27
|
$c->$action(@args); |
26
|
|
|
|
|
|
|
} else { |
27
|
0
|
|
|
|
|
|
$next->(); |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|