DistanceMatrix/Params.pm

filter: Statementstmt 56.1% 32 / 57 Branchbran 11.1% 2 / 18 Conditioncond 23.8% 5 / 21 MC/DCmcdc 0.0% 0 / 11 Subroutinesub 37.5% 9 / 24 Podpod 0.0% 0 / 7 totaltotal 34.7% 48 / 138 SCAR 44.5
CC
18
Cov
41%
validate
110.0
check_latlng
10.5
__ANON__
6.0
CRAP 85.8
↑ Summary DistanceMatrix.pm »
1 package WWW::Google::DistanceMatrix::Params;
2  
3 5 $WWW::Google::DistanceMatrix::Params::VERSION = '0.19';
4 5 $WWW::Google::DistanceMatrix::Params::AUTHORITY = 'cpan:MANWAR';
5  
6 =head1 NAME
7  
8 WWW::Google::DistanceMatrix::Params - Placeholder for parameters for WWW::Google::DistanceMatrix
9  
10 =head1 VERSION
11  
12 Version 0.19
13  
14 =cut
15  
16 5 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 5 ▶use strict; use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
18 5 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 5 ▶use parent 'Exporter';
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 5 our @EXPORT_OK = qw(validate $FIELDS);
22  
23 5 my $LANGUAGES = {
24 'ar' => 1, 'eu' => 1, 'bg' => 1, 'bn' => 1, 'ca' => 1, 'cs' => 1, 'da' => 1, 'de' => 1,
25 'el' => 1, 'en' => 1, 'en-au' => 1, 'en-gb' => 1, 'es' => 1, 'eu' => 1, 'fa' => 1, 'fi' => 1,
26 'fi' => 1, 'fr' => 1, 'gl' => 1, 'gu' => 1, 'hi' => 1, 'hr' => 1, 'hu' => 1, 'id' => 1,
27 'it' => 1, 'iw' => 1, 'ja' => 1, 'kn' => 1, 'ko' => 1, 'lt' => 1, 'lv' => 1, 'ml' => 1,
28 'mr' => 1, 'nl' => 1, 'no' => 1, 'pl' => 1, 'pt' => 1, 'pt-br' => 1, 'pt-pt' => 1, 'ro' => 1,
29 'ru' => 1, 'sk' => 1, 'sl' => 1, 'sr' => 1, 'sv' => 1, 'tl' => 1, 'ta' => 1, 'te' => 1,
30 'th' => 1, 'tr' => 1, 'uk' => 1, 'vi' => 1, 'zh-cn' => 1, 'zh-tw' => 1 };
31  
32 5 my $AVOID = { 'tolls' => 1, 'highways' => 1 };
33 5 my $UNITS = { 'metric' => 1, 'imperial' => 1 };
34 5 my $MODE = { 'driving' => 1, 'walking' => 1, 'bicycling' => 1 };
35  
36 our $Language = sub {
37 0 ▶ my ($str) = @_;
Subroutine __ANON__: not called CC=2 SCAR=17.9
38  
39 0 ▶ die "ERROR: Invalid data type 'language' found [$str]" unless check_language($str);
Branch: 1 branch
BranchTrueFalseTotal
unless check_language($str) 0 0 0
40 5 };
41  
42 0 ▶sub check_language { return exists $LANGUAGES->{lc($_[0])}; }
Subroutine check_language: not called CC=1 SCAR=6.9
Pod undocumented
43  
44 0 ▶sub check_avoid { return exists $AVOID->{lc($_[0])}; }
Subroutine check_avoid: not called CC=1 SCAR=6.9
Pod undocumented
45  
46 0 ▶sub check_units { return exists $UNITS->{lc($_[0])}; }
Subroutine check_units: not called CC=1 SCAR=6.9
Pod undocumented
47  
48 0 ▶sub check_mode { return exists $MODE->{lc($_[0])}; }
Subroutine check_mode: not called CC=1 SCAR=6.9
Pod undocumented
49  
50 sub check_latlng {
51 1 ▶ my ($latlng) = @_;
Subroutine check_latlng: called CC=6 SCAR=23.5
Pod undocumented
52  
53 1 my $str = $latlng->[0];
54 1 my ($lat, $lng);
55 1 ▶ die "ERROR: Invalid data type 'latlng' found [$str]"
Branch: 1 branch
BranchTrueFalseTotal
unless defined $str and $str =~ /\,/ and (() = split(/\,/, $str, 2) and ($lat =~ /^\-?\d+\.?\d+$/ and $lng =~ /^\-?\d+\.?\d+$/)) 1 0 1
Condition33%4/12
defined $str and $str =~ /\,/ and (() = split(/\,/, $str, 2) and ($lat =~ /^\-?\d+\.?\d+$/ and $lng =~ /^\-?\d+\.?\d+$/))
!ll&&!rl&&r
010
defined $str and $str =~ /\,/
!ll&&!rl&&r
001
() = split(/\,/, $str, 2) and ($lat =~ /^\-?\d+\.?\d+$/ and $lng =~ /^\-?\d+\.?\d+$/)
!ll&&!rl&&r
010
$lat =~ /^\-?\d+\.?\d+$/ and $lng =~ /^\-?\d+\.?\d+$/
!ll&&!rl&&r
010
MC/DC0%0/5
defined $str and $str =~ /\,/ and (() = split(/\,/, $str, 2) and ($lat =~ /^\-?\d+\.?\d+$/ and $lng =~ /^\-?\d+\.?\d+$/))
defined $str $str =~ /\,/ () = split(/\,/, $str, 2) $lat =~ /^\-?\d+\.?\d+$/ $lng =~ /^\-?\d+\.?\d+$/
Truth table16%1/6
A and B and C and D and E
A= defined $strB= $str =~ /\,/C= () = split(/\,/, $str, 2)D= $lat =~ /^\-?\d+\.?\d+$/E= $lng =~ /^\-?\d+\.?\d+$/
ABCDEresult
0XXXX0
10XXX0
110XX0
1110X0
111100
111111
56 unless (defined($str)
57 &&
58 ($str =~ /\,/)
59 &&
60 ((($lat, $lng) = split /\,/, $str, 2)
61 &&
62 (($lat =~ /^\-?\d+\.?\d+$/) && ($lng =~ /^\-?\d+\.?\d+$/))));
63 }
64  
65 sub check_str {
66 1 ▶ my ($str) = @_;
Subroutine check_str: called CC=3 SCAR=13.1
Pod undocumented
67  
68 1 ▶ die "ERROR: Invalid STR data type [$str]"
Branch: 1 branch
BranchTrueFalseTotal
if defined $str and $str =~ /^\d+$/ 0 1 1
Condition33%1/3
defined $str and $str =~ /^\d+$/
!ll&&!rl&&r
010
MC/DC0%0/2
defined $str and $str =~ /^\d+$/
defined $str $str =~ /^\d+$/
Truth table33%1/3
A and B
A= defined $strB= $str =~ /^\d+$/
ABresult
0X0
100
111
69 if (defined $str && $str =~ /^\d+$/);
70 };
71  
72 our $FIELDS = {
73 1 ▶ 'o_addr' => { check => sub { check_str(@_) }, type => 's' },
Subroutine __ANON__: called CC=1 SCAR=0.0
74 1 ▶ 'o_latlng' => { check => sub { check_latlng(@_) }, type => 's' },
Subroutine __ANON__: called CC=1 SCAR=0.0
75 0 ▶ 'd_addr' => { check => sub { check_str(@_) }, type => 's' },
Subroutine __ANON__: not called CC=1 SCAR=6.9
76 0 ▶ 'd_latlng' => { check => sub { check_latlng(@_) }, type => 's' },
Subroutine __ANON__: not called CC=1 SCAR=6.9
77 0 ▶ 'origins' => { check => sub { check_str(@_) }, type => 's' },
Subroutine __ANON__: not called CC=1 SCAR=6.9
78 0 ▶ 'destinations' => { check => sub { check_str(@_) }, type => 's' },
Subroutine __ANON__: not called CC=1 SCAR=6.9
79 0 ▶ 'sensor' => { check => sub { check_str(@_) }, type => 's' },
Subroutine __ANON__: not called CC=1 SCAR=6.9
80 0 ▶ 'avoid' => { check => sub { check_str(@_) }, type => 's' },
Subroutine __ANON__: not called CC=1 SCAR=6.9
81 0 ▶ 'units' => { check => sub { check_units(@_) }, type => 's' },
Subroutine __ANON__: not called CC=1 SCAR=6.9
82 0 ▶ 'mode' => { check => sub { check_str(@_) }, type => 's' },
Subroutine __ANON__: not called CC=1 SCAR=6.9
83 0 ▶ 'language' => { check => sub { check_language(@_) }, type => 's' },
Subroutine __ANON__: not called CC=1 SCAR=1.2
84 };
85  
86 sub validate {
87 0 ▶ my ($fields, $values) = @_;
Subroutine validate: not called CC=10 SCAR=47.0
Pod undocumented
88  
89 0 ▶ die "ERROR: Missing params list." unless (defined $values);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $values 0 0 0
90  
91 0 ▶ die "ERROR: Parameters have to be hash ref" unless (ref($values) eq 'HASH');
Branch: 1 branch
BranchTrueFalseTotal
unless ref $values eq "HASH" 0 0 0
92  
93 0 foreach my $field (keys %{$fields}) {
94 die "ERROR: Received invalid param: $field"
95 0 ▶ unless (exists $FIELDS->{$field});
Branch: 1 branch
BranchTrueFalseTotal
unless exists $WWW::Google::DistanceMatrix::Params::FIELDS->{$field} 0 0 0
96  
97 die "ERROR: Received undefined mandatory param: $field"
98 0 ▶ if ($fields->{$field} && !defined $values->{$field});
Branch: 1 branch
BranchTrueFalseTotal
if $fields->{$field} and not defined $values->{$field} 0 0 0
Condition0%0/3
$fields->{$field} and not defined $values->{$field}
!ll&&!rl&&r
000
MC/DC0%0/2
$fields->{$field} and not defined $values->{$field}
$fields->{$field} not defined $values->{$field}
Truth table0%0/3
A and not(B)
A= $fields->{$field}B= not defined $values->{$field}
ABresult
0X0
100
111
99  
100 die "ERROR: Missing mandatory param: $field"
101 0 ▶ if ($fields->{$field} && !scalar(@{$values->{$field}}));
Branch: 1 branch
BranchTrueFalseTotal
if $fields->{$field} and not scalar @{$values->{$field};} 0 0 0
Condition0%0/3
$fields->{$field} and not scalar @{$values->{$field};}
!ll&&!rl&&r
000
MC/DC0%0/2
$fields->{$field} and not scalar @{$values->{$field};}
$fields->{$field} not scalar @{$values->{$field};}
Truth table0%0/3
A and not(B)
A= $fields->{$field}B= not scalar @{$values->{$field};}
ABresult
0X0
100
111
102  
103 $FIELDS->{$field}->{check}->($values->{$field})
104 0 ▶ if defined $values->{$field};
Branch: 1 branch
BranchTrueFalseTotal
if defined $values->{$field} 0 0 0
105 }
106 }
107  
108 =head1 AUTHOR
109  
110 Mohammad S Anwar, C<< <mohammad.anwar at yahoo.com> >>
111  
112 =head1 REPOSITORY
113  
114 L<https://github.com/manwar/WWW-Google-DistanceMatrix>
115  
116 =head1 BUGS
117  
118 Please report any bugs or feature requests to C<bug-www-google-distancematrix at
119 rt.cpan.org>, or through the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=WWW-Google-DistanceMatrix>.
120 I will be notified, and then you'll automatically be notified of progress on your
121 bug as I make changes.
122  
123 =head1 SUPPORT
124  
125 You can find documentation for this module with the perldoc command.
126  
127 perldoc WWW::Google::DistanceMatrix
128  
129 You can also look for information at:
130  
131 =over 4
132  
133 =item * RT: CPAN's request tracker (report bugs here)
134  
135 L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=WWW-Google-DistanceMatrix>
136  
137 =item * AnnoCPAN: Annotated CPAN documentation
138  
139 L<http://annocpan.org/dist/WWW-Google-DistanceMatrix>
140  
141 =item * CPAN Ratings
142  
143 L<http://cpanratings.perl.org/d/WWW-Google-DistanceMatrix>
144  
145 =item * Search CPAN
146  
147 L<http://search.cpan.org/dist/WWW-Google-DistanceMatrix/>
148  
149 =back
150  
151 =head1 LICENSE AND COPYRIGHT
152  
153 Copyright (C) 2011 - 2015 Mohammad S Anwar.
154  
155 This program is free software; you can redistribute it and/or modify it under
156 the terms of the the Artistic License (2.0). You may obtain a copy of the full
157 license at:
158  
159 L<http://www.perlfoundation.org/artistic_license_2_0>
160  
161 Any use, modification, and distribution of the Standard or Modified Versions is
162 governed by this Artistic License.By using, modifying or distributing the Package,
163 you accept this license. Do not use, modify, or distribute the Package, if you do
164 not accept this license.
165  
166 If your Modified Version has been derived from a Modified Version made by someone
167 other than you,you are nevertheless required to ensure that your Modified Version
168 complies with the requirements of this license.
169  
170 This license does not grant you the right to use any trademark, service mark,
171 tradename, or logo of the Copyright Holder.
172  
173 This license includes the non-exclusive, worldwide, free-of-charge patent license
174 to make, have made, use, offer to sell, sell, import and otherwise transfer the
175 Package with respect to any patent claims licensable by the Copyright Holder that
176 are necessarily infringed by the Package. If you institute patent litigation
177 (including a cross-claim or counterclaim) against any party alleging that the
178 Package constitutes direct or contributory patent infringement,then this Artistic
179 License to you shall terminate on the date that such litigation is filed.
180  
181 Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER AND
182 CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES. THE IMPLIED
183 WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR
184 NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY YOUR LOCAL LAW. UNLESS
185 REQUIRED BY LAW, NO COPYRIGHT HOLDER OR CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT,
186 INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE
187 OF THE PACKAGE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
188  
189 =cut
190  
191 5 1; # End of WWW::Google::DistanceMatrix::Params
↑ Summary DistanceMatrix.pm »