| 1 | package Mojolicious::Plugin::Helper::Vars; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 2 | ▶ | use Mojo::Base 'Mojolicious::Plugin'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | 2 | our $VERSION = '0.0004'; | |||||||||||||||||||||||||||
| 6 | 2 | my $pkg = __PACKAGE__; | |||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | =pod | ||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | =encoding utf8 | ||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | Доброго всем | ||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | =head1 Mojolicious::Plugin::Helper::Vars | ||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | ¡ ¡ ¡ ALL GLORY TO GLORIA ! ! ! | ||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | =head VERSION | ||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | 0.0004 | ||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | =head1 NAME | ||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | Mojolicious::Plugin::Helper::Vars - Stash & every_params to one var named. | ||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | =head1 SINOPSYS | ||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | $app->plugin('Helper::Vars'); | ||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | # controller | ||||||||||||||||||||||||||||
| 31 | $c->param('foo'=>[1,2,3]); | ||||||||||||||||||||||||||||
| 32 | $foo = $c->vars('foo'); # 1 | ||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | $c->stash('foo'=>['undef']); | ||||||||||||||||||||||||||||
| 35 | $c->stash('Foo'=>5); | ||||||||||||||||||||||||||||
| 36 | @foo = $c->vars('foo', 'Foo'); # (1,2,3,undef,5) | ||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | =head1 OPTIONS | ||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | =over 4 | ||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | =item * B<helper> | ||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | Name of the helper. Default - 'vars'. | ||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | Возвращает объединенный список stash & every_param и в скалярном контексте первое из определенных. String value 'undef' convert to undef. | ||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | =back | ||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | =head1 SEE ALSO | ||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | L<Mojolicious::Plugin::ParamExpand> | ||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | =head1 AUTHOR | ||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | Михаил Че (Mikhail Che), C<< <mche [on] cpan.org> >> | ||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | =head1 BUGS / CONTRIBUTING | ||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | Please report any bugs or feature requests at L<https://github.com/mche/Mojolicious-Plugin-Helper-Vars/issues>. Pull requests also welcome. | ||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | =head1 COPYRIGHT | ||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | Copyright 2016-2017 Mikhail Che. | ||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | This library is free software; you can redistribute it and/or modify | ||||||||||||||||||||||||||||
| 70 | it under the same terms as Perl itself. | ||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | =cut | ||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | #~ my $a; | ||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | 1 | ▶ | sub register { | ||||||||||||||||||||||||||
|
Subroutine
register: called CC=2 SCAR=7.2
Pod
documented
| |||||||||||||||||||||||||||||
| 77 | 1 | my ($self, $app, $conf) = @_; | |||||||||||||||||||||||||||
| 78 | #~ $a = $app; | ||||||||||||||||||||||||||||
| 79 | 1 | ▶ | my $helper = delete $conf->{helper} || 'vars'; | ||||||||||||||||||||||||||
|
Condition50%1/2
delete $conf->{'helper'} || 'vars'
MC/DC0%0/1
delete $conf->{'helper'} || 'vars'
delete $conf->{'helper'}
Truth table50%1/2
A
A= delete $conf->{'helper'}
| |||||||||||||||||||||||||||||
| 80 | 1 | ▶ | $app->helper($helper => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=6 SCAR=19.1
| |||||||||||||||||||||||||||||
| 81 | 1 | my $c = shift; | |||||||||||||||||||||||||||
| 82 | 1 | my @vars; | |||||||||||||||||||||||||||
| 83 | 1 | for (@_) { | |||||||||||||||||||||||||||
| 84 | 1 | ▶ | if (defined(my $stash = $c->stash($_))) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 85 | #~ warn "Stash [$_]:", $c->dumper($stash); | ||||||||||||||||||||||||||||
| 86 | 1 | ▶ | if (ref($stash) eq 'ARRAY') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 87 | 0 | push @vars, map _val($_), @$stash; | |||||||||||||||||||||||||||
| 88 | } else { | ||||||||||||||||||||||||||||
| 89 | 1 | push @vars, _val($stash); | |||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | 1 | ▶ | if (my $param = $c->req->params->every_param($_)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 94 | #~ warn "Param [$_]:", $c->dumper($param); | ||||||||||||||||||||||||||||
| 95 | #~ if (ref($param) eq 'ARRAY') { | ||||||||||||||||||||||||||||
| 96 | 1 | push @vars, map _val($_), @$param; | |||||||||||||||||||||||||||
| 97 | #~ } else { | ||||||||||||||||||||||||||||
| 98 | #~ push @vars, map $val->($param); | ||||||||||||||||||||||||||||
| 99 | #~ } | ||||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||
| 102 | 1 | ▶ | return wantarray ? @vars : shift(@vars); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 103 | 1 | }); | |||||||||||||||||||||||||||
| 104 | 1 | return $self; | |||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | 3 | ▶ | sub _val { | ||||||||||||||||||||||||||
|
Subroutine
_val: called CC=3 SCAR=13.1
| |||||||||||||||||||||||||||||
| 108 | 3 | my $val = shift; | |||||||||||||||||||||||||||
| 109 | 3 | ▶ | return $val eq 'undef' || $val eq 'undefined' ? undef : $val; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$val eq "undef" or $val eq "undefined"
MC/DC0%0/2
$val eq "undef" or $val eq "undefined"
$val eq "undef"
$val eq "undefined"
Truth table33%1/3
A or B
A= $val eq "undef"B= $val eq "undefined"
| |||||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||
| 112 | 2 | 1; | |||||||||||||||||||||||||||