Types.pm

filter: Statementstmt 95.4% 63 / 66 Branchbran 100% 6 / 6 Conditioncond 66.6% 6 / 9 MC/DCmcdc 50.0% 3 / 6 Subroutinesub 80.0% 12 / 15 Podpod n/a totaltotal 88.2% 90 / 102 CC 10 SCAR 9.2
CC
10
Cov
93%
__ANON__
4.0
__ANON__
4.0
__ANON__
4.0
CRAP 2.5
« Client.pm ↑ Summary Response/Polyline.pm »
1 package Google::Directions::Types;
2 =head1 NAME
3  
4 Google::Directions::Types
5  
6 =head1 DESCRIPTION
7  
8 Types used in Google::Directions modules
9  
10 =cut
11  
12 3 ▶use MooseX::Types::Moose -all;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 3 ▶use MooseX::Types -declare => [qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
14 ArrayRefOfLegs
15 ArrayRefOfPoints
16 ArrayRefOfRoutes
17 ArrayRefOfSteps
18 BoundsClass
19 CoordinatesClass
20 LegClass
21 PolylineClass
22 RouteClass
23 StatusCode
24 StepClass
25 TravelMode
26 ValueFromHashRef
27 3 )];
28  
29  
30 # Bounds
31 3 class_type BoundsClass, { class => 'Google::Directions::Response::Bounds' };
32  
33 coerce BoundsClass,
34 from HashRef,
35 3 ▶ via { Google::Directions::Response::Bounds->new( %{ $_ } ) };
Subroutine __ANON__: called CC=1 SCAR=0.0
36  
37 # Coordinates
38 3 class_type CoordinatesClass, { class => 'Google::Directions::Response::Coordinates' };
39  
40 coerce CoordinatesClass,
41 from HashRef,
42 90 ▶ via { Google::Directions::Response::Coordinates->new( %{ $_ } ) };
Subroutine __ANON__: called CC=1 SCAR=0.0
43  
44  
45 # Polyline
46 3 class_type PolylineClass, { class => 'Google::Directions::Response::Polyline' };
47  
48 coerce PolylineClass,
49 from HashRef,
50 36 ▶ via { Google::Directions::Response::Polyline->new( %{ $_ } ) };
Subroutine __ANON__: called CC=1 SCAR=0.0
51  
52 # Route
53 3 class_type RouteClass, { class => 'Google::Directions::Response::Route' };
54  
55 # Step
56 3 class_type StepClass, { class => 'Google::Directions::Response::Step' };
57  
58 # Leg
59 3 class_type LegClass, { class => 'Google::Directions::Response::Leg' };
60  
61 # Valid status codes
62 3 enum StatusCode, [ qw/OK NOT_FOUND ZERO_RESULTS MAX_WAYPOINTS_EXCEEDED INVALID_REQUEST
63 OVER_QUERY_LIMIT REQUEST_DENIED UNKNOWN_ERROR/ ];
64  
65 # Valid travel modes
66 3 enum TravelMode, [ qw/DRIVING WALKING BICYCLING/ ];
67  
68 # A number in the value key of a hashref
69 3 subtype ValueFromHashRef,
70 as Num;
71  
72 coerce ValueFromHashRef,
73 from HashRef,
74 84 ▶ via { $_->{value} };
Subroutine __ANON__: called CC=1 SCAR=0.0
75  
76 # Array of legs
77 # TODO: RCL 2012-02-19 neater/faster/more compact way of doing this?
78 subtype ArrayRefOfLegs,
79 as ArrayRef,
80 6 ▶ where {
Subroutine __ANON__: called CC=4 SCAR=13.9
81 6 my $arrayref = $_;
82 6 foreach( @{ $arrayref } ){
83 12 ▶ if( not ref( $_ ) or ref( $_ ) ne 'Google::Directions::Response::Leg' ){
Branch: 1 branch
BranchTrueFalseTotal
if (not ref $_ or ref $_ ne "Google::Directions::Response::Leg") 3 9 12
Condition66%2/3
not ref $_ or ref $_ ne "Google::Directions::Response::Leg"
l!l&&r!l&&!r
039
MC/DC50%1/2
not ref $_ or ref $_ ne "Google::Directions::Response::Leg"
not ref $_ ref $_ ne "Google::Directions::Response::Leg"
Truth table66%2/3
not(A) or B
A= not ref $_B= ref $_ ne "Google::Directions::Response::Leg"
ABresult
1X1
011
000
84 3 return 0;
85 }
86 }
87 3 return 1;
88 },
89 0 ▶ message { "Not all elements of the ArrayRef are Google::Direction::Response::Leg objects" };
Subroutine __ANON__: not called CC=1 SCAR=1.2
90  
91 coerce ArrayRefOfLegs,
92 from ArrayRef[HashRef],
93 3 ▶ via { [ map{ Google::Directions::Response::Leg->new( %{ $_ } ) } @{ $_ } ] };
Subroutine __ANON__: called CC=1 SCAR=0.0
94  
95  
96 # Array of routes
97 # TODO: RCL 2012-02-19 neater/faster/more compact way of doing this?
98 subtype ArrayRefOfRoutes,
99 as ArrayRef,
100 6 ▶ where {
Subroutine __ANON__: called CC=4 SCAR=13.9
101 6 my $arrayref = $_;
102 6 foreach( @{ $arrayref } ){
103 6 ▶ if( not ref( $_ ) or ref( $_ ) ne 'Google::Directions::Response::Route' ){
Branch: 1 branch
BranchTrueFalseTotal
if (not ref $_ or ref $_ ne "Google::Directions::Response::Route") 3 3 6
Condition66%2/3
not ref $_ or ref $_ ne "Google::Directions::Response::Route"
l!l&&r!l&&!r
033
MC/DC50%1/2
not ref $_ or ref $_ ne "Google::Directions::Response::Route"
not ref $_ ref $_ ne "Google::Directions::Response::Route"
Truth table66%2/3
not(A) or B
A= not ref $_B= ref $_ ne "Google::Directions::Response::Route"
ABresult
1X1
011
000
104 3 return 0;
105 }
106 }
107 3 return 1;
108 },
109 0 ▶ message { "Not all elements of the ArrayRef are Google::Direction::Response::Route objects" };
Subroutine __ANON__: not called CC=1 SCAR=1.2
110  
111 coerce ArrayRefOfRoutes,
112 from ArrayRef[HashRef],
113 3 ▶ via { [ map{ Google::Directions::Response::Route->new( %{ $_ } ) } @{ $_ } ] };
Subroutine __ANON__: called CC=1 SCAR=0.0
114  
115  
116 # Array of steps
117 # TODO: RCL 2012-02-19 neater/faster/more compact way of doing this?
118 subtype ArrayRefOfSteps,
119 as ArrayRef,
120 18 ▶ where {
Subroutine __ANON__: called CC=4 SCAR=13.9
121 18 my $arrayref = $_;
122 18 foreach( @{ $arrayref } ){
123 42 ▶ if( not ref( $_ ) or ref( $_ ) ne 'Google::Directions::Response::Step' ){
Branch: 1 branch
BranchTrueFalseTotal
if (not ref $_ or ref $_ ne "Google::Directions::Response::Step") 9 33 42
Condition66%2/3
not ref $_ or ref $_ ne "Google::Directions::Response::Step"
l!l&&r!l&&!r
0933
MC/DC50%1/2
not ref $_ or ref $_ ne "Google::Directions::Response::Step"
not ref $_ ref $_ ne "Google::Directions::Response::Step"
Truth table66%2/3
not(A) or B
A= not ref $_B= ref $_ ne "Google::Directions::Response::Step"
ABresult
1X1
011
000
124 9 return 0;
125 }
126 }
127 9 return 1;
128 },
129 0 ▶ message { "Not all elements of the ArrayRef are Google::Direction::Response::Step objects" };
Subroutine __ANON__: not called CC=1 SCAR=1.2
130  
131 coerce ArrayRefOfSteps,
132 from ArrayRef[HashRef],
133 9 ▶ via { [ map{ Google::Directions::Response::Step->new( %{ $_ } ) } @{ $_ } ] };
Subroutine __ANON__: called CC=1 SCAR=0.0
134  
135  
136 3 1;
137  
138 =head1 LICENSE AND COPYRIGHT
139  
140 Copyright 2012 Robin Clarke.
141  
142 This program is free software; you can redistribute it and/or modify it
143 under the terms of either: the GNU General Public License as published
144 by the Free Software Foundation; or the Artistic License.
145  
146 See http://dev.perl.org/licenses/ for more information.
147  
148 =cut
149  
« Client.pm ↑ Summary Response/Polyline.pm »