line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
2
|
|
|
2
|
|
1148
|
use strict; |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
125
|
|
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
package HTML::FormFu::Element::URL; |
4
|
|
|
|
|
|
|
$HTML::FormFu::Element::URL::VERSION = '2.07'; |
5
|
|
|
|
|
|
|
# ABSTRACT: HTML5 URL form field |
6
|
|
|
|
|
|
|
|
7
|
2
|
|
|
2
|
|
22
|
use Moose; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
18
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
extends 'HTML::FormFu::Element'; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
with 'HTML::FormFu::Role::Element::Input'; |
12
|
|
|
|
|
|
|
|
13
|
2
|
|
|
2
|
|
15017
|
use HTML::FormFu::Attribute qw( mk_output_accessors ); |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
800
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
has http_only => ( is => 'rw', traits => ['Chained'] ); |
16
|
|
|
|
|
|
|
has https_only => ( is => 'rw', traits => ['Chained'] ); |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
has error_message => ( |
19
|
|
|
|
|
|
|
is => 'rw', |
20
|
|
|
|
|
|
|
predicate => 'has_message', |
21
|
|
|
|
|
|
|
traits => ['Chained'], |
22
|
|
|
|
|
|
|
); |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
has _has_auto_regex_constraint => ( |
25
|
|
|
|
|
|
|
is => 'rw', |
26
|
|
|
|
|
|
|
init_arg => undef, |
27
|
|
|
|
|
|
|
); |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
__PACKAGE__->mk_output_accessors(qw( message )); |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
after BUILD => sub { |
32
|
|
|
|
|
|
|
my $self = shift; |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
$self->field_type('url'); |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
return; |
37
|
|
|
|
|
|
|
}; |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
sub pre_process { |
40
|
|
|
|
|
|
|
my ($self) = @_; |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
my $constraint; |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
if ( $self->_has_auto_regex_constraint ) { |
45
|
|
|
|
|
|
|
$constraint = $self->_has_auto_regex_constraint; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
else { |
48
|
|
|
|
|
|
|
my $scheme; |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
if ( $self->http_only ) { |
51
|
|
|
|
|
|
|
$scheme = 'http'; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
elsif ( $self->https_only ) { |
54
|
|
|
|
|
|
|
$scheme = 'https'; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
else { |
57
|
|
|
|
|
|
|
$scheme = 'https?'; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
$constraint = $self->constraint( |
61
|
|
|
|
|
|
|
{ type => 'Regex', |
62
|
|
|
|
|
|
|
common => [ 'URI', 'HTTP', { -scheme => $scheme }, ], |
63
|
|
|
|
|
|
|
} ); |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
$self->_has_auto_regex_constraint($constraint); |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
# 'pattern' attribute |
68
|
|
|
|
|
|
|
$self->pattern("$scheme://.*"); |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
my $message = $self->error_message; |
73
|
|
|
|
|
|
|
if ( defined $message && length $message ) { |
74
|
|
|
|
|
|
|
$constraint->message($message); |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
return; |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
1; |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
__END__ |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
=pod |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
=encoding UTF-8 |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=head1 NAME |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
HTML::FormFu::Element::URL - HTML5 URL form field |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
=head1 VERSION |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
version 2.07 |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
=head1 SYNOPSIS |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
my $element = $form->element( URL => 'foo' ); |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
# no need to add a separate constraint |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=head1 DESCRIPTION |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
HTML5 URL form field which provides native client-side validation in modern browsers. |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
Creates an input field with C<<type="url">>. |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
Also sets the C<pattern> attribute to restrict the client-side validation to only |
111
|
|
|
|
|
|
|
our desired schemes (http and/or https). |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
This element automatically adds a L<Regex constraint|HTML::FormFu::Constraint::Regex>, |
114
|
|
|
|
|
|
|
so you don't have to. |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
If neither L</http_only> or L</https_only> are set, the constraint allows any HTTP or HTTPS url. |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=head1 METHODS |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
=head2 http_only |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
=head2 https_only |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
=head2 message |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
Arguments: $string |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
Set the error message on the L<Regex constraint|HTML::FormFu::Constraint::Regex> which is |
129
|
|
|
|
|
|
|
automatically added. |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
=head2 message_xml |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
Arguments: $string |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
If you don't want your error message to be XML-escaped, use the L</message_xml> method |
136
|
|
|
|
|
|
|
instead of L</message>. |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
=head2 message_loc |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
Arguments: $localization_key |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
Set the error message using a L10N key. |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
=head1 SEE ALSO |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
Is a sub-class of, and inherits methods from |
147
|
|
|
|
|
|
|
L<HTML::FormFu::Role::Element::Input>, |
148
|
|
|
|
|
|
|
L<HTML::FormFu::Role::Element::Field>, |
149
|
|
|
|
|
|
|
L<HTML::FormFu::Element>. |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
L<HTML::FormFu> |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
=head1 AUTHOR |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
Carl Franks, C<cfranks@cpan.org> |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
=head1 LICENSE |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
This library is free software, you can redistribute it and/or modify it under |
160
|
|
|
|
|
|
|
the same terms as Perl itself. |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
=head1 AUTHOR |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
Carl Franks <cpan@fireartist.com> |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
This software is copyright (c) 2018 by Carl Franks. |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
171
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
=cut |