File Coverage

blib/lib/Bot/Cobalt/IRC/Event.pm
Criterion Covered Total %
statement 6 6 100.0
branch n/a
condition n/a
subroutine 2 2 100.0
pod n/a
total 8 8 100.0


line stmt bran cond sub pod time code
1             package Bot::Cobalt::IRC::Event;
2             $Bot::Cobalt::IRC::Event::VERSION = '0.021001';
3             ## Base class for IRC events.
4              
5 11     11   16861 use Bot::Cobalt::Common;
  11         13  
  11         53  
6              
7 11     11   484 use Moo;
  11         5765  
  11         47  
8              
9             has context => (
10             required => 1,
11             is => 'rw',
12             isa => Str,
13             );
14              
15             has src => (
16             required => 1,
17             is => 'rw',
18             isa => Str,
19             trigger => sub {
20             ## If 'src' changes, reset nick/user/host as-needed.
21             my ($self, $value) = @_;
22            
23             my @types = qw/nick user host/;
24             my %pieces;
25             @pieces{@types} = parse_user($value);
26            
27             for my $type (@types) {
28             my $meth = '_set_src_'.$type;
29             my $hasmeth = 'has_src_'.$type;
30             $self->$meth($pieces{$type}) if $self->$hasmeth;
31             }
32             }
33             );
34              
35             has src_nick => (
36             lazy => 1,
37             is => 'rwp',
38             predicate => 'has_src_nick',
39             default => sub { (parse_user($_[0]->src))[0] },
40             );
41              
42             has src_user => (
43             lazy => 1,
44             is => 'rwp',
45             predicate => 'has_src_user',
46             default => sub { (parse_user($_[0]->src))[1] },
47             );
48              
49             has src_host => (
50             lazy => 1,
51             is => 'rwp',
52             predicate => 'has_src_host',
53             default => sub { (parse_user($_[0]->src))[2] },
54             );
55              
56             1;
57             __END__