ChatBots/MojoPlugin.pm

filter: Statementstmt 97.3% 37 / 38 Branchbran 50.0% 1 / 2 Conditioncond 61.5% 8 / 13 MC/DCmcdc 25.0% 2 / 8 Subroutinesub 100% 8 / 8 Podpod 100% 3 / 3 totaltotal 81.9% 59 / 72 CC 8 SCAR 10.8
CC
8
Cov
87%
register
5.0
add_instance
3.3
helper_name
2.0
CRAP 2.9
« ChatBots/Role/Poller.pm ↑ Summary ChatBots/Weak.pm »
1 package Bot::ChatBots::MojoPlugin;
2 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 { our $VERSION = '0.014'; }
5  
6 2 ▶use Bot::ChatBots::Utils qw< load_module >;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 2 ▶use Mojo::Base 'Mojolicious::Plugin';
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 2 has [qw< app instances >];
11  
12 3 ▶sub helper_name {
Subroutine helper_name: called CC=2 SCAR=7.0
Pod documented
13 3 my $self = shift;
14 3 ▶ (my $name = lc(ref $self || $self)) =~ s{.*::}{}mxs;
Condition66%2/3
ref $self || $self
l!l&&r!l&&!r
210
MC/DC0%0/2
ref $self || $self
ref $self $self
Truth table66%2/3
A || B
A= ref $selfB= $self
ABresult
1X1
011
000
15 3 return "chatbots.$name";
16 }
17  
18 1 ▶sub add_instance {
Subroutine add_instance: called CC=3 SCAR=11.8
Pod documented
19 1 my $self = shift;
20 1 my $module = load_module(shift, ref $self);
21 0 ▶ my @args = (@_ && ref($_[0])) ? %{$_[0]} : @_;
Branch: 1 branch
BranchTrueFalseTotal
@_ && ref $_[0] ? : 0 1 1
Condition33%1/3
@_ and ref $_[0]
!ll&&!rl&&r
010
MC/DC0%0/2
@_ and ref $_[0]
@_ ref $_[0]
Truth table33%1/3
A and B
A= @_B= ref $_[0]
ABresult
0X0
100
111
22 1 my $instance = $module->new(@args, app => $self->app);
23 1 push @{$self->instances}, $instance;
24 1 return $instance;
25 } ## end sub add_instance
26  
27 2 ▶sub register {
Subroutine register: called CC=5 SCAR=16.2
Pod documented
28 2 my ($self, $app, $conf) = @_;
29 2 ▶ $conf //= {};
Condition100%2/2
$conf //= {}
l!l
11
MC/DC100%1/1
$conf //= {}
$conf
Truth table100%2/2
A
A= $conf
Aresult
11
00
30 2 ▶ my $helper_name = $conf->{helper_name} // $self->helper_name;
Condition33%1/3
$conf->{"helper_name"} // $self->helper_name
l!l&&r!l&&!r
020
MC/DC0%0/2
$conf->{"helper_name"} // $self->helper_name
$conf->{"helper_name"} $self->helper_name
Truth table33%1/3
A // B
A= $conf->{"helper_name"}B= $self->helper_name
ABresult
1X1
011
000
31  
32 # initialize object
33 2 $self->app($app);
34 2 $self->instances([]);
35  
36 # add helper to be usable
37 2 ▶ $app->helper($helper_name => sub { return $self });
Subroutine __ANON__: called CC=1 SCAR=0.0
38  
39 # initialize with instances passed on the fly
40 2 ▶ $self->add_instance(@$_) for @{$conf->{instances} // []};
Condition100%2/2
$conf->{"instances"} // []
l!l
11
MC/DC100%1/1
$conf->{"instances"} // []
$conf->{"instances"}
Truth table100%2/2
A
A= $conf->{"instances"}
Aresult
11
00
41  
42 2 $app->log->debug("helper $helper_name registered");
43  
44 2 return $self;
45 } ## end sub register
46  
47 2 1;
48 __END__
« ChatBots/Role/Poller.pm ↑ Summary ChatBots/Weak.pm »