blib/lib/Tk/SignalSlot.pm

filter: Statementstmt 34.0% 16 / 47 Branchbran 0.0% 0 / 14 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 42.8% 3 / 7 Podpod 100% 3 / 3 totaltotal 28.9% 22 / 76 CC 10 SCAR 24.8
CC
10
Cov
25%
connect
20.0
__ANON__
12.0
disconnect
12.0
CRAP 11.9
↑ Summary
1  
2 package Tk::SignalSlot;
3  
4 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 1 our $VERSION = 0.1;
8  
9 1 my %connected;
10 my @ids;
11 1 my $newID = 0;
12  
13 0 ▶sub connect {
Subroutine connect: not called CC=4 SCAR=30.0
Pod documented
14 0 my ($parent, $event, $code) = @_;
15  
16 0 ▶ unless ($event && $code) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($event and $code) 0 0 0
Condition0%0/3
$event and $code
!ll&&!rl&&r
000
MC/DC0%0/2
$event and $code
$event $code
Truth table0%0/3
A and B
A= $eventB= $code
ABresult
0X0
100
111
17 0 croak "connect usage - need an event description and a callback";
18 }
19  
20 # create the callback object.
21 0 my $cb = Tk::Callback->new($code);
22  
23 # if this is the first time we connect to this event,
24 # create the Tk binding for it.
25 0 ▶ unless (exists $connected{$parent}{$event}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $connected{$parent}{$event}) 0 0 0
26 0 ▶ $parent->Tk::bind($event => sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
27 0 ▶ $_ && $_->Call() for @{$connected{$parent}{$event}};
Branch: 1 branch
BranchTrueFalseTotal
$_ and $_->Call 0 0 0
28 0 });
29  
30 0 $connected{$parent}{$event} = [];
31 }
32  
33 0 my $index = @{$connected{$parent}{$event}};
34 0 $connected{$parent}{$event}[$index] = $cb;
35  
36 0 $ids[$newID] = [$parent, $event, $index];
37 0 return $newID++;
38 }
39  
40 0 ▶sub disconnect {
Subroutine disconnect: not called CC=3 SCAR=24.8
Pod documented
41 0 my ($w, $id) = @_;
42  
43 0 ▶ if ($id > $#ids) {
Branch: 1 branch
BranchTrueFalseTotal
if ($id > $#ids) 0 0 0
44 0 carp "disconnect - Callback ID $id not defined!";
45 0 return undef;
46 }
47  
48 0 my ($parent, $event, $index) = @{$ids[$id]};
49  
50 0 ▶ unless (defined $connected{$parent}{$event}[$index]) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $connected{$parent}{$event}[$index]) 0 0 0
51 0 carp "disconnect - Callback ID $id already disconnected!";
52 0 return undef;
53 }
54  
55 0 $connected{$parent}{$event}[$index] = undef;
56  
57 0 return 1;
58 }
59  
60 0 ▶sub is_connected {
Subroutine is_connected: not called CC=3 SCAR=24.8
Pod documented
61 0 my ($w, $id) = @_;
62  
63 0 ▶ return 0 if $id > $#ids;
Branch: 1 branch
BranchTrueFalseTotal
if $id > $#ids 0 0 0
64  
65 0 my ($parent, $event, $index) = @{$ids[$id]};
66 0 ▶ return 0 unless defined $connected{$parent}{$event}[$index];
Branch: 1 branch
BranchTrueFalseTotal
unless defined $connected{$parent}{$event}[$index] 0 0 0
67  
68 0 return 1;
69 }
70  
71 package Tk;
72  
73 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
74  
75 1 *connect = \&Tk::SignalSlot::connect;
76 1 *disconnect = \&Tk::SignalSlot::disconnect;
77 1 *is_connected = \&Tk::SignalSlot::is_connected;
78  
79 1 1;
80  
81 __END__
↑ Summary