line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Valiemon::Attributes::Format; |
2
|
3
|
|
|
3
|
|
2003
|
use strict; |
|
3
|
|
|
|
|
9
|
|
|
3
|
|
|
|
|
96
|
|
3
|
3
|
|
|
3
|
|
16
|
use warnings; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
94
|
|
4
|
3
|
|
|
3
|
|
16
|
use utf8; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
18
|
|
5
|
3
|
|
|
3
|
|
488
|
use parent qw(Valiemon::Attributes); |
|
3
|
|
|
|
|
290
|
|
|
3
|
|
|
|
|
22
|
|
6
|
|
|
|
|
|
|
|
7
|
3
|
|
|
3
|
|
244
|
use Carp qw(croak); |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
201
|
|
8
|
3
|
|
|
3
|
|
1456
|
use Data::Validate::URI qw(); |
|
3
|
|
|
|
|
150096
|
|
|
3
|
|
|
|
|
835
|
|
9
|
|
|
|
|
|
|
|
10
|
40
|
|
|
40
|
0
|
252
|
sub attr_name { 'format' } |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub is_valid { |
13
|
41
|
|
|
41
|
0
|
103
|
my ($class, $context, $schema, $data) = @_; |
14
|
|
|
|
|
|
|
|
15
|
41
|
100
|
|
|
|
124
|
return 1 unless $context->prims->is_string($data); |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
$context->in_attr($class, sub { |
18
|
40
|
|
|
40
|
|
82
|
my $format = $schema->{format}; |
19
|
|
|
|
|
|
|
|
20
|
40
|
100
|
|
|
|
103
|
if ($format eq 'date-time') { |
21
|
10
|
|
|
|
|
120
|
return _validate_date_time($data); |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
|
24
|
30
|
100
|
|
|
|
65
|
if ($format eq 'uri') { |
25
|
16
|
|
|
|
|
35
|
return _validate_uri($data); |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
# TODO: email, hostname, ipv4, ipv6 |
29
|
|
|
|
|
|
|
|
30
|
14
|
|
|
|
|
1519
|
croak sprintf 'invalid format: `%s`', $format; |
31
|
40
|
|
|
|
|
240
|
}); |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub _validate_date_time { |
35
|
10
|
|
|
10
|
|
23
|
my ($data) = @_; |
36
|
|
|
|
|
|
|
# TODO: check range of value (date-month must be `01-12` etc...) |
37
|
10
|
100
|
|
|
|
61
|
$data =~ /\A\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d+)?(Z|[+-]\d{2}:\d{2})/ ? 1 : 0; |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub _validate_uri { |
41
|
16
|
|
|
16
|
|
29
|
my ($data) = @_; |
42
|
16
|
|
|
|
|
394
|
Data::Validate::URI::is_uri($data); |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
1; |