| 1 | package WWW::EFA::Request; | ||||||||||||||||||||
| 2 | 2 | ▶ | use Moose; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 3 | 2 | ▶ | use HTTP::Request; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 4 | 2 | ▶ | use MooseX::Params::Validate; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 5 | 2 | ▶ | use Digest::SHA qw/sha256_hex/; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 6 | 2 | with 'WWW::EFA::Roles::Printable'; # provides to_string | |||||||||||||||||||
| 7 | |||||||||||||||||||||
| 8 | =head1 NAME | ||||||||||||||||||||
| 9 | |||||||||||||||||||||
| 10 | WWW::EFA::Request - A request which can be passed around, and built up | ||||||||||||||||||||
| 11 | |||||||||||||||||||||
| 12 | =head1 VERSION | ||||||||||||||||||||
| 13 | |||||||||||||||||||||
| 14 | Version 0.01 | ||||||||||||||||||||
| 15 | |||||||||||||||||||||
| 16 | =cut | ||||||||||||||||||||
| 17 | |||||||||||||||||||||
| 18 | 2 | our $VERSION = '0.01'; | |||||||||||||||||||
| 19 | |||||||||||||||||||||
| 20 | =head1 SYNOPSIS | ||||||||||||||||||||
| 21 | |||||||||||||||||||||
| 22 | URI request extended with some useful methods | ||||||||||||||||||||
| 23 | |||||||||||||||||||||
| 24 | use WWW::EFA::Location; | ||||||||||||||||||||
| 25 | |||||||||||||||||||||
| 26 | my $location = WWW::EFA::Location->new(); | ||||||||||||||||||||
| 27 | ... | ||||||||||||||||||||
| 28 | |||||||||||||||||||||
| 29 | =head1 ATTRIBUTES | ||||||||||||||||||||
| 30 | |||||||||||||||||||||
| 31 | TODO: RCL 2012-01-22 Documentation | ||||||||||||||||||||
| 32 | |||||||||||||||||||||
| 33 | =cut | ||||||||||||||||||||
| 34 | |||||||||||||||||||||
| 35 | has 'arguments' => ( | ||||||||||||||||||||
| 36 | is => 'rw', | ||||||||||||||||||||
| 37 | isa => 'HashRef', | ||||||||||||||||||||
| 38 | required => 1, | ||||||||||||||||||||
| 39 | 0 | ▶ | default => sub{ | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 40 | return | ||||||||||||||||||||
| 41 | { | ||||||||||||||||||||
| 42 | 0 | outputFormat => 'XML', | |||||||||||||||||||
| 43 | coordOutputFormat => 'WGS84', | ||||||||||||||||||||
| 44 | }; | ||||||||||||||||||||
| 45 | }, | ||||||||||||||||||||
| 46 | 2 | ); | |||||||||||||||||||
| 47 | |||||||||||||||||||||
| 48 | 2 | has 'base_url' => ( | |||||||||||||||||||
| 49 | is => 'ro', | ||||||||||||||||||||
| 50 | isa => 'Str', | ||||||||||||||||||||
| 51 | required => 1, | ||||||||||||||||||||
| 52 | ); | ||||||||||||||||||||
| 53 | |||||||||||||||||||||
| 54 | 2 | has 'can_accept_poid' => ( | |||||||||||||||||||
| 55 | is => 'ro', | ||||||||||||||||||||
| 56 | isa => 'Bool', | ||||||||||||||||||||
| 57 | required => 1, | ||||||||||||||||||||
| 58 | default => 1, | ||||||||||||||||||||
| 59 | ); | ||||||||||||||||||||
| 60 | 2 | has 'service' => ( | |||||||||||||||||||
| 61 | is => 'ro', | ||||||||||||||||||||
| 62 | isa => 'Str', | ||||||||||||||||||||
| 63 | required => 1, | ||||||||||||||||||||
| 64 | ); | ||||||||||||||||||||
| 65 | |||||||||||||||||||||
| 66 | =head1 METHODS | ||||||||||||||||||||
| 67 | |||||||||||||||||||||
| 68 | =head2 url | ||||||||||||||||||||
| 69 | |||||||||||||||||||||
| 70 | Returns $string | ||||||||||||||||||||
| 71 | |||||||||||||||||||||
| 72 | Get the URL for the request. Concatenation of base_url and service after common_params are set. | ||||||||||||||||||||
| 73 | |||||||||||||||||||||
| 74 | =cut | ||||||||||||||||||||
| 75 | 0 | ▶ | sub url { | ||||||||||||||||||
|
Subroutine
url: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 76 | 0 | my $self = shift; | |||||||||||||||||||
| 77 | 0 | $self->set_common_params(); | |||||||||||||||||||
| 78 | 0 | return $self->base_url . $self->service; | |||||||||||||||||||
| 79 | } | ||||||||||||||||||||
| 80 | |||||||||||||||||||||
| 81 | =head2 set_common_params | ||||||||||||||||||||
| 82 | |||||||||||||||||||||
| 83 | Set common parameters for the request | ||||||||||||||||||||
| 84 | |||||||||||||||||||||
| 85 | =cut | ||||||||||||||||||||
| 86 | 0 | ▶ | sub set_common_params { | ||||||||||||||||||
|
Subroutine
set_common_params: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||
| 87 | 0 | my $self = shift; | |||||||||||||||||||
| 88 | |||||||||||||||||||||
| 89 | # These are common to all services | ||||||||||||||||||||
| 90 | 0 | $self->set_argument( 'locationServerActive' , 1 ); | |||||||||||||||||||
| 91 | 0 | $self->set_argument( 'SpEncId' , '0' ); | |||||||||||||||||||
| 92 | |||||||||||||||||||||
| 93 | # Set service specific parameters | ||||||||||||||||||||
| 94 | 0 | my $service = $self->service; | |||||||||||||||||||
| 95 | 0 | ▶ | if( $service eq 'XSLT_TRIP_REQUEST2' ){ | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 96 | 0 | $self->set_argument( 'coordListOutputFormat' , 'STRING' ); | |||||||||||||||||||
| 97 | 0 | $self->set_argument( 'calcNumberOfTrips' , '4' ); | |||||||||||||||||||
| 98 | } | ||||||||||||||||||||
| 99 | } | ||||||||||||||||||||
| 100 | |||||||||||||||||||||
| 101 | =head2 add_location( $suffix, $location ) | ||||||||||||||||||||
| 102 | |||||||||||||||||||||
| 103 | Add a location to the request. | ||||||||||||||||||||
| 104 | |||||||||||||||||||||
| 105 | e.g. | ||||||||||||||||||||
| 106 | |||||||||||||||||||||
| 107 | |||||||||||||||||||||
| 108 | $request->add_location( 'origin', $location ); | ||||||||||||||||||||
| 109 | |||||||||||||||||||||
| 110 | $location is a L<WWW::EFA::Location> object | ||||||||||||||||||||
| 111 | |||||||||||||||||||||
| 112 | =cut | ||||||||||||||||||||
| 113 | 0 | ▶ | sub add_location { | ||||||||||||||||||
|
Subroutine
add_location: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||
| 114 | 0 | my $self = shift; | |||||||||||||||||||
| 115 | 0 | my ( $suffix, $location ) = pos_validated_list( | |||||||||||||||||||
| 116 | \@_, | ||||||||||||||||||||
| 117 | { isa => 'Str' }, | ||||||||||||||||||||
| 118 | { isa => 'WWW::EFA::Location' }, | ||||||||||||||||||||
| 119 | ); | ||||||||||||||||||||
| 120 | 0 | ▶ | if( $location->id ){ | ||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||
| 121 | 0 | $self->set_argument( 'type_' . $suffix, 'stop' ); | |||||||||||||||||||
| 122 | 0 | $self->set_argument( 'name_' . $suffix, $location->id ); | |||||||||||||||||||
| 123 | ▶ | } elsif ( $self->can_accept_poid and $location->poi_id ){ | |||||||||||||||||||
|
Condition0%0/3
$self->can_accept_poid and $location->poi_id
MC/DC0%0/2
$self->can_accept_poid and $location->poi_id
$self->can_accept_poid
$location->poi_id
Truth table0%0/3
A and B
A= $self->can_accept_poidB= $location->poi_id
| |||||||||||||||||||||
| 124 | 0 | $self->set_argument( 'type_' . $suffix, 'poiID' ); | |||||||||||||||||||
| 125 | 0 | $self->set_argument( 'name_' . $suffix, $location->poi_id ); | |||||||||||||||||||
| 126 | }elsif( $location->coordinates ){ | ||||||||||||||||||||
| 127 | 0 | $self->set_argument( 'type_' . $suffix, 'coord' ); | |||||||||||||||||||
| 128 | 0 | $self->set_argument( 'name_' . $suffix, | |||||||||||||||||||
| 129 | sprintf( "%.6f:%.6f:WGS84", | ||||||||||||||||||||
| 130 | $location->coordinates->longitude, | ||||||||||||||||||||
| 131 | $location->coordinates->latitude, | ||||||||||||||||||||
| 132 | ) ); | ||||||||||||||||||||
| 133 | }else{ | ||||||||||||||||||||
| 134 | 0 | die( "Incomplete Location\n" ); | |||||||||||||||||||
| 135 | } | ||||||||||||||||||||
| 136 | } | ||||||||||||||||||||
| 137 | |||||||||||||||||||||
| 138 | =head2 set_argument( $key, $value ) | ||||||||||||||||||||
| 139 | |||||||||||||||||||||
| 140 | Set an argument for the request. | ||||||||||||||||||||
| 141 | |||||||||||||||||||||
| 142 | e.g. | ||||||||||||||||||||
| 143 | |||||||||||||||||||||
| 144 | |||||||||||||||||||||
| 145 | $request->set_argument( 'inclMOT_0', 'on' ); | ||||||||||||||||||||
| 146 | |||||||||||||||||||||
| 147 | =cut | ||||||||||||||||||||
| 148 | 0 | ▶ | sub set_argument { | ||||||||||||||||||
|
Subroutine
set_argument: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 149 | 0 | my $self = shift; | |||||||||||||||||||
| 150 | 0 | my ( $key, $value ) = pos_validated_list( | |||||||||||||||||||
| 151 | \@_, | ||||||||||||||||||||
| 152 | { isa => 'Str' }, | ||||||||||||||||||||
| 153 | { isa => 'Str' }, | ||||||||||||||||||||
| 154 | ); | ||||||||||||||||||||
| 155 | 0 | $self->arguments->{ $key } = $value; | |||||||||||||||||||
| 156 | } | ||||||||||||||||||||
| 157 | |||||||||||||||||||||
| 158 | =head2 del_argument( $key ) | ||||||||||||||||||||
| 159 | |||||||||||||||||||||
| 160 | Added an argument you didn't mean to? Remove it here! | ||||||||||||||||||||
| 161 | |||||||||||||||||||||
| 162 | e.g. | ||||||||||||||||||||
| 163 | |||||||||||||||||||||
| 164 | |||||||||||||||||||||
| 165 | $request->del_argument( $key ); | ||||||||||||||||||||
| 166 | |||||||||||||||||||||
| 167 | =cut | ||||||||||||||||||||
| 168 | 0 | ▶ | sub del_argument { | ||||||||||||||||||
|
Subroutine
del_argument: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 169 | 0 | my $self = shift; | |||||||||||||||||||
| 170 | 0 | my ( $key ) = validated_list( | |||||||||||||||||||
| 171 | \@_, | ||||||||||||||||||||
| 172 | key => { isa => 'Str' }, | ||||||||||||||||||||
| 173 | ); | ||||||||||||||||||||
| 174 | 0 | delete( $self->arguments->{ $key } ); | |||||||||||||||||||
| 175 | } | ||||||||||||||||||||
| 176 | |||||||||||||||||||||
| 177 | =head2 digest | ||||||||||||||||||||
| 178 | |||||||||||||||||||||
| 179 | Returns $string | ||||||||||||||||||||
| 180 | |||||||||||||||||||||
| 181 | Generate a sha256_hex digest of this request. | ||||||||||||||||||||
| 182 | |||||||||||||||||||||
| 183 | =cut | ||||||||||||||||||||
| 184 | 0 | ▶ | sub digest { | ||||||||||||||||||
|
Subroutine
digest: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||
| 185 | 0 | my $self = shift; | |||||||||||||||||||
| 186 | 0 | my $string = $self->url . "\n"; | |||||||||||||||||||
| 187 | 0 | my %arguments = %{ $self->{arguments} }; | |||||||||||||||||||
| 188 | 0 | foreach( sort keys( %arguments ) ){ | |||||||||||||||||||
| 189 | 0 | $string .= "$_=$arguments{$_}\n"; | |||||||||||||||||||
| 190 | } | ||||||||||||||||||||
| 191 | 0 | return sha256_hex( $string ); | |||||||||||||||||||
| 192 | } | ||||||||||||||||||||
| 193 | |||||||||||||||||||||
| 194 | 2 | 1; | |||||||||||||||||||