line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Data::Format::Validate::URL; |
2
|
|
|
|
|
|
|
our $VERSION = q/0.3/; |
3
|
|
|
|
|
|
|
|
4
|
2
|
|
|
2
|
|
134917
|
use Carp; |
|
2
|
|
|
|
|
17
|
|
|
2
|
|
|
|
|
86
|
|
5
|
2
|
|
|
2
|
|
10
|
use base q/Exporter/; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
879
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our @EXPORT_OK = qw/ |
8
|
|
|
|
|
|
|
looks_like_any_url |
9
|
|
|
|
|
|
|
looks_like_full_url |
10
|
|
|
|
|
|
|
/; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
our %EXPORT_TAGS = ( |
13
|
|
|
|
|
|
|
q/all/ => [qw/ |
14
|
|
|
|
|
|
|
looks_like_any_url |
15
|
|
|
|
|
|
|
looks_like_full_url |
16
|
|
|
|
|
|
|
/] |
17
|
|
|
|
|
|
|
); |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub looks_like_any_url ($) { |
20
|
|
|
|
|
|
|
|
21
|
11
|
|
33
|
11
|
0
|
117
|
my $url = shift || croak q/Value must be provided/; |
22
|
11
|
|
|
|
|
75
|
$url =~ /^ |
23
|
|
|
|
|
|
|
((https?|ftp):\/\/)? # Protocol (optional) |
24
|
|
|
|
|
|
|
[a-z0-9-]+(\.[a-z0-9-]+)+ # URL name (with optional hostname) |
25
|
|
|
|
|
|
|
([\/?].*)? # URL path & params (both optional) |
26
|
|
|
|
|
|
|
$/ix |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub looks_like_full_url ($) { |
30
|
|
|
|
|
|
|
|
31
|
8
|
|
33
|
8
|
0
|
100
|
my $url = shift || croak q/Value must be provided/; |
32
|
8
|
|
|
|
|
60
|
$url =~ /^ |
33
|
|
|
|
|
|
|
(https?|ftp):\/\/ # Protocol |
34
|
|
|
|
|
|
|
(www|ftp)\. # Hostname |
35
|
|
|
|
|
|
|
[a-z0-9-]+(\.[a-z0-9-]+)+ # URL name |
36
|
|
|
|
|
|
|
([\/?].*)? # URL path & params (both optional) |
37
|
|
|
|
|
|
|
$/ix |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
1; |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
=pod |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
=encoding utf8 |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
=head1 NAME |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
Data::Format::Validate::URL - A URL validating module. |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
=head1 SYNOPSIS |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
Function-oriented module capable of validating: |
52
|
|
|
|
|
|
|
- Any URL with name, with or without protocol, hostname, path or params |
53
|
|
|
|
|
|
|
- Full URL, with protocol, hostname and name, with or without path or params |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
=head1 UTILITIES |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
=over 4 |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
=item Any URL |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
use Data::Format::Validate::URL 'looks_like_any_url'; |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
looks_like_any_url 'duckduckgo.com'; # returns 1 |
64
|
|
|
|
|
|
|
looks_like_any_url 'www. duckduckgo'; # returns 0 |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
=item Only full URL |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
use Data::Format::Validate::URL 'looks_like_full_url'; |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
looks_like_full_url 'http://www.duckduckgo.com/search?q=perl'; # returns 1 |
71
|
|
|
|
|
|
|
looks_like_full_url 'http://duckduckgo.com'; # returns 0 |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
=back |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
=head1 CONTRIBUITION |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
This source is on Github: |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
https://github.com/rozcovo/Data-Format-Validate/blob/master/lib/Data/Format/Validate/URL.pm |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=head1 AUTHOR |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
Created by Israel Batista |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=cut |