File Coverage

blib/lib/IP/CountryFlag/Params.pm
Criterion Covered Total %
statement 25 25 100.0
branch 10 16 62.5
condition 5 9 55.5
subroutine 8 8 100.0
pod 0 3 0.0
total 48 61 78.6


line stmt bran cond sub pod time code
1             package IP::CountryFlag::Params;
2              
3             $IP::CountryFlag::Params::VERSION = '0.14';
4             $IP::CountryFlag::Params::AUTHORITY = 'cpan:MANWAR';
5              
6             =head1 NAME
7              
8             IP::CountryFlag::Params - Placeholder for parameters for IP::CountryFlag.
9              
10             =head1 VERSION
11              
12             Version 0.14
13              
14             =cut
15              
16 2     2   38 use 5.006;
  2         5  
17 2     2   10 use strict; use warnings;
  2     2   3  
  2         43  
  2         8  
  2         4  
  2         62  
18 2     2   870 use Data::Validate::IP qw(is_ipv4 is_ipv6);
  2         52567  
  2         166  
19 2     2   14 use parent 'Exporter';
  2         4  
  2         17  
20              
21             our @EXPORT_OK = qw(validate);
22              
23 3 100 66 3 0 10 sub check_ip { die "ERROR: Received invalid IP [$_[0]]." unless (is_ipv4($_[0]) || is_ipv6($_[0])) };
24 1 50   1 0 33 sub check_path { die "ERROR: Received invalid Path [$_[0]]." unless (-d "$_[0]") };
25              
26             our $FIELDS = {
27             'ip' => { check => sub { check_ip(@_) }, type => 's' },
28             'path' => { check => sub { check_path(@_) }, type => 's' },
29             };
30              
31             sub validate {
32 4     4 0 6 my ($fields, $values) = @_;
33              
34 4 50       10 die "ERROR: Missing params list." unless (defined $values);
35              
36 4 50       10 die "ERROR: Parameters have to be hash ref" unless (ref($values) eq 'HASH');
37              
38 4         6 foreach my $field (sort keys %{$fields}) {
  4         16  
39             die "ERROR: Received invalid param: $field"
40 6 50       53 unless (exists $FIELDS->{$field});
41              
42             die "ERROR: Missing mandatory param: $field"
43 6 100 66     35 if ($fields->{$field} && !exists $values->{$field});
44              
45             die "ERROR: Received undefined mandatory param: $field"
46 4 50 33     15 if ($fields->{$field} && !defined $values->{$field});
47              
48             $FIELDS->{$field}->{check}->($values->{$field})
49 4 50       13 if defined $values->{$field};
50             }
51             }
52              
53             =head1 AUTHOR
54              
55             Mohammad S Anwar, C<< >>
56              
57             =head1 REPOSITORY
58              
59             L
60              
61             =head1 BUGS
62              
63             Please report any bugs / feature requests to C,
64             or through the web interface at L.
65             I will be notified & then you'll automatically be notified of progress on your bug
66             as I make changes.
67              
68             =head1 SUPPORT
69              
70             You can find documentation for this module with the perldoc command.
71              
72             perldoc IP::CountryFlag::Params
73              
74             You can also look for information at:
75              
76             =over 4
77              
78             =item * RT: CPAN's request tracker
79              
80             L
81              
82             =item * AnnoCPAN: Annotated CPAN documentation
83              
84             L
85              
86             =item * CPAN Ratings
87              
88             L
89              
90             =item * Search CPAN
91              
92             L
93              
94             =back
95              
96             =head1 LICENSE AND COPYRIGHT
97              
98             Copyright (C) 2011 - 2017 Mohammad S Anwar.
99              
100             This program is free software; you can redistribute it and/or modify it under
101             the terms of the the Artistic License (2.0). You may obtain a copy of the full
102             license at:
103              
104             L
105              
106             Any use, modification, and distribution of the Standard or Modified Versions is
107             governed by this Artistic License.By using, modifying or distributing the Package,
108             you accept this license. Do not use, modify, or distribute the Package, if you do
109             not accept this license.
110              
111             If your Modified Version has been derived from a Modified Version made by someone
112             other than you,you are nevertheless required to ensure that your Modified Version
113             complies with the requirements of this license.
114              
115             This license does not grant you the right to use any trademark, service mark,
116             tradename, or logo of the Copyright Holder.
117              
118             This license includes the non-exclusive, worldwide, free-of-charge patent license
119             to make, have made, use, offer to sell, sell, import and otherwise transfer the
120             Package with respect to any patent claims licensable by the Copyright Holder that
121             are necessarily infringed by the Package. If you institute patent litigation
122             (including a cross-claim or counterclaim) against any party alleging that the
123             Package constitutes direct or contributory patent infringement,then this Artistic
124             License to you shall terminate on the date that such litigation is filed.
125              
126             Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER AND
127             CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES. THE IMPLIED
128             WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR
129             NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY YOUR LOCAL LAW. UNLESS
130             REQUIRED BY LAW, NO COPYRIGHT HOLDER OR CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT,
131             INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE
132             OF THE PACKAGE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
133              
134             DEAFilter API itself is distributed under the terms of the Gnu GPLv3 licence.
135              
136             =cut
137              
138             1; # End of IP::CountryFlag::Params