| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package HTML::FormFu::Element::URL; |
|
2
|
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
860
|
use strict; |
|
|
2
|
|
|
|
|
2
|
|
|
|
2
|
|
|
|
|
74
|
|
|
4
|
|
|
|
|
|
|
our $VERSION = '2.05'; # VERSION |
|
5
|
|
|
|
|
|
|
|
|
6
|
2
|
|
|
2
|
|
7
|
use Moose; |
|
|
2
|
|
|
|
|
3
|
|
|
|
2
|
|
|
|
|
12
|
|
|
7
|
2
|
|
|
2
|
|
9006
|
use MooseX::Attribute::FormFuChained; |
|
|
2
|
|
|
|
|
2
|
|
|
|
2
|
|
|
|
|
78
|
|
|
8
|
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
extends 'HTML::FormFu::Element'; |
|
10
|
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
with 'HTML::FormFu::Role::Element::Input'; |
|
12
|
|
|
|
|
|
|
|
|
13
|
2
|
|
|
2
|
|
9
|
use HTML::FormFu::Attribute qw( mk_output_accessors ); |
|
|
2
|
|
|
|
|
4
|
|
|
|
2
|
|
|
|
|
516
|
|
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
has http_only => ( is => 'rw', traits => ['FormFuChained'] ); |
|
16
|
|
|
|
|
|
|
has https_only => ( is => 'rw', traits => ['FormFuChained'] ); |
|
17
|
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
has error_message => ( |
|
19
|
|
|
|
|
|
|
is => 'rw', |
|
20
|
|
|
|
|
|
|
predicate => 'has_message', |
|
21
|
|
|
|
|
|
|
traits => ['FormFuChained'], |
|
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 => [ |
|
63
|
|
|
|
|
|
|
'URI', |
|
64
|
|
|
|
|
|
|
'HTTP', |
|
65
|
|
|
|
|
|
|
{ -scheme => $scheme }, |
|
66
|
|
|
|
|
|
|
], |
|
67
|
|
|
|
|
|
|
}); |
|
68
|
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
$self->_has_auto_regex_constraint( $constraint ); |
|
70
|
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
# 'pattern' attribute |
|
72
|
|
|
|
|
|
|
$self->pattern( "$scheme://.*" ); |
|
73
|
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
} |
|
75
|
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
my $message = $self->error_message; |
|
77
|
|
|
|
|
|
|
if ( defined $message && length $message ) { |
|
78
|
|
|
|
|
|
|
$constraint->message( $message ); |
|
79
|
|
|
|
|
|
|
} |
|
80
|
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
return; |
|
82
|
|
|
|
|
|
|
}; |
|
83
|
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
|
85
|
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
1; |
|
87
|
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
__END__ |
|
89
|
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=head1 NAME |
|
91
|
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
HTML::FormFu::Element::URL - HTML5 URL form field |
|
93
|
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
=head1 VERSION |
|
95
|
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
version 2.05 |
|
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
|
|
|
|
|
|
|
=cut |