aboutsummaryrefslogtreecommitdiffstats
path: root/perllib/FixMyStreet/Cobrand/Base.pm
blob: ea2b8f4100d39df74de6ef0bf8dd986bf5cf8315 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
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 $last_part;
}

=head2 asset_moniker

    $moniker = $cobrand_class->asset_moniker();

Same as moniker, except for the cobrand with the 'fixmystreet' moniker, when it
returns 'fixmystreet.com', as to avoid confusion that's where its assets are.

=cut

sub asset_moniker {
    my $self = shift;
    return $self->moniker eq 'fixmystreet' ? 'fixmystreet.com' : $self->moniker;
}

=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 'default';
}

=head2 call_hook

  $cobrand->call_hook(foo => 1, 2, 3); # calls $cobrand->foo(1, 2, 3) if it exists

=cut

sub call_hook {
    my ($self, $method_name, @args) = @_;
    my $method = $self->can($method_name) or return;
    return $self->$method(@args);
}

# NB: this Base class is for 'meta' features.  To add base methods for all cobrands,
# you may want to look at FMS::Cobrand::Default instead!

1;