CountryFlag/Params.pm

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