line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mojolicious::Plugin::Helper::Vars; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
27539
|
use Mojo::Base 'Mojolicious::Plugin'; |
|
2
|
|
|
|
|
7078
|
|
|
2
|
|
|
|
|
9
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
our $VERSION = '0.0002'; |
6
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
=head1 NAME |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
Mojolicious::Plugin::Helper::Vars - Stash & every_params to one var named. |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
=head1 SINOPSYS |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
$app->plugin('Helper::Vars'); |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
# controller |
27
|
|
|
|
|
|
|
$c->param('foo'=>[1,2,3]); |
28
|
|
|
|
|
|
|
$foo = $c->vars('foo'); # 1 |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
$c->stash('foo'=>['undef']); |
31
|
|
|
|
|
|
|
$c->stash('Foo'=>5); |
32
|
|
|
|
|
|
|
@foo = $c->vars('foo', 'Foo'); # (1,2,3,undef,5) |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
=head1 OPTIONS |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
=over 4 |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
=item * B |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
Name of the helper. Default - 'vars'. |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
Возвращает объединенный список stash & every_param и в скалярном контексте первое из определенных. String value 'undef' convert to undef. |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
=back |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
=head1 SEE ALSO |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
L |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
=head1 AUTHOR |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
Михаил Че (Mikhail Che), C<< >> |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
=head1 BUGS / CONTRIBUTING |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
Please report any bugs or feature requests at L. Pull requests also welcome. |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
=head1 COPYRIGHT |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
Copyright 2016 Mikhail Che. |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify |
66
|
|
|
|
|
|
|
it under the same terms as Perl itself. |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
=cut |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
#~ my $a; |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
sub register { |
73
|
1
|
|
|
1
|
1
|
27
|
my ($self, $app, $conf) = @_; |
74
|
|
|
|
|
|
|
#~ $a = $app; |
75
|
1
|
|
50
|
|
|
4
|
my $helper = delete $conf->{helper} || 'vars'; |
76
|
|
|
|
|
|
|
$app->helper($helper => sub { |
77
|
1
|
|
|
1
|
|
7570
|
my $c = shift; |
78
|
1
|
|
|
|
|
2
|
my @vars; |
79
|
1
|
50
|
|
|
|
3
|
my $val = sub{my $val = shift; $val eq 'undef' ? undef : $val;}; |
|
3
|
|
|
|
|
4
|
|
|
3
|
|
|
|
|
8
|
|
80
|
1
|
|
|
|
|
1
|
for (@_) { |
81
|
1
|
50
|
|
|
|
4
|
if (my $stash = $c->stash($_)) { |
82
|
|
|
|
|
|
|
#~ warn "Stash [$_]:", $c->dumper($stash); |
83
|
1
|
50
|
|
|
|
14
|
if (ref($stash) eq 'ARRAY') { |
84
|
0
|
|
|
|
|
0
|
push @vars, map $val->($_), @$stash; |
85
|
|
|
|
|
|
|
} else { |
86
|
1
|
|
|
|
|
2
|
push @vars, $val->($stash); |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
} |
90
|
1
|
|
|
|
|
2
|
for (@_) { |
91
|
1
|
50
|
|
|
|
2
|
if (my $param = $c->req->params->every_param($_)) { |
92
|
|
|
|
|
|
|
#~ warn "Param [$_]:", $c->dumper($param); |
93
|
1
|
50
|
|
|
|
185
|
if (ref($param) eq 'ARRAY') { |
94
|
1
|
|
|
|
|
5
|
push @vars, map $val->($_), @$param; |
95
|
|
|
|
|
|
|
} else { |
96
|
0
|
|
|
|
|
0
|
push @vars, map $val->($param); |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
} |
100
|
1
|
50
|
|
|
|
11
|
return wantarray ? @vars : shift(@vars); |
101
|
1
|
|
|
|
|
5
|
}); |
102
|
1
|
|
|
|
|
13
|
return $self; |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
1; |