From e2732a6a935bf54c4338a742c11e16eea6f26764 Mon Sep 17 00:00:00 2001 From: Tom Bloor Date: Tue, 25 Jul 2017 17:07:15 +0100 Subject: [PATCH] Change to underlying postcode regex for validation --- cpanfile | 2 +- lib/Pear/LocalLoop/Plugin/Validators.pm | 11 ++--------- 2 files changed, 3 insertions(+), 10 deletions(-) diff --git a/cpanfile b/cpanfile index 13d8ffc..6531d21 100644 --- a/cpanfile +++ b/cpanfile @@ -4,7 +4,7 @@ requires 'Data::UUID'; requires 'Devel::Dwarn'; requires 'Mojo::JSON'; requires 'Email::Valid'; -requires 'Geo::UK::Postcode'; +requires 'Geo::UK::Postcode::Regex'; requires 'Authen::Passphrase::BlowfishCrypt'; requires 'Time::Fake'; requires 'Scalar::Util'; diff --git a/lib/Pear/LocalLoop/Plugin/Validators.pm b/lib/Pear/LocalLoop/Plugin/Validators.pm index 677b4d0..cc07414 100644 --- a/lib/Pear/LocalLoop/Plugin/Validators.pm +++ b/lib/Pear/LocalLoop/Plugin/Validators.pm @@ -2,7 +2,7 @@ package Pear::LocalLoop::Plugin::Validators; use Mojo::Base 'Mojolicious::Plugin'; use Email::Valid; -use Geo::UK::Postcode; +use Geo::UK::Postcode::Regex qw/ is_valid_pc /; use Scalar::Util qw/ looks_like_number /; use File::Basename qw/ fileparse /; use DateTime::Format::Strptime; @@ -28,14 +28,7 @@ sub register { $app->validator->add_check( postcode => sub { my ( $validation, $name, $value ) = @_; - my $postcode; - try { - $postcode = Geo::UK::Postcode->new( $value ); - }; - return 1 unless defined( $postcode ); - return 1 if $postcode->partial; - return undef if $postcode->valid; - return 1; + return is_valid_pc( $value ) ? undef : 1; }); $app->validator->add_check( number => sub {