line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mojolicious::Plugin::Helper::Vars; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
70933
|
use Mojo::Base 'Mojolicious::Plugin'; |
|
2
|
|
|
|
|
10584
|
|
|
2
|
|
|
|
|
11
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
our $VERSION = '0.0004'; |
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
|
|
|
|
|
|
|
=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 |
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 |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
=head1 AUTHOR |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
Михаил Че (Mikhail Che), C<< >> |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
=head1 BUGS / CONTRIBUTING |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
Please report any bugs or feature requests at L. 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
|
|
|
|
|
|
|
sub register { |
77
|
1
|
|
|
1
|
1
|
34
|
my ($self, $app, $conf) = @_; |
78
|
|
|
|
|
|
|
#~ $a = $app; |
79
|
1
|
|
50
|
|
|
5
|
my $helper = delete $conf->{helper} || 'vars'; |
80
|
|
|
|
|
|
|
$app->helper($helper => sub { |
81
|
1
|
|
|
1
|
|
11418
|
my $c = shift; |
82
|
1
|
|
|
|
|
3
|
my @vars; |
83
|
1
|
|
|
|
|
3
|
for (@_) { |
84
|
1
|
50
|
|
|
|
4
|
if (defined(my $stash = $c->stash($_))) { |
85
|
|
|
|
|
|
|
#~ warn "Stash [$_]:", $c->dumper($stash); |
86
|
1
|
50
|
|
|
|
18
|
if (ref($stash) eq 'ARRAY') { |
87
|
0
|
|
|
|
|
0
|
push @vars, map _val($_), @$stash; |
88
|
|
|
|
|
|
|
} else { |
89
|
1
|
|
|
|
|
3
|
push @vars, _val($stash); |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
|
93
|
1
|
50
|
|
|
|
5
|
if (my $param = $c->req->params->every_param($_)) { |
94
|
|
|
|
|
|
|
#~ warn "Param [$_]:", $c->dumper($param); |
95
|
|
|
|
|
|
|
#~ if (ref($param) eq 'ARRAY') { |
96
|
1
|
|
|
|
|
254
|
push @vars, map _val($_), @$param; |
97
|
|
|
|
|
|
|
#~ } else { |
98
|
|
|
|
|
|
|
#~ push @vars, map $val->($param); |
99
|
|
|
|
|
|
|
#~ } |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
} |
102
|
1
|
50
|
|
|
|
11
|
return wantarray ? @vars : shift(@vars); |
103
|
1
|
|
|
|
|
8
|
}); |
104
|
1
|
|
|
|
|
18
|
return $self; |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
sub _val { |
108
|
3
|
|
|
3
|
|
6
|
my $val = shift; |
109
|
3
|
50
|
33
|
|
|
18
|
return $val eq 'undef' || $val eq 'undefined' ? undef : $val; |
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
1; |