aboutsummaryrefslogtreecommitdiffstats
path: root/perllib/FixMyStreet/Cobrand.pm
diff options
context:
space:
mode:
authorMatthew Somerville <matthew@mysociety.org>2012-08-17 15:24:35 +0100
committerMatthew Somerville <matthew@mysociety.org>2012-08-17 15:24:35 +0100
commit262b862427ae7523aada0af8f705925bd6891961 (patch)
treeab6398834e3994c7806a31e751922edfe434e568 /perllib/FixMyStreet/Cobrand.pm
parent0a9dd827dd0d36cc56a7e8011ce58efe215e4237 (diff)
Allow cobrands to be given in ALLOWED_COBRANDS that don't have a Cobrand .pm file. Just assume there would be a blank file with the right name that inherits from Default.pm.
Diffstat (limited to 'perllib/FixMyStreet/Cobrand.pm')
-rw-r--r--perllib/FixMyStreet/Cobrand.pm26
1 files changed, 20 insertions, 6 deletions
diff --git a/perllib/FixMyStreet/Cobrand.pm b/perllib/FixMyStreet/Cobrand.pm
index d694e4bdb..881183463 100644
--- a/perllib/FixMyStreet/Cobrand.pm
+++ b/perllib/FixMyStreet/Cobrand.pm
@@ -46,9 +46,9 @@ sub _get_allowed_cobrands {
@available_cobrand_classes =
FixMyStreet::Cobrand->available_cobrand_classes();
-Return an array of all the classes that were found and that have monikers
-that match the values from get_allowed_cobrands, in the order of
-get_allowed_cobrands.
+Return an array of all the classes from get_allowed_cobrands, in
+the order of get_allowed_cobrands, with added class information
+for those that have found classes.
=cut
@@ -58,7 +58,7 @@ sub available_cobrand_classes {
my %all = map { $_->moniker => $_ } @ALL_COBRAND_CLASSES;
my @avail;
foreach (@{ $class->get_allowed_cobrands }) {
- next unless $all{$_->{moniker}};
+ #next unless $all{$_->{moniker}};
$_->{class} = $all{$_->{moniker}};
push @avail, $_;
}
@@ -66,6 +66,20 @@ sub available_cobrand_classes {
return @avail;
}
+=head2 class
+
+=cut
+
+sub class {
+ my $avail = shift;
+ return $avail->{class} if $avail->{class};
+ my $moniker = $avail->{moniker};
+ Class::MOP::Class->create("FixMyStreet::Cobrand::$moniker" => (
+ superclasses => [ 'FixMyStreet::Cobrand::Default' ],
+ ));
+ return "FixMyStreet::Cobrand::$moniker";
+}
+
=head2 get_class_for_host
$cobrand_class = FixMyStreet::Cobrand->get_class_for_host( $host );
@@ -79,7 +93,7 @@ sub get_class_for_host {
my $host = shift;
foreach my $avail ( $class->available_cobrand_classes ) {
- return $avail->{class} if $host =~ /$avail->{host}/;
+ return class($avail) if $host =~ /$avail->{host}/;
}
# if none match then use the default
@@ -99,7 +113,7 @@ sub get_class_for_moniker {
my $moniker = shift;
foreach my $avail ( $class->available_cobrand_classes ) {
- return $avail->{class} if $moniker eq $avail->{moniker};
+ return class($avail) if $moniker eq $avail->{moniker};
}
# Special case for old blank cobrand entries in fixmystreet.com.