diff options
author | Matthew Somerville <matthew@mysociety.org> | 2015-07-06 17:35:35 +0100 |
---|---|---|
committer | Matthew Somerville <matthew@mysociety.org> | 2015-07-07 14:13:18 +0100 |
commit | a978c0a1ad216f7004ef88b8a58b9731242155dc (patch) | |
tree | 58ec3daece503b314bb1dfe54ab2d0c0e80cb24e /perllib/FixMyStreet/App/Controller/Around.pm | |
parent | beb7e1f345ace940c542d93768ec44bfd6f5dc21 (diff) |
Factor out all uses of param()/params.
Use a central get_param and get_param_list functions dependent on
whether we're after a scalar or a list (almost always a scalar). This
prevents any possibility of confusion where param() could return a list,
or params->{} an arrayref.
Diffstat (limited to 'perllib/FixMyStreet/App/Controller/Around.pm')
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Around.pm | 33 |
1 files changed, 16 insertions, 17 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Around.pm b/perllib/FixMyStreet/App/Controller/Around.pm index 5bfe1ada2..723684793 100644 --- a/perllib/FixMyStreet/App/Controller/Around.pm +++ b/perllib/FixMyStreet/App/Controller/Around.pm @@ -41,7 +41,7 @@ sub around_index : Path : Args(0) { my $ret = $c->forward('/location/determine_location_from_coords') || $c->forward('/location/determine_location_from_pc'); unless ($ret) { - return $c->res->redirect('/') unless $c->req->param('pc') || $partial_report; + return $c->res->redirect('/') unless $c->get_param('pc') || $partial_report; return; } @@ -78,13 +78,12 @@ Handle coord systems that are no longer in use. sub redirect_en_or_xy_to_latlon : Private { my ( $self, $c ) = @_; - my $req = $c->req; # check for x,y or e,n requests - my $x = $req->param('x'); - my $y = $req->param('y'); - my $e = $req->param('e'); - my $n = $req->param('n'); + my $x = $c->get_param('x'); + my $y = $c->get_param('y'); + my $e = $c->get_param('e'); + my $n = $c->get_param('n'); # lat and lon - fill in below if we need to my ( $lat, $lon ); @@ -118,7 +117,7 @@ token to stash and return report. Otherwise return false. sub load_partial : Private { my ( $self, $c ) = @_; - my $partial = scalar $c->req->param('partial') + my $partial = $c->get_param('partial') || return; # is it in the database @@ -161,7 +160,7 @@ sub display_location : Private { my $longitude = $c->stash->{longitude}; # Deal with pin hiding/age - my $all_pins = $c->req->param('all_pins') ? 1 : undef; + my $all_pins = $c->get_param('all_pins') ? 1 : undef; $c->stash->{all_pins} = $all_pins; my $interval = $all_pins ? undef : $c->cobrand->on_map_default_max_pin_age; @@ -182,7 +181,7 @@ sub display_location : Private { # create a list of all the pins my @pins; - unless ($c->req->param('no_pins') || $c->cobrand->moniker eq 'emptyhomes') { + unless ($c->get_param('no_pins') || $c->cobrand->moniker eq 'emptyhomes') { @pins = map { # Here we might have a DB::Problem or a DB::Nearby, we always want the problem. my $p = (ref $_ eq 'FixMyStreet::App::Model::DB::Nearby') ? $_->problem : $_; @@ -258,7 +257,7 @@ sub check_and_stash_category : Private { $c->stash->{filter_categories} = \@categories; - my $category = $c->req->param('filter_category'); + my $category = $c->get_param('filter_category'); my %categories_mapped = map { $_ => 1 } @categories; if ( defined $category && $categories_mapped{$category} ) { $c->stash->{filter_category} = $category; @@ -278,7 +277,7 @@ sub ajax : Path('/ajax') { $c->res->content_type('application/json; charset=utf-8'); - unless ( $c->req->param('bbox') ) { + unless ( $c->get_param('bbox') ) { $c->res->status(404); $c->res->body(''); return; @@ -288,7 +287,7 @@ sub ajax : Path('/ajax') { $c->res->header( 'Cache_Control' => 'max-age=0' ); # how far back should we go? - my $all_pins = $c->req->param('all_pins') ? 1 : undef; + my $all_pins = $c->get_param('all_pins') ? 1 : undef; my $interval = $all_pins ? undef : $c->cobrand->on_map_default_max_pin_age; # Need to be the class that can handle it @@ -320,7 +319,7 @@ sub ajax : Path('/ajax') { sub location_autocomplete : Path('/ajax/geocode') { my ( $self, $c ) = @_; $c->res->content_type('application/json; charset=utf-8'); - unless ( $c->req->param('term') ) { + unless ( $c->get_param('term') ) { $c->res->status(404); $c->res->body(''); return; @@ -328,26 +327,26 @@ sub location_autocomplete : Path('/ajax/geocode') { # we want the match even if there's no ambiguity, so recommendation doesn't # disappear when it's the last choice being offered in the autocomplete. $c->stash->{allow_single_geocode_match_strings} = 1; - return $self->_geocode( $c, $c->req->param('term') ); + return $self->_geocode( $c, $c->get_param('term') ); } sub location_lookup : Path('/ajax/lookup_location') { my ( $self, $c ) = @_; $c->res->content_type('application/json; charset=utf-8'); - unless ( $c->req->param('term') ) { + unless ( $c->get_param('term') ) { $c->res->status(404); $c->res->body(''); return; } - return $self->_geocode( $c, $c->req->param('term') ); + return $self->_geocode( $c, $c->get_param('term') ); } sub _geocode : Private { my ( $self, $c, $term ) = @_; my ( $lat, $long, $suggestions ) = - FixMyStreet::Geocode::lookup( $c->req->param('term'), $c ); + FixMyStreet::Geocode::lookup( $c->get_param('term'), $c ); my ($response, @addresses, @locations); |