Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added inflate attribute.

  • Loading branch information...
commit d701cde4063fd1086b3bfdb3014d69d2249f5975 1 parent 4c7282b
moltar authored
Showing with 37 additions and 43 deletions.
  1. +14 −14 README.pod
  2. +17 −29 lib/HTML/FormHandlerX/Field/URI/HTTP.pm
  3. +6 −0 t/test.t
View
28 README.pod
@@ -1,20 +1,20 @@
+=pod
+
=head1 NAME
HTML::FormHandlerX::Field::URI::HTTP - an HTTP URI field
=head1 VERSION
-0.1
+version v0.2
=head1 SYNOPSIS
This field inherits from a Text field and is used to validate HTTP(S) URIs.
-Validate values are inflated into an L<URI> object.
+Validated values are inflated into an L<URI> object.
=head1 METHODS
-Only one extra method is supported:
-
=head2 scheme
This method is used to set the type of regex used for validating the URI. By
@@ -25,6 +25,11 @@ validate HTTP or HTTPS if you wish:
scheme => qr/https/i, # only validate HTTPS URIs
scheme => qr/https?/i, # validate both HTTP and HTTPS (default behaviour)
+=head2 inflate
+
+A boolean value that is checked whether or not the URL should be inflated into
+the L<URI> object. Default is true.
+
=head1 SEE ALSO
=over 4
@@ -41,17 +46,12 @@ validate HTTP or HTTPS if you wish:
=head1 AUTHOR
- Roman F.
- romanf@cpan.org
-
-=head1 COPYRIGHT
-
-Copyright (c) 2011 Roman F.
+Roman F. <romanf@cpan.org>
-This program is free software; you can redistribute
-it and/or modify it under the same terms as Perl itself.
+=head1 COPYRIGHT AND LICENSE
-The full text of the license can be found in the
-LICENSE file included with this module.
+This software is copyright (c) 2012 by Roman F..
+This is free software; you can redistribute it and/or modify it under
+the same terms as the Perl 5 programming language system itself.
View
46 lib/HTML/FormHandlerX/Field/URI/HTTP.pm
@@ -1,11 +1,13 @@
package HTML::FormHandlerX::Field::URI::HTTP;
+# ABSTRACT: an HTTP URI field
+
use Moose;
use Moose::Util::TypeConstraints;
extends 'HTML::FormHandler::Field::Text';
-use version; our $VERSION = version->declare("v0.1");
+use version; our $VERSION = version->declare("v0.2");
use URI;
use Regexp::Common qw(URI);
@@ -17,6 +19,12 @@ has 'scheme' => (
default => sub { qr/https?/i },
);
+has 'inflate' => (
+ is => 'rw',
+ isa => 'Bool',
+ default => 1,
+);
+
our $class_messages = {
'uri_http_invalid' => 'HTTP URI is invalid.',
};
@@ -37,7 +45,7 @@ sub validate {
my $regex = $RE{URI}{HTTP}{-scheme => $self->scheme};
if ($uri =~ m{^$regex$}) {
$is_valid = 1;
- $self->_set_value(URI->new($uri));
+ $self->_set_value($self->inflate ? URI->new($uri) : $uri);
} else {
$self->add_error($self->get_message('uri_http_invalid'));
}
@@ -52,23 +60,13 @@ use namespace::autoclean;
__END__
=pod
-=head1 NAME
-
-HTML::FormHandlerX::Field::URI::HTTP - an HTTP URI field
-
-=head1 VERSION
-
-0.1
-
=head1 SYNOPSIS
This field inherits from a Text field and is used to validate HTTP(S) URIs.
-Validate values are inflated into an L<URI> object.
+Validated values are inflated into an L<URI> object.
=head1 METHODS
-Only one extra method is supported:
-
=head2 scheme
This method is used to set the type of regex used for validating the URI. By
@@ -79,6 +77,11 @@ validate HTTP or HTTPS if you wish:
scheme => qr/https/i, # only validate HTTPS URIs
scheme => qr/https?/i, # validate both HTTP and HTTPS (default behaviour)
+=head2 inflate
+
+A boolean value that is checked whether or not the URL should be inflated into
+the L<URI> object. Default is true.
+
=head1 SEE ALSO
=over 4
@@ -93,19 +96,4 @@ validate HTTP or HTTPS if you wish:
=back
-=head1 AUTHOR
-
- Roman F.
- romanf@cpan.org
-
-=head1 COPYRIGHT
-
-Copyright (c) 2011 Roman F.
-
-This program is free software; you can redistribute
-it and/or modify it under the same terms as Perl itself.
-
-The full text of the license can be found in the
-LICENSE file included with this module.
-
-
+=cut
View
6 t/test.t
@@ -41,5 +41,11 @@ _pass($uri, 'http://example.com');
is $uri->value, 'http://example.com', 'value is set';
isa_ok $uri->value, 'URI';
+## value explicitly not inflated
+$uri = HTML::FormHandlerX::Field::URI::HTTP->new(name => 'uri', inflate => 0);
+_pass($uri, 'http://example.com/');
+is $uri->value, 'http://example.com/', 'value is set';
+ok ! ref $uri->value, 'not a ref';
+
done_testing;
# eof
Please sign in to comment.
Something went wrong with that request. Please try again.