blib/lib/Mojolicious/Plugin/Kavorka.pm

filter: Statementstmt 97.5% 39 / 40 Branchbran 50.0% 11 / 22 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 6 / 6 Podpod n/a totaltotal 82.3% 56 / 68 CC 13 SCAR 19.0
CC
13
Cov
81%
_around_action
10.0
register
5.3
BEGIN
1.0
CRAP 6.7
↑ Summary
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
BranchTrueFalseTotal
@_ ? : 1 0 1
if @_ != 2 0 1 1
$#_ >= 0 ? : 1 0 1
$#_ >= 1 ? : 1 0 1
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
BranchTrueFalseTotal
if @_ != 4 0 2 2
$#_ >= 0 ? : 2 0 2
$#_ >= 1 ? : 2 0 2
$#_ >= 2 ? : 2 0 2
$#_ >= 3 ? : 2 0 2
15 2 ▶ if (my $info = Kavorka->info($action)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $info = 'Kavorka'->info($action)) { } 2 0 2
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
BranchTrueFalseTotal
if $param->named 0 2 2
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  
↑ Summary