blib/lib/Aion/Emitter.pm

filter: Statementstmt 92.0% 46 / 50 Branchbran 68.7% 11 / 16 Conditioncond 36.3% 4 / 11 MC/DCmcdc 0.0% 0 / 7 Subroutinesub 100% 7 / 7 Podpod 100% 1 / 1 totaltotal 75.0% 69 / 92 CC 15 SCAR 22.4
CC
15
Cov
79%
__ANON__
15.2
emit
5.2
BEGIN
1.0
CRAP 9.4
↑ Summary blib/lib/Aion/Emitter/ListenersRun.pm »
1 package Aion::Emitter;
2 # Диспетчер
3  
4 2 ▶use common::sense;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 2 our $VERSION = "0.1.2";
7  
8 2 ▶use Aion::Pleroma;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 2 ▶use Aion;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 2 my $event_isa = HashRef[ArrayRef[Dict[act => StrMatch[qr/^[\w:]+#\w+$/a], line => Option[Nat], nice => Option[Num], remark => Option[Str]]]];
13  
14 2 ▶use Aion::Env::Etc INI => (isa => Str, default => 'etc/annotation/listen.ann', key => 'aion.emitter.ini');
Subroutine BEGIN: called CC=1 SCAR=0.0
15 2 ▶use Aion::Env::Etc EVENT => (isa => $event_isa, default => {}, key => 'aion.emitter.event');
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 # Путь к собранным из аннотаций методам
18 2 has ini => (is => 'ro', isa => Str, default => INI);
19  
20 # Список слушателей
21 2 ▶has event => (is => 'ro?!', isa => $event_isa, default => sub {
Subroutine __ANON__: called CC=11 SCAR=27.2
22 2 my ($self) = @_;
23 2 my %event = %{EVENT()};
24
25 2 ▶ if(defined $self->ini and -e $self->ini) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->ini and -e $self->ini) 2 0 2
Condition33%1/3
defined $self->ini and -e $self->ini
!ll&&!rl&&r
002
MC/DC0%0/2
defined $self->ini and -e $self->ini
defined $self->ini -e $self->ini
Truth table33%1/3
A and B
A= defined $self->iniB= -e $self->ini
ABresult
0X0
100
111
26 2 ▶ open my $f, "<:encoding(UTF-8)", $self->ini or die "Not open ${\$self->ini}";
Branch: 1 branch
BranchTrueFalseTotal
open my $f, "<:encoding(UTF-8)", $self->ini or die "Not open ${\$self->ini;}" 2 0 2
27 2 ▶ while(<$f>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline $f)) 6 2 8
28 6 ▶ do { close $f; die "${\$self->ini}:$. corrupt!" } unless /^([\w:]+)#(\w*),(\d+)=(?:(-?\d+(?:\.\d+)?)\s+)?([a-z][\w:]*(?:#[\w.:-]+)?)(?:\s+(.*?))??\s*$/ia;
Branch: 1 branch
BranchTrueFalseTotal
unless (/^([\w:]+)#(\w*),(\d+)=(?:(-?\d+(?:\.\d+)?)\s+)?([a-z][\w:]*(?:#[\w.:-]+)?)(?:\s+(.*?))??\s*$/ai) 0 6 6
29 6 my ($pkg, $sub, $line, $nice, $evt, $remark) = ($1, $2, $3, $4, $5, $6);
30 6 ▶ $sub //= 'listen';
Condition50%1/2
$sub //= "listen"
l!l
60
MC/DC0%0/1
$sub //= "listen"
$sub
Truth table50%1/2
A
A= $sub
Aresult
11
00
31 6 ▶ push @{$event{$evt}}, {
Branch: 2 branches
BranchTrueFalseTotal
$nice ? : 0 6 6
$remark ne '' ? : 2 4 6
32 act => "$pkg#$sub",
33 line => $line,
34 $nice? (nice => $nice): (),
35 $remark ne ''? (remark => $remark): (),
36 };
37 }
38 2 close $f;
39 }
40  
41 2 for my $listens (values %event) {
42 4 ▶ @$listens = sort { $a->{nice} <=> $b->{nice} or $a->{act} cmp $b->{act} } @$listens;
Condition33%1/3
$Aion::Emitter::a->{'nice'} <=> $Aion::Emitter::b->{'nice'} || $Aion::Emitter::a->{'act'} cmp $Aion::Emitter::b->{'act'}
l!l&&r!l&&!r
020
MC/DC0%0/2
$Aion::Emitter::a->{'nice'} <=> $Aion::Emitter::b->{'nice'} || $Aion::Emitter::a->{'act'} cmp $Aion::Emitter::b->{'act'}
$Aion::Emitter::a->{'nice'} <=> $Aion::Emitter::b->{'nice'} $Aion::Emitter::a->{'act'} cmp $Aion::Emitter::b->{'act'}
Truth table33%1/3
A || B
A= $Aion::Emitter::a->{'nice'} <=> $Aion::Emitter::b->{'nice'}B= $Aion::Emitter::a->{'act'} cmp $Aion::Emitter::b->{'act'}
ABresult
1X1
011
000
43 }
44
45 2 \%event
46 2 });
47  
48 # Плерома
49 2 has pleroma => (is => 'ro', isa => 'Aion::Pleroma', eon => 1);
50  
51 # Излучить
52 2 ▶sub emit {
Subroutine emit: called CC=5 SCAR=16.4
Pod documented
53 2 my ($self, $event, $key) = @_;
54
55 2 ▶ my $listeners = $self->event->{defined($key)? "${\ref $event}#$key": ref $event};
Branch: 1 branch
BranchTrueFalseTotal
defined $key ? : 1 1 2
56 2 ▶ return $self unless $listeners;
Branch: 1 branch
BranchTrueFalseTotal
unless $listeners 0 2 2
57
58 2 for my $listener_bag (@$listeners) {
59 3 my ($pkg, $sub) = split /#/, $listener_bag->{act}, 2;
60 3 ▶ my $listener = $self->pleroma->get($pkg) // $self->pleroma->autoware($pkg)->resolve($pkg);
Condition33%1/3
$self->pleroma->get($pkg) // $self->pleroma->autoware($pkg)->resolve($pkg)
l!l&&r!l&&!r
300
MC/DC0%0/2
$self->pleroma->get($pkg) // $self->pleroma->autoware($pkg)->resolve($pkg)
$self->pleroma->get($pkg) $self->pleroma->autoware($pkg)->resolve($pkg)
Truth table33%1/3
A // B
A= $self->pleroma->get($pkg)B= $self->pleroma->autoware($pkg)->resolve($pkg)
ABresult
1X1
011
000
61 3 $listener->$sub($event);
62 }
63
64 $self
65 2 }
66  
67 2 1;
68  
69 __END__
↑ Summary blib/lib/Aion/Emitter/ListenersRun.pm »