aboutsummaryrefslogtreecommitdiffstats
path: root/perllib/Cobrand.pm
diff options
context:
space:
mode:
Diffstat (limited to 'perllib/Cobrand.pm')
-rw-r--r--perllib/Cobrand.pm25
1 files changed, 15 insertions, 10 deletions
diff --git a/perllib/Cobrand.pm b/perllib/Cobrand.pm
index 4e3638881..ec439f7b4 100644
--- a/perllib/Cobrand.pm
+++ b/perllib/Cobrand.pm
@@ -7,7 +7,7 @@
# Copyright (c) 2009 UK Citizens Online Democracy. All rights reserved.
# Email: louise@mysociety.org. WWW: http://www.mysociety.org
#
-# $Id: Cobrand.pm,v 1.8 2009-09-02 08:55:59 louise Exp $
+# $Id: Cobrand.pm,v 1.9 2009-09-02 11:35:18 matthew Exp $
package Cobrand;
use strict;
@@ -15,7 +15,7 @@ use Carp;
=item get_allowed_cobrands
-Return an array of allowed cobrand subdomains
+Return an array reference of allowed cobrand subdomains
=cut
sub get_allowed_cobrands{
@@ -30,16 +30,21 @@ Given a query that has the name of a site set, return a handle to the Util modul
site, if one exists, or zero if not.
=cut
-sub cobrand_handle{
+sub cobrand_handle {
my $cobrand = shift;
+
+ our %handles;
+
+ # Once we have a handle defined, return it.
+ return $handles{$cobrand} if defined $handles{$cobrand};
+
my $cobrand_class = ucfirst($cobrand);
my $class = "Cobrands::" . $cobrand_class . "::Util";
eval "use $class";
- my $handle;
- eval{ $handle = $class->new };
- return 0 if $@;
- return $handle;
+ eval{ $handles{$cobrand} = $class->new };
+ $handles{$cobrand} = 0 if $@;
+ return $handles{$cobrand};
}
@@ -52,7 +57,7 @@ sub cobrand_page{
my $q = shift;
my $cobrand = $q->{site};
my $handle = cobrand_handle($cobrand);
- return 0 if $handle == 0;
+ return 0 unless $handle;
return $handle->page($q);
}
@@ -69,7 +74,7 @@ sub set_site_restriction{
my $site_id = 0;
my $cobrand = $q->{site};
my $handle = cobrand_handle($cobrand);
- return ($site_restriction, $site_id) if $handle == 0;
+ return ($site_restriction, $site_id) unless $handle;
return $handle->site_restriction($q);
}
@@ -81,7 +86,7 @@ Set the language and domain of the site based on the cobrand and host
sub set_lang_and_domain{
my ($cobrand, $lang) = @_;
my $handle = cobrand_handle($cobrand);
- if ($handle != 0){
+ if ($handle){
$handle->set_lang_and_domain($lang);
}
}