blib/lib/Bot/Cobalt/IRC/Message/Public.pm

filter: Statementstmt 85.7% 12 / 14 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 5 / 5 Podpod n/a totaltotal 89.4% 17 / 19 SCAR 0.0
CC
1
Cov
86%
BEGIN
1.3
BEGIN
1.0
BEGIN
1.0
CRAP 1.0
« blib/lib/Bot/Cobalt/DB.pm ↑ Summary blib/lib/Bot/Cobalt/Plugin/Alarmclock.pm »
1 package Bot::Cobalt::IRC::Message::Public;
2 $Bot::Cobalt::IRC::Message::Public::VERSION = '0.021002';
3 1 ▶use v5.10;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use strictures 2;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use Scalar::Util 'blessed';
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 1 ▶use Bot::Cobalt;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use Bot::Cobalt::Common;
Subroutine BEGIN: called CC=1 SCAR=2.6
9  
10 require Bot::Cobalt::Core;
11  
12 use Moo;
13 extends 'Bot::Cobalt::IRC::Message';
14  
15 has cmd => (
16 lazy => 1,
17 is => 'rw',
18 isa => Any,
19 predicate => 'has_cmd',
20 builder => '_build_cmd',
21 );
22  
23 has highlight => (
24 lazy => 1,
25 is => 'rw',
26 isa => Bool,
27 predicate => 'has_highlight',
28 builder => '_build_highlight',
29 );
30  
31 has myself => (
32 lazy => 1,
33 is => 'rw',
34 isa => Str,
35 builder => sub {
36 my ($self) = @_;
37 my $irc;
38 return ''
39 unless Bot::Cobalt::Core->has_instance
40 and $irc = irc_object($self->context);
41 $irc->nick_name || ''
42 },
43 );
44  
45 after message => sub {
46 my ($self, $value) = @_;
47 return unless defined $value;
48
49 if ($self->has_highlight) {
50 $self->highlight( $self->_build_highlight );
51 }
52  
53 if ($self->has_cmd) {
54 $self->cmd( $self->_build_cmd );
55 }
56 };
57  
58 sub _build_highlight {
59 my ($self) = @_;
60 my $me = $self->myself || return 0;
61 my $txt = $self->stripped;
62 $txt =~ /^${me}[,:;!-]?\s+/i
63 }
64  
65 sub _build_cmd {
66 my ($self) = @_;
67  
68 my $cmdchar = Bot::Cobalt::Core->has_instance ?
69 (core->get_core_cfg->opts->{CmdChar} // '!') : '!'
70 ;
71  
72 if ($self->stripped =~ /^${cmdchar}([^\s]+)/) {
73 my $message = $self->message_array;
74 shift @$message;
75 # shift above modifies the ref, but intentionally hit trigger:
76 $self->message_array($message);
77 return lc($1)
78 }
79 undef
80 }
81  
82  
83 1;
84 __END__
« blib/lib/Bot/Cobalt/DB.pm ↑ Summary blib/lib/Bot/Cobalt/Plugin/Alarmclock.pm »