aboutsummaryrefslogtreecommitdiffstats
path: root/perllib/FixMyStreet/Cobrand.pm
diff options
context:
space:
mode:
authorMatthew Somerville <matthew@mysociety.org>2013-11-06 21:04:10 +0000
committerMatthew Somerville <matthew@mysociety.org>2013-11-07 17:01:02 +0000
commitab1625b7eaec127c727c236b98ba47a6643f4625 (patch)
tree239b736778b0b80f01b37222ab1039e984b4cae2 /perllib/FixMyStreet/Cobrand.pm
parenta44daf98c962a22f43408ab3990114ea156475c6 (diff)
If only one cobrand given, always use it.
If the ALLOWED_COBRANDS configuration variable only contains one entry (and also work if it's a string rather than a list), always use that cobrand, no matter what the hostname is. The example Vagrantfile no longer needs the configuration changes at all.
Diffstat (limited to 'perllib/FixMyStreet/Cobrand.pm')
-rw-r--r--perllib/FixMyStreet/Cobrand.pm15
1 files changed, 13 insertions, 2 deletions
diff --git a/perllib/FixMyStreet/Cobrand.pm b/perllib/FixMyStreet/Cobrand.pm
index 881183463..ff7d7f943 100644
--- a/perllib/FixMyStreet/Cobrand.pm
+++ b/perllib/FixMyStreet/Cobrand.pm
@@ -8,6 +8,7 @@ use warnings;
use FixMyStreet;
use Carp;
+use Moose;
use Module::Pluggable
sub_name => '_cobrands',
@@ -38,7 +39,10 @@ Simply returns the config variable (so this function can be overridden in test s
=cut
sub _get_allowed_cobrands {
- return FixMyStreet->config('ALLOWED_COBRANDS') || [];
+ my $allowed = FixMyStreet->config('ALLOWED_COBRANDS') || [];
+ # If the user has supplied a string, convert to an arrayref
+ $allowed = [ $allowed ] unless ref $allowed;
+ return $allowed;
}
=head2 available_cobrand_classes
@@ -92,7 +96,14 @@ sub get_class_for_host {
my $class = shift;
my $host = shift;
- foreach my $avail ( $class->available_cobrand_classes ) {
+ my @available = $class->available_cobrand_classes;
+
+ # If only one entry, always use it
+ return class($available[0]) if 1 == @available;
+
+ # If more than one entry, pick first whose regex (or
+ # name by default) matches hostname
+ foreach my $avail ( @available ) {
return class($avail) if $host =~ /$avail->{host}/;
}