line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package HTML::FormHandlerX::Field::URI::HTTP; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# ABSTRACT: an HTTP URI field |
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
20285
|
use version; our $VERSION = version->declare('v0.4'); |
|
1
|
|
|
|
|
2546
|
|
|
1
|
|
|
|
|
6
|
|
6
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
1151
|
use HTML::FormHandler::Moose; |
|
1
|
|
|
|
|
1507017
|
|
|
1
|
|
|
|
|
10
|
|
8
|
|
|
|
|
|
|
extends 'HTML::FormHandler::Field::Text'; |
9
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
277168
|
use URI; |
|
1
|
|
|
|
|
5107
|
|
|
1
|
|
|
|
|
37
|
|
11
|
1
|
|
|
1
|
|
1023
|
use Regexp::Common qw(URI); |
|
1
|
|
|
|
|
2346
|
|
|
1
|
|
|
|
|
4
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
has 'scheme' => ( |
14
|
|
|
|
|
|
|
is => 'rw', |
15
|
|
|
|
|
|
|
isa => 'RegexpRef', |
16
|
|
|
|
|
|
|
required => 1, |
17
|
|
|
|
|
|
|
default => sub {qr/https?/i}, |
18
|
|
|
|
|
|
|
); |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
has 'inflate' => ( |
21
|
|
|
|
|
|
|
is => 'rw', |
22
|
|
|
|
|
|
|
isa => 'Bool', |
23
|
|
|
|
|
|
|
default => 1, |
24
|
|
|
|
|
|
|
); |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
our $class_messages = { 'uri_http_invalid' => 'HTTP URI is invalid.' }; |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub get_class_messages { |
29
|
4
|
|
|
4
|
0
|
423
|
my $self = shift; |
30
|
4
|
|
|
|
|
8
|
return { %{ $self->next::method }, %{$class_messages}, }; |
|
4
|
|
|
|
|
33
|
|
|
4
|
|
|
|
|
1252
|
|
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub validate { |
34
|
10
|
|
|
10
|
1
|
26655
|
my $self = shift; |
35
|
10
|
|
|
|
|
27
|
my $uri = $self->value; |
36
|
|
|
|
|
|
|
|
37
|
10
|
|
|
|
|
1125
|
my $is_valid = 0; |
38
|
10
|
|
|
|
|
87
|
my $regex = $RE{URI}{HTTP}{ -scheme => $self->scheme }; |
39
|
10
|
100
|
|
|
|
236
|
if ($uri =~ m{^$regex$}) { |
40
|
6
|
|
|
|
|
1499
|
$is_valid = 1; |
41
|
6
|
100
|
|
|
|
284
|
$self->_set_value($self->inflate ? URI->new($uri) : $uri); |
42
|
|
|
|
|
|
|
} else { |
43
|
4
|
|
|
|
|
397
|
$self->add_error($self->get_message('uri_http_invalid')); |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
10
|
|
|
|
|
32269
|
return $is_valid; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
50
|
1
|
|
|
1
|
|
30748
|
use namespace::autoclean; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
12
|
|
51
|
|
|
|
|
|
|
1; |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
__END__ |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
=pod |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
=head1 NAME |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
HTML::FormHandlerX::Field::URI::HTTP - an HTTP URI field |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
=head1 VERSION |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
version v0.4 |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
=head1 SYNOPSIS |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
This field inherits from a Text field and is used to validate HTTP(S) URIs. |
68
|
|
|
|
|
|
|
Validated values are inflated into an L<URI> object. |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
has_field 'url' => ( |
71
|
|
|
|
|
|
|
type => 'URI::HTTP', |
72
|
|
|
|
|
|
|
scheme => qr/https?/i, ## default |
73
|
|
|
|
|
|
|
inflate => 1, ## default |
74
|
|
|
|
|
|
|
); |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
=head1 METHODS |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
=head2 scheme |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
This method is used to set the type of regex used for validating the URI. By |
81
|
|
|
|
|
|
|
default both HTTP and HTTPS URIs are marked as valid. You can set this to only |
82
|
|
|
|
|
|
|
validate HTTP or HTTPS if you wish: |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
scheme => qr/http/i, # only validate HTTP URIs |
85
|
|
|
|
|
|
|
scheme => qr/https/i, # only validate HTTPS URIs |
86
|
|
|
|
|
|
|
scheme => qr/https?/i, # validate both HTTP and HTTPS (default behaviour) |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
=head2 inflate |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
A boolean value that is checked whether or not the URL should be inflated into |
91
|
|
|
|
|
|
|
the L<URI> object. Default is true. |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=head1 SEE ALSO |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=over 4 |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=item L<HTML::FormHandler> |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=item L<HTML::FormHandler::Field::Text> |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
=item L<Regexp::Common::URI::http> |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=item L<URI> |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
=back |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
=head1 AUTHOR |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
Roman F. <romanf@cpan.org> |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
This software is copyright (c) 2013 by Roman F.. |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
116
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=cut |