File Coverage

blib/lib/Bot/Cobalt/Core/ContextMeta/Ignore.pm
Criterion Covered Total %
statement 21 21 100.0
branch 2 4 50.0
condition 2 6 33.3
subroutine 7 7 100.0
pod 2 2 100.0
total 34 40 85.0


line stmt bran cond sub pod time code
1             package Bot::Cobalt::Core::ContextMeta::Ignore;
2             $Bot::Cobalt::Core::ContextMeta::Ignore::VERSION = '0.021003';
3 6     6   13997 use strictures 2;
  6         1184  
  6         209  
4 6     6   894 use Carp;
  6         10  
  6         326  
5              
6 6     6   519 use IRC::Utils 'normalize_mask';
  6         14591  
  6         260  
7 6     6   369 use Bot::Cobalt::Common ':types';
  6         8  
  6         33  
8              
9              
10 6     6   468 use Moo;
  6         6343  
  6         30  
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 1     1 1 273 my ($self, $context, $mask) = @_;
37            
38             return unless exists $self->_list->{$context}
39 1 50 33     20 and exists $self->_list->{$context}->{$mask};
40              
41             $self->_list->{$context}->{$mask}->{Reason}
42 1         34 }
43              
44             sub addedby {
45 1     1 1 272 my ($self, $context, $mask) = @_;
46              
47             return unless exists $self->_list->{$context}
48 1 50 33     19 and exists $self->_list->{$context}->{$mask};
49            
50             $self->_list->{$context}->{$mask}->{AddedBy}
51 1         34 }
52              
53             1;
54             __END__