Address-PostCode-Australia
view release on metacpan or search on metacpan
lib/Address/PostCode/Australia/Params.pm view on Meta::CPAN
package Address::PostCode::Australia::Params;
$Address::PostCode::Australia::Params::VERSION = '0.12';
$Address::PostCode::Australia::Params::AUTHORITY = 'cpan:MANWAR';
=head1 NAME
Address::PostCode::Australia::Params - Placeholder for parameters for Address::PostCode::Australia
=head1 VERSION
Version 0.12
=head1 DESCRIPTION
B<FOR INTERNAL USE ONLY>
=cut
use 5.006;
use strict; use warnings;
use Data::Dumper;
use parent 'Exporter';
our @EXPORT_OK = qw(validate);
sub check_num {
my ($num) = @_;
die "ERROR: Invalid NUM data type [$num]"
unless (defined $num && $num =~ /^\d+$/);
};
sub check_str {
my ($str) = @_;
die "ERROR: Invalid STR data type [$str]"
if (defined $str && $str =~ /^\d+$/);
};
our $FIELDS = {
'postcode' => { check => sub { check_num(@_) }, type => 'd' },
'location' => { check => sub { check_str(@_) }, type => 's' },
'state' => { check => sub { check_str(@_) }, type => 's' },
};
sub validate {
my ($fields, $values) = @_;
die "ERROR: Missing params list." unless (defined $values);
die "ERROR: Parameters have to be hash ref" unless (ref($values) eq 'HASH');
foreach my $field (keys %{$fields}) {
die "ERROR: Received invalid param: $field"
unless (exists $FIELDS->{$field});
die "ERROR: Missing mandatory param: $field"
if ($fields->{$field} && !exists $values->{$field});
die "ERROR: Received undefined mandatory param: $field"
if ($fields->{$field} && !defined $values->{$field});
$FIELDS->{$field}->{check}->($values->{$field})
if defined $values->{$field};
}
}
=head1 AUTHOR
Mohammad S Anwar, C<< <mohammad.anwar at yahoo.com> >>
=head1 REPOSITORY
L<https://github.com/manwar/Address-PostCode-Australia>
=head1 BUGS
Please report any bugs or feature requests to C<bug-address-postcode-australia at rt.cpan.org>,
or through the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Address-PostCode-Australia>.
I will be notified, and then you'll automatically be notified of progress on your
bug as I make changes.
( run in 0.573 second using v1.01-cache-2.11-cpan-39bf76dae61 )