| 1 | package Bot::Backbone::Service::Role::SendPolicy; | ||||||||||||||||||||||||||||||||
| 2 | 4 | $Bot::Backbone::Service::Role::SendPolicy::VERSION = '0.161950'; | |||||||||||||||||||||||||||||||
| 3 | 4 | ▶ | use v5.10; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 4 | 4 | ▶ | use Moose::Role; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||
| 6 | 4 | with 'Bot::Backbone::Service::Role::Sender'; | |||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||
| 8 | # ABSTRACT: Provides send policy framework to a service | ||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||
| 11 | 4 | has send_policy_name => ( | |||||||||||||||||||||||||||||||
| 12 | is => 'ro', | ||||||||||||||||||||||||||||||||
| 13 | isa => 'Str', | ||||||||||||||||||||||||||||||||
| 14 | init_arg => 'send_policy', | ||||||||||||||||||||||||||||||||
| 15 | predicate => 'has_send_policy', | ||||||||||||||||||||||||||||||||
| 16 | ); | ||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||
| 19 | 4 | has send_policy => ( | |||||||||||||||||||||||||||||||
| 20 | is => 'ro', | ||||||||||||||||||||||||||||||||
| 21 | does => 'Bot::Backbone::SendPolicy', | ||||||||||||||||||||||||||||||||
| 22 | init_arg => undef, | ||||||||||||||||||||||||||||||||
| 23 | lazy_build => 1, | ||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||
| 25 | # lazy_build implies (predicate => has_send_policy) | ||||||||||||||||||||||||||||||||
| 26 | predicate => 'has_setup_the_send_policy', | ||||||||||||||||||||||||||||||||
| 27 | ); | ||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||
| 29 | 3 | ▶ | sub _build_send_policy { | ||||||||||||||||||||||||||||||
|
Subroutine
_build_send_policy: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||||||
| 30 | 3 | my $self = shift; | |||||||||||||||||||||||||||||||
| 31 | 3 | my $send_policy = $self->bot->meta->send_policies->{ $self->send_policy_name }; | |||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||
| 33 | 3 | ▶ | die "no such send policy as ", $self->send_policy_name, "\n" | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 34 | unless defined $send_policy; | ||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||
| 36 | 3 | Bot::Backbone::SendPolicy::Aggregate->new( | |||||||||||||||||||||||||||||||
| 37 | bot => $self->bot, | ||||||||||||||||||||||||||||||||
| 38 | config => $send_policy, | ||||||||||||||||||||||||||||||||
| 39 | ); | ||||||||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||
| 43 | 4 | requires qw( send_message ); | |||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||
| 45 | 900 | ▶ | around send_message => sub { | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=9 SCAR=22.4
| |||||||||||||||||||||||||||||||||
| 46 | 900 | my ($next, $self, $params) = @_; | |||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||
| 48 | 900 | ▶ | my $send_policy_result = $params->{send_policy_result} // { allow => 1 }; | ||||||||||||||||||||||||||||||
|
Condition50%1/2
$params->{"send_policy_result"} // {"allow", 1}
MC/DC0%0/1
$params->{"send_policy_result"} // {"allow", 1}
$params->{"send_policy_result"}
Truth table50%1/2
A
A= $params->{"send_policy_result"}
| |||||||||||||||||||||||||||||||||
| 49 | 900 | my $send_policy = $params->{send_policy}; | |||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||
| 51 | 900 | ▶ | $send_policy_result->{after} //= 0; | ||||||||||||||||||||||||||||||
|
Condition50%1/2
$send_policy_result->{"after"} //= 0
MC/DC0%0/1
$send_policy_result->{"after"} //= 0
$send_policy_result->{"after"}
Truth table50%1/2
A
A= $send_policy_result->{"after"}
| |||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||
| 53 | 900 | ▶ | _apply_send_policy($send_policy, $send_policy_result, $params) | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 54 | if defined $send_policy; | ||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||
| 56 | 900 | ▶ | _apply_send_policy($self->send_policy, $send_policy_result, $params) | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 57 | if $self->has_send_policy; | ||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||
| 59 | 900 | ▶ | return unless $send_policy_result->{allow}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||
| 61 | # If this is a bare metal chat... then apply any required delay | ||||||||||||||||||||||||||||||||
| 62 | 317 | ▶ | if (($send_policy_result->{after} // 0) > 0 | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition60%3/5
($send_policy_result->{"after"} // 0) > 0 and $self->does("Bot::Backbone::Service::Role::BareMetalChat")
$send_policy_result->{"after"} // 0
MC/DC0%0/2
($send_policy_result->{"after"} // 0) > 0 and $self->does("Bot::Backbone::Service::Role::BareMetalChat")
$send_policy_result->{"after"}
$self->does("Bot::Backbone::Service::Role::BareMetalChat")
Truth table33%1/3
A and B
A= $send_policy_result->{"after"}B= $self->does("Bot::Backbone::Service::Role::BareMetalChat")
| |||||||||||||||||||||||||||||||||
| 63 | and $self->does('Bot::Backbone::Service::Role::BareMetalChat')) { | ||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||
| 65 | # Setting Timer | ||||||||||||||||||||||||||||||||
| 66 | my $w = AnyEvent->timer( | ||||||||||||||||||||||||||||||||
| 67 | after => $send_policy_result->{after}, | ||||||||||||||||||||||||||||||||
| 68 | 7 | ▶ | cb => sub { $self->$next($params) }, | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 69 | 298 | ); | |||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||
| 71 | 298 | $self->_enqueue_message($w); | |||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||
| 73 | 298 | return; | |||||||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||
| 76 | # Allowed and no delays... so GO! | ||||||||||||||||||||||||||||||||
| 77 | 19 | $self->$next($params); | |||||||||||||||||||||||||||||||
| 78 | 4 | }; | |||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||
| 80 | 897 | ▶ | sub _apply_send_policy { | ||||||||||||||||||||||||||||||
|
Subroutine
_apply_send_policy: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||
| 81 | 897 | my ($send_policy, $send_policy_result, $options) = @_; | |||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||
| 83 | 897 | my $new_result = $send_policy->allow_send($options); | |||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||
| 85 | 897 | ▶ | $send_policy_result->{allow} &&= $new_result->{allow}; | ||||||||||||||||||||||||||||||
|
Condition66%2/3
$send_policy_result->{"allow"} &&= $new_result->{"allow"}
MC/DC50%1/2
$send_policy_result->{"allow"} &&= $new_result->{"allow"}
$send_policy_result->{"allow"}
$new_result->{"allow"}
Truth table66%2/3
A &&= B
A= $send_policy_result->{"allow"}B= $new_result->{"allow"}
| |||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||
| 87 | $send_policy_result->{after} = $new_result->{after} | ||||||||||||||||||||||||||||||||
| 88 | 897 | ▶ | if ($new_result->{after} // 0) > $send_policy_result->{after}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
$new_result->{"after"} // 0
MC/DC100%1/1
$new_result->{"after"} // 0
$new_result->{"after"}
Truth table100%2/2
A
A= $new_result->{"after"}
| |||||||||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||
| 92 | 4 | 1; | |||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||
| 94 | __END__ | ||||||||||||||||||||||||||||||||