| 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
MC/DC0%0/2
ref $self || $self
ref $self
$self
Truth table66%2/3
A || B
A= ref $selfB= $self
| |||||||||||||||||||||||||||||
| 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
Condition33%1/3
@_ and ref $_[0]
MC/DC0%0/2
@_ and ref $_[0]
@_
ref $_[0]
Truth table33%1/3
A and B
A= @_B= ref $_[0]
| |||||||||||||||||||||||||||||
| 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 //= {}
MC/DC100%1/1
$conf //= {}
$conf
Truth table100%2/2
A
A= $conf
| |||||||||||||||||||||||||||||
| 30 | 2 | ▶ | my $helper_name = $conf->{helper_name} // $self->helper_name; | ||||||||||||||||||||||||||
|
Condition33%1/3
$conf->{"helper_name"} // $self->helper_name
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
| |||||||||||||||||||||||||||||
| 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"} // []
MC/DC100%1/1
$conf->{"instances"} // []
$conf->{"instances"}
Truth table100%2/2
A
A= $conf->{"instances"}
| |||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||