line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Data::Transpose::Validator::URL; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
832
|
use strict; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
46
|
|
4
|
2
|
|
|
2
|
|
7
|
use warnings; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
38
|
|
5
|
2
|
|
|
2
|
|
5
|
use base 'Data::Transpose::Validator::Base'; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
384
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
=head1 NAME |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
Data::Transpose::Validator::URL - Validate http(s) urls |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
=head1 SYNOPSIS |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
=cut |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
my $urlre = qr/(https?:\/\/)[\w\-\.]+\.(\w+) # domain |
17
|
|
|
|
|
|
|
(:\d+)* # the port |
18
|
|
|
|
|
|
|
(\/[\w:\.,;\?'\\\+&%\$\#=~\@!\-]+)* |
19
|
|
|
|
|
|
|
/x; |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
=head2 is_valid($url) |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
Validate the url or set an error |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
=cut |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub is_valid { |
30
|
11
|
|
|
11
|
1
|
2148
|
my ($self, $url) = @_; |
31
|
11
|
|
|
|
|
33
|
$self->reset_errors; |
32
|
11
|
100
|
|
|
|
533
|
if ($url =~ m/^($urlre)$/s) { |
33
|
4
|
|
|
|
|
17
|
return $1; |
34
|
|
|
|
|
|
|
} else { |
35
|
7
|
|
|
|
|
24
|
$self->error( |
36
|
|
|
|
|
|
|
["badurl", |
37
|
|
|
|
|
|
|
"URL is not correct (the protocol is required)"]); |
38
|
7
|
|
|
|
|
20
|
return undef; |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
|