| 1 | package Bot::Cobalt::Core::ContextMeta::Ignore; | ||
| 2 | $Bot::Cobalt::Core::ContextMeta::Ignore::VERSION = '0.021002'; | ||
| 3 | 1 | ▶ | use strictures 2; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 4 | 1 | ▶ | use Carp; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 5 | |||
| 6 | 1 | ▶ | use IRC::Utils 'normalize_mask'; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 7 | 1 | ▶ | use Bot::Cobalt::Common ':types'; |
|
Subroutine
BEGIN: called CC=1 SCAR=2.6
| |||
| 8 | |||
| 9 | |||
| 10 | use Moo; | ||
| 11 | extends 'Bot::Cobalt::Core::ContextMeta'; | ||
| 12 | |||
| 13 | |||
| 14 | around add => sub { | ||
| 15 | my $orig = shift; | ||
| 16 | my ($self, $context, $mask, $reason, $addedby) = @_; | ||
| 17 | |||
| 18 | my ($pkg, $line) = (caller)[0,2]; | ||
| 19 | |||
| 20 | confess "Missing arguments in ignore add()" | ||
| 21 | unless defined $context and defined $mask; | ||
| 22 | |||
| 23 | $mask = normalize_mask($mask); | ||
| 24 | $addedby = $pkg unless defined $addedby; | ||
| 25 | $reason = "Added by $pkg" unless defined $reason; | ||
| 26 | |||
| 27 | my $meta = +{ | ||
| 28 | AddedBy => $addedby, | ||
| 29 | Reason => $reason, | ||
| 30 | }; | ||
| 31 | |||
| 32 | $self->$orig($context, $mask, $meta) | ||
| 33 | }; | ||
| 34 | |||
| 35 | sub reason { | ||
| 36 | my ($self, $context, $mask) = @_; | ||
| 37 | |||
| 38 | return unless exists $self->_list->{$context} | ||
| 39 | and exists $self->_list->{$context}->{$mask}; | ||
| 40 | |||
| 41 | $self->_list->{$context}->{$mask}->{Reason} | ||
| 42 | } | ||
| 43 | |||
| 44 | sub addedby { | ||
| 45 | my ($self, $context, $mask) = @_; | ||
| 46 | |||
| 47 | return unless exists $self->_list->{$context} | ||
| 48 | and exists $self->_list->{$context}->{$mask}; | ||
| 49 | |||
| 50 | $self->_list->{$context}->{$mask}->{AddedBy} | ||
| 51 | } | ||
| 52 | |||
| 53 | 1; | ||
| 54 | __END__ | ||