aboutsummaryrefslogtreecommitdiffstats
path: root/perllib/FixMyStreet/Cobrand/Base.pm
diff options
context:
space:
mode:
authorMatthew Somerville <matthew@mysociety.org>2012-01-20 10:44:58 +0000
committerMatthew Somerville <matthew@mysociety.org>2012-01-20 10:44:58 +0000
commitce98919c502c6e34a5469b0ae75746011fbcb7b3 (patch)
tree71723ebbd67a7c83ba76d6c9fcaa35fcdeb93d10 /perllib/FixMyStreet/Cobrand/Base.pm
parent74f008e988ebc93380969f6761da8df527ff9940 (diff)
Remove some unused cobrand functions, start of a base class.
Diffstat (limited to 'perllib/FixMyStreet/Cobrand/Base.pm')
-rw-r--r--perllib/FixMyStreet/Cobrand/Base.pm70
1 files changed, 70 insertions, 0 deletions
diff --git a/perllib/FixMyStreet/Cobrand/Base.pm b/perllib/FixMyStreet/Cobrand/Base.pm
new file mode 100644
index 000000000..00b47d7da
--- /dev/null
+++ b/perllib/FixMyStreet/Cobrand/Base.pm
@@ -0,0 +1,70 @@
+package FixMyStreet::Cobrand::Base;
+
+use strict;
+use warnings;
+
+=head2 new
+
+ my $cobrand = $class->new;
+ my $cobrand = $class->new( { c => $c } );
+
+Create a new cobrand object, optionally setting the context.
+
+You probably shouldn't need to do this and should get the cobrand object via a
+method in L<FixMyStreet::Cobrand> instead.
+
+=cut
+
+sub new {
+ my $class = shift;
+ my $self = shift || {};
+ return bless $self, $class;
+}
+
+=head2 moniker
+
+ $moniker = $cobrand_class->moniker();
+
+Returns a moniker that can be used to identify this cobrand. By default this is
+the last part of the class name lowercased - eg 'F::C::SomeCobrand' becomes
+'somecobrand'.
+
+=cut
+
+sub moniker {
+ my $class = ref( $_[0] ) || $_[0]; # deal with object or class
+ my ($last_part) = $class =~ m{::(\w+)$};
+ $last_part = lc($last_part);
+ return '' if $last_part eq 'default';
+ return $last_part;
+}
+
+=head2 is_default
+
+ $bool = $cobrand->is_default();
+
+Returns true if this is the default cobrand, false otherwise.
+
+=cut
+
+sub is_default {
+ my $self = shift;
+ return $self->moniker eq '';
+}
+
+=head2 path_to_web_templates
+
+ $path = $cobrand->path_to_web_templates( );
+
+Returns the path to the templates for this cobrand - by default
+"templates/web/$moniker"
+
+=cut
+
+sub path_to_web_templates {
+ my $self = shift;
+ return FixMyStreet->path_to( 'templates/web', $self->moniker );
+}
+
+1;
+