line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Slovo::Validator; |
2
|
14
|
|
|
14
|
|
87
|
use Mojo::Base 'Mojolicious::Validator', -signatures; |
|
14
|
|
|
|
|
24
|
|
|
14
|
|
|
|
|
279
|
|
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
# can this $name with $value do $sub with @args? |
5
|
22
|
|
|
22
|
|
1503
|
my sub _can ($v, $name, $value, $sub, @args) { |
|
22
|
|
|
|
|
37
|
|
|
22
|
|
|
|
|
50
|
|
|
22
|
|
|
|
|
48
|
|
|
22
|
|
|
|
|
43
|
|
|
22
|
|
|
|
|
41
|
|
|
22
|
|
|
|
|
37
|
|
6
|
22
|
|
|
|
|
113
|
return !$sub->($v, $name, $value, @args); |
7
|
|
|
|
|
|
|
} |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
sub new { |
10
|
5
|
|
|
5
|
1
|
56
|
my $self = shift->SUPER::new(@_); |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
# new filters |
13
|
5
|
|
|
23
|
|
1488
|
$self->add_filter(xml_escape => sub { Mojo::Util::xml_escape($_[2]) }); |
|
23
|
|
|
|
|
691
|
|
14
|
5
|
|
|
23
|
|
108
|
$self->add_filter(slugify => sub { Mojo::Util::slugify($_[2], 1) }); |
|
23
|
|
|
|
|
664
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
# new checks |
17
|
5
|
|
|
|
|
57
|
$self->add_check(is => \&_can); |
18
|
0
|
|
|
|
|
|
$self->add_check( |
19
|
0
|
|
|
0
|
|
0
|
equals => sub ($v, $name, $value, $eq) { |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
20
|
0
|
0
|
|
|
|
0
|
unless ($value eq $eq) { |
21
|
0
|
|
|
|
|
0
|
return 1; |
22
|
|
|
|
|
|
|
} |
23
|
0
|
|
|
|
|
0
|
return; |
24
|
5
|
|
|
|
|
229
|
}); |
25
|
5
|
|
|
|
|
230
|
return $self; |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
1; |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
=encoding utf8 |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
=head1 NAME |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
Slovo::Validator - additional validator filters and checks |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
=head1 CHECKS |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
Slovo::Validator inherits all checks from Mojolicious::Validator and implements |
39
|
|
|
|
|
|
|
the following new ones. |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
=head2 is |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
A custom check -- some code reference which returns true on success, false |
44
|
|
|
|
|
|
|
otherwise. |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
# in the action |
47
|
|
|
|
|
|
|
$v->required('id')->is(\&_writable_by, $c->stranici, $c->user); |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
# in the same or parent controller |
50
|
|
|
|
|
|
|
sub _writable_by ($v, $id_name, $id_value, $m, $user) { |
51
|
|
|
|
|
|
|
return !!$m->find_where({$id_name => $id_value, %{$m->writable_by($user)}}); |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
# or simply |
55
|
|
|
|
|
|
|
$v->required('sum')->is(sub($v, $name, $value) { |
56
|
|
|
|
|
|
|
$v->param('one') + $v->param('two') == $value |
57
|
|
|
|
|
|
|
}); |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
=head1 FILTERS |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
Slovo::Validator inherits all filters from Mojolicious::Validator and |
62
|
|
|
|
|
|
|
implements the following new ones. |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
=head2 slugify |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
$v->required('alias', 'slugify')->size(0, 255); |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
Generate URL slug for bytestream with L. |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
=head2 xml_escape |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
$c->validation->optional(title => xml_escape => 'trim')->size(10, 255); |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
Uses L to escape unsafe characters. Returns the escaped |
75
|
|
|
|
|
|
|
string. |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
=head1 SEE ALSO |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
L, L |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=cut |
82
|
|
|
|
|
|
|
|