line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Syccess::Validator::Call; |
2
|
|
|
|
|
|
|
BEGIN { |
3
|
2
|
|
|
2
|
|
3121
|
$Syccess::Validator::Call::AUTHORITY = 'cpan:GETTY'; |
4
|
|
|
|
|
|
|
} |
5
|
|
|
|
|
|
|
# ABSTRACT: A validator to check via call to a method |
6
|
|
|
|
|
|
|
$Syccess::Validator::Call::VERSION = '0.103'; |
7
|
2
|
|
|
2
|
|
19
|
use Moo; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
11
|
|
8
|
2
|
|
|
2
|
|
520
|
use Carp qw( croak ); |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
508
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
with qw( |
11
|
|
|
|
|
|
|
Syccess::ValidatorSimple |
12
|
|
|
|
|
|
|
); |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
has not => ( |
15
|
|
|
|
|
|
|
is => 'ro', |
16
|
|
|
|
|
|
|
predicate => 1, |
17
|
|
|
|
|
|
|
); |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub BUILD { |
20
|
3
|
|
|
3
|
0
|
1228
|
my ( $self ) = @_; |
21
|
3
|
50
|
66
|
|
|
18
|
croak __PACKAGE__.' cant have arg and not' |
22
|
|
|
|
|
|
|
if $self->has_arg and $self->has_not; |
23
|
3
|
50
|
66
|
|
|
60
|
croak __PACKAGE__.' requires arg or not' |
24
|
|
|
|
|
|
|
unless $self->has_arg or $self->has_not; |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
has message => ( |
28
|
|
|
|
|
|
|
is => 'lazy', |
29
|
|
|
|
|
|
|
); |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub _build_message { |
32
|
2
|
|
|
2
|
|
374
|
return 'Your value for %s is not valid.'; |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub validator { |
36
|
6
|
|
|
6
|
0
|
7
|
my ( $self, $value ) = @_; |
37
|
|
|
|
|
|
|
# probably making function() possible, don't know yet how, as the |
38
|
|
|
|
|
|
|
# function will be not available in my scope probably, and calling |
39
|
|
|
|
|
|
|
# on main:: doesnt sound much of a "functionality" |
40
|
6
|
100
|
|
|
|
7
|
my ( $thing, $method ) = @{$self->has_arg ? $self->arg : $self->not}; |
|
6
|
|
|
|
|
18
|
|
41
|
6
|
100
|
|
|
|
11
|
my $not = $self->has_not ? 1 : 0; |
42
|
6
|
100
|
|
|
|
53
|
my $return = $thing->$method($value) ? 1 : 0; |
43
|
6
|
100
|
100
|
|
|
62
|
return if ( $return and !$not ) or ( !$return and $not ); |
|
|
|
100
|
|
|
|
|
|
|
|
66
|
|
|
|
|
44
|
3
|
|
|
|
|
35
|
return $self->message; |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
1; |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
__END__ |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
=pod |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
=head1 NAME |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
Syccess::Validator::Call - A validator to check via call to a method |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
=head1 VERSION |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
version 0.103 |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
=head1 SYNOPSIS |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
Syccess->new( |
64
|
|
|
|
|
|
|
fields => [ |
65
|
|
|
|
|
|
|
foo => [ call => [ $thing, 'whitelisted' ] ], |
66
|
|
|
|
|
|
|
baz => [ call => { not => [ $thing, 'blacklisted' ] } ], |
67
|
|
|
|
|
|
|
bar => [ call => { |
68
|
|
|
|
|
|
|
not => [ $thing, 'blacklisted' ], |
69
|
|
|
|
|
|
|
message => 'You have 5 seconds to comply.' |
70
|
|
|
|
|
|
|
} ], |
71
|
|
|
|
|
|
|
], |
72
|
|
|
|
|
|
|
); |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
=head1 DESCRIPTION |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
This validator allows checking against a method call on an object. If used |
77
|
|
|
|
|
|
|
with the B<not> parameter, it will see success if the called method gives back |
78
|
|
|
|
|
|
|
a B<false> value, else it will succeed on a B<true> value. |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
=head1 ATTRIBUTES |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
=head2 message |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
This contains the error message or the format for the error message |
85
|
|
|
|
|
|
|
generation. See L<Syccess::Error/validator_message>. |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=encoding utf8 |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=head1 SUPPORT |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
IRC |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
Join #sycontent on irc.perl.org. Highlight Getty for fast reaction :). |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
Repository |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
http://github.com/SyContent/Syccess |
98
|
|
|
|
|
|
|
Pull request and additional contributors are welcome |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
Issue Tracker |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
http://github.com/SyContent/Syccess/issues |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=cut |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=head1 AUTHOR |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
Torsten Raudssus <torsten@raudss.us> |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
This software is copyright (c) 2014 by Torsten Raudssus. |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
115
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
=cut |