aboutsummaryrefslogtreecommitdiffstats
path: root/perllib/FixMyStreet/FakeQ.pm
diff options
context:
space:
mode:
Diffstat (limited to 'perllib/FixMyStreet/FakeQ.pm')
-rw-r--r--perllib/FixMyStreet/FakeQ.pm60
1 files changed, 60 insertions, 0 deletions
diff --git a/perllib/FixMyStreet/FakeQ.pm b/perllib/FixMyStreet/FakeQ.pm
new file mode 100644
index 000000000..19f5ab32b
--- /dev/null
+++ b/perllib/FixMyStreet/FakeQ.pm
@@ -0,0 +1,60 @@
+package FixMyStreet::FakeQ;
+
+use strict;
+use warnings;
+use Carp;
+
+=head1 NAME
+
+FixMyStreet::FakeQ - adaptor object to ease code transition
+
+=head1 DESCRIPTION
+
+The old code uses '$q' everywhere - partly to passaround which cobrand is in
+use, partly to give access to the request query parameters and partly as a
+scratch pad.
+
+This object lets us fake this behaviour in a structured way so that the new
+Catalyst based code can call the old CGI code with no need for changes.
+
+Eventually it will be phased out.
+
+=head1 METHODS
+
+=head2 new
+
+ $fake_q = FixMyStreet::FakeQ->new( $args );
+
+Create a new FakeQ object. Checks that 'site' argument is present and corrects
+it if needed.
+
+=cut
+
+sub new {
+ my $class = shift;
+ my $args = shift || {};
+
+ croak "required argument 'site' missing" unless $args->{site};
+ $args->{site} = 'fixmystreet' if $args->{site} eq 'default';
+
+ $args->{params} ||= {};
+
+ return bless $args, $class;
+}
+
+=head2 param
+
+ $val = $fake_q->param( 'key' );
+
+Behaves much like CGI's ->param. Returns value if found, or undef if not.
+
+=cut
+
+sub param {
+ my $self = shift;
+ my $key = shift;
+
+ return $self->{params}->{$key};
+}
+
+1;