| 1 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | package HTML::FormFu::Element::URL; | ||||||||||||||||||||||||||||
| 4 | 2 | $HTML::FormFu::Element::URL::VERSION = '2.06'; | |||||||||||||||||||||||||||
| 5 | # ABSTRACT: HTML5 URL form field | ||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 2 | ▶ | use Moose; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 2 | extends 'HTML::FormFu::Element'; | |||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 2 | with 'HTML::FormFu::Role::Element::Input'; | |||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 2 | ▶ | use HTML::FormFu::Attribute qw( mk_output_accessors ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | 2 | has http_only => ( is => 'rw', traits => ['Chained'] ); | |||||||||||||||||||||||||||
| 16 | 2 | has https_only => ( is => 'rw', traits => ['Chained'] ); | |||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 2 | has error_message => ( | |||||||||||||||||||||||||||
| 19 | is => 'rw', | ||||||||||||||||||||||||||||
| 20 | predicate => 'has_message', | ||||||||||||||||||||||||||||
| 21 | traits => ['Chained'], | ||||||||||||||||||||||||||||
| 22 | ); | ||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | 2 | has _has_auto_regex_constraint => ( | |||||||||||||||||||||||||||
| 25 | is => 'rw', | ||||||||||||||||||||||||||||
| 26 | init_arg => undef, | ||||||||||||||||||||||||||||
| 27 | ); | ||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | 2 | __PACKAGE__->mk_output_accessors(qw( message )); | |||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | after BUILD => sub { | ||||||||||||||||||||||||||||
| 32 | 1 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | 1 | $self->field_type('url'); | |||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | 1 | return; | |||||||||||||||||||||||||||
| 37 | 2 | }; | |||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | sub pre_process { | ||||||||||||||||||||||||||||
| 40 | 3 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||
|
Subroutine
pre_process: called CC=6 SCAR=19.4
| |||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | 3 | my $constraint; | |||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | 3 | ▶ | if ( $self->_has_auto_regex_constraint ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 45 | 2 | $constraint = $self->_has_auto_regex_constraint; | |||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||
| 47 | else { | ||||||||||||||||||||||||||||
| 48 | 1 | my $scheme; | |||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | 1 | ▶ | if ( $self->http_only ) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 51 | 0 | $scheme = 'http'; | |||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||
| 53 | elsif ( $self->https_only ) { | ||||||||||||||||||||||||||||
| 54 | 0 | $scheme = 'https'; | |||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||
| 56 | else { | ||||||||||||||||||||||||||||
| 57 | 1 | $scheme = 'https?'; | |||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | 1 | $constraint = $self->constraint( | |||||||||||||||||||||||||||
| 61 | { type => 'Regex', | ||||||||||||||||||||||||||||
| 62 | common => [ 'URI', 'HTTP', { -scheme => $scheme }, ], | ||||||||||||||||||||||||||||
| 63 | } ); | ||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | 1 | $self->_has_auto_regex_constraint($constraint); | |||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | # 'pattern' attribute | ||||||||||||||||||||||||||||
| 68 | 1 | $self->pattern("$scheme://.*"); | |||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | 3 | my $message = $self->error_message; | |||||||||||||||||||||||||||
| 73 | 3 | ▶ | if ( defined $message && length $message ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $message and length $message
MC/DC0%0/2
defined $message and length $message
defined $message
length $message
Truth table33%1/3
A and B
A= defined $messageB= length $message
| |||||||||||||||||||||||||||||
| 74 | 0 | $constraint->message($message); | |||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | 3 | return; | |||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | 2 | __PACKAGE__->meta->make_immutable; | |||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | 2 | 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.06 | ||||||||||||||||||||||||||||
| 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 | ||||||||||||||||||||||||||||