blib/lib/Bot/Cobalt/Timer.pm

filter: Statementstmt 26.0% 12 / 46 Branchbran 0.0% 0 / 16 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 22.2% 4 / 18 Podpod 75.0% 3 / 4 totaltotal 21.3% 19 / 89 CC 10 SCAR 17.1
CC
10
Cov
18%
__ANON__
12.0
_process_type
12.0
__ANON__
6.0
CRAP 5.6
« blib/lib/Bot/Cobalt/Logger/Output/File.pm ↑ Summary blib/lib/Bot/Cobalt/Core/Role/EasyAccessors.pm »
1 package Bot::Cobalt::Timer;
2 $Bot::Cobalt::Timer::VERSION = '0.021003';
3 2 ▶use strictures 2;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 2 ▶use Bot::Cobalt::Common ':types';
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 1 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 ## It's possible to pass in a different core.
11 ## (Allows timers to fire against different syndicators if needed)
12 has core => (
13 lazy => 1,
14 is => 'rw',
15 isa => HasMethods['send_event'],
16 0 ▶ builder => sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
17 0 require Bot::Cobalt::Core;
18 0 ▶ Bot::Cobalt::Core->instance
Branch: 1 branch
BranchTrueFalseTotal
"Bot::Cobalt::Core"->instance or die "Cannot find active Bot::Cobalt::Core instance" 0 0 0
19 || die "Cannot find active Bot::Cobalt::Core instance"
20 },
21 );
22  
23 ## May have a timer ID specified at construction for use by
24 ## timer pool managers; if not, creating IDs is up to them.
25 ## (See ::Core::Role::Timers)
26 has id => (
27 lazy => 1,
28 is => 'rw',
29 isa => Str,
30 predicate => 'has_id'
31 );
32  
33 ## 'at' is set regardless of whether delay()/at() is used
34 ## (or 0 if none is ever set)
35 has at => (
36 lazy => 1,
37 is => 'rw',
38 isa => Num,
39 0 ▶ builder => sub { 0 },
Subroutine _build_at: not called CC=1 SCAR=6.9
40 );
41  
42 has delay => (
43 lazy => 1,
44 is => 'rw',
45 isa => Num,
46 predicate => 'has_delay',
47 clearer => 'clear_delay',
48 0 ▶ builder => sub { 0 },
Subroutine _build_delay: not called CC=1 SCAR=6.9
49 0 ▶ trigger => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
50 0 my ($self, $value) = @_;
51 0 $self->at( time() + $value );
52 },
53 );
54  
55 has event => (
56 lazy => 1,
57 is => 'rw',
58 isa => Str,
59 predicate => 'has_event',
60 );
61  
62 has args => (
63 lazy => 1,
64 is => 'rw',
65 isa => ArrayObj,
66 coerce => 1,
67 0 ▶ builder => sub { [] },
Subroutine _build_args: not called CC=1 SCAR=6.9
68 );
69  
70 has alias => (
71 is => 'rw',
72 isa => Str,
73 0 ▶ builder => sub { scalar caller },
Subroutine __ANON__: not called CC=1 SCAR=6.9
74 );
75  
76 has context => (
77 lazy => 1,
78 is => 'rw',
79 isa => Str,
80 predicate => 'has_context',
81 0 ▶ builder => sub { 'Main' },
Subroutine _build_context: not called CC=1 SCAR=6.9
82 );
83  
84 has text => (
85 lazy => 1,
86 is => 'rw',
87 isa => Str,
88 predicate => 'has_text'
89 );
90  
91 has target => (
92 lazy => 1,
93 is => 'rw',
94 isa => Str,
95 predicate => 'has_target'
96 );
97  
98 has type => (
99 lazy => 1,
100 is => 'rw',
101 isa => Str,
102 0 ▶ builder => sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
103 0 my ($self) = @_;
104 # best guess:
105 0 ▶ $self->has_context && $self->has_target ? 'msg' : 'event'
Branch: 1 branch
BranchTrueFalseTotal
$self->has_context && $self->has_target ? : 0 0 0
Condition0%0/3
$self->has_context and $self->has_target
!ll&&!rl&&r
000
MC/DC0%0/2
$self->has_context and $self->has_target
$self->has_context $self->has_target
Truth table0%0/3
A and B
A= $self->has_contextB= $self->has_target
ABresult
0X0
100
111
106 },
107 0 ▶ coerce => sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
108 0 ▶ $_[0] =~ /message|privmsg/i ? 'msg' : lc($_[0]) ;
Branch: 1 branch
BranchTrueFalseTotal
$_[0] =~ /message|privmsg/i ? : 0 0 0
109 },
110 );
111  
112  
113 0 ▶sub _process_type {
Subroutine _process_type: not called CC=3 SCAR=24.8
114 0 my ($self) = @_;
115 ## If this is a special type, set up event and args.
116 0 my $type = lc $self->type;
117  
118 0 ▶ if (grep {; $_ eq $type } qw/msg message privmsg action/) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep {$_ eq $type;} "msg", "message", "privmsg", "action") 0 0 0
119 0 ▶ my $ev_name = $type eq 'action' ?
Branch: 1 branch
BranchTrueFalseTotal
$type eq 'action' ? : 0 0 0
120 'action' : 'message' ;
121 0 $self->event( $ev_name );
122  
123 0 my @ev_args = ( $self->context, $self->target, $self->text );
124 0 $self->args( \@ev_args );
125 }
126  
127 1
128 0 }
129  
130 0 ▶sub is_ready {
Subroutine is_ready: not called CC=2 SCAR=17.9
Pod documented
131 0 my ($self) = @_;
132 0 ▶ $self->at <= time ? 1 : ()
Branch: 1 branch
BranchTrueFalseTotal
$self->at <= time ? : 0 0 0
133 }
134  
135 0 ▶sub execute {
Subroutine execute: not called CC=2 SCAR=17.9
Pod documented
136 0 my ($self) = @_;
137 0 $self->_process_type;
138  
139 0 ▶ unless ( $self->event ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->event) 0 0 0
140 0 carp "timer execute called but no event specified";
141 return
142 0 }
143  
144 0 my $args = $self->args;
145 0 $self->core->send_event( $self->event, @$args );
146 0 1
147 }
148  
149 0 ▶sub execute_if_ready { execute_ready(@_) }
Subroutine execute_if_ready: not called CC=1 SCAR=6.9
Pod documented
150 0 ▶sub execute_ready {
Subroutine execute_ready: not called CC=2 SCAR=17.9
Pod undocumented
151 0 my ($self) = @_;
152 0 ▶ $self->is_ready ? $self->execute : ()
Branch: 1 branch
BranchTrueFalseTotal
$self->is_ready ? : 0 0 0
153 }
154  
155  
156 1;
157 __END__
« blib/lib/Bot/Cobalt/Logger/Output/File.pm ↑ Summary blib/lib/Bot/Cobalt/Core/Role/EasyAccessors.pm »