line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package HTML::CheckArgs::url; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
7
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
39
|
|
4
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
616
|
|
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
6
|
use base 'HTML::CheckArgs::Object'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
663
|
|
7
|
1
|
|
|
1
|
|
931
|
use URI::Find; |
|
1
|
|
|
|
|
9274
|
|
|
1
|
|
|
|
|
80
|
|
8
|
1
|
|
|
1
|
|
1363
|
use LWP::UserAgent; |
|
1
|
|
|
|
|
47881
|
|
|
1
|
|
|
|
|
307
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub is_valid { |
11
|
6
|
|
|
6
|
0
|
8
|
my $self = shift; |
12
|
|
|
|
|
|
|
|
13
|
6
|
|
|
|
|
33
|
my $value = $self->value; |
14
|
6
|
|
|
|
|
30
|
my $config = $self->config; |
15
|
|
|
|
|
|
|
|
16
|
6
|
|
|
|
|
45
|
$self->check_params( required => [], optional => [ qw( verify max_chars ) ], cleanable => 0 ); |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
# no value passed in |
19
|
6
|
100
|
66
|
|
|
65
|
if ( $config->{required} && !$value ) { |
|
|
50
|
33
|
|
|
|
|
20
|
1
|
|
|
|
|
8
|
$self->error_code( 'url_00' ); # required |
21
|
1
|
|
|
|
|
9
|
$self->error_message( 'Not given.' ); |
22
|
1
|
|
|
|
|
5
|
return; |
23
|
|
|
|
|
|
|
} elsif ( !$config->{required} && !$value ) { |
24
|
0
|
|
|
|
|
0
|
return 1; |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
|
27
|
5
|
|
|
|
|
8
|
my @urls; |
28
|
5
|
|
|
|
|
9
|
my $url = $value; ### find_uris modifies $value |
29
|
5
|
100
|
|
4
|
|
42
|
unless ( find_uris( $url, sub { push @urls, shift } ) ) { |
|
4
|
|
|
|
|
11834
|
|
30
|
1
|
|
|
|
|
36598
|
$self->error_code( 'url_01' ); # not valid |
31
|
1
|
|
|
|
|
4
|
$self->error_message( 'Not valid.' ); |
32
|
1
|
|
|
|
|
8
|
return; |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
# check params |
36
|
4
|
100
|
|
|
|
178
|
if ( $config->{params}{verify} ) { |
37
|
2
|
|
|
|
|
22
|
my $ua = LWP::UserAgent->new; |
38
|
2
|
|
|
|
|
605
|
my $response = $ua->get( $value ); |
39
|
2
|
100
|
|
|
|
235185
|
if ( $response->is_error ) { |
40
|
1
|
|
|
|
|
75
|
$self->error_code( 'url_02' ); # not reachable |
41
|
1
|
|
|
|
|
6
|
$self->error_message( 'Not accessible.' ); |
42
|
1
|
|
|
|
|
35
|
return; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
# check length if db field limits are an issue |
47
|
3
|
|
|
|
|
105
|
my $max_chars = $config->{params}{max_chars}; |
48
|
3
|
100
|
66
|
|
|
23
|
if ( $max_chars && ( length( $value ) > $max_chars ) ) { |
49
|
1
|
|
|
|
|
7
|
$self->error_code( 'url_03' ); # over max chars |
50
|
1
|
|
|
|
|
7
|
$self->error_message( "Exceeds the maximum allowable length ($max_chars characters)." ); |
51
|
1
|
|
|
|
|
6
|
return; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
2
|
|
|
|
|
27
|
return 1; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
1; |