blib/lib/Event/Watcher.pm

filter: Statementstmt 88.4% 84 / 95 Branchbran 69.4% 25 / 36 Conditioncond 80.0% 4 / 5 MC/DCmcdc 66.6% 2 / 3 Subroutinesub 87.5% 14 / 16 Podpod 0.0% 0 / 7 totaltotal 79.6% 129 / 162 CC 24 SCAR 22.5
CC
24
Cov
83%
init
17.7
configure
12.0
register
3.0
CRAP 9.5
« blib/lib/Event/type.pm ↑ Summary blib/lib/Event.pm »
1 25 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 package Event::Watcher;
3 25 ▶use base 'Exporter';
Subroutine BEGIN: called CC=1 SCAR=0.0
4 25 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 25 ▶use vars qw(@EXPORT_OK @ATTRIBUTE);
Subroutine BEGIN: called CC=1 SCAR=0.0
6 25 @EXPORT_OK = qw(ACTIVE SUSPEND R W E T);
7 25 @ATTRIBUTE = qw(cb cbtime desc debug prio reentrant repeat max_cb_tm);
8  
9 127 ▶sub register {
Subroutine register: called CC=3 SCAR=11.0
Pod undocumented
10 25 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
11 127 my $package = caller;
12  
13 127 my $name = $package;
14 127 $name =~ s/^.*:://;
15  
16 127 my $sub = \&{"$package\::new"};
17 127 ▶ die "can't find $package\::new"
Branch: 1 branch
BranchTrueFalseTotal
unless $sub 0 127 127
18 if !$sub;
19 127 ▶ *{"Event::".$name} = sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
20 5043 shift;
21 5043 $sub->("Event::".$name, @_);
22 127 };
23  
24 127 ▶ &Event::add_hooks if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 127 0 127
25 }
26  
27 25 my $warn_noise = 10;
28 5042 ▶sub init {
Subroutine init: called CC=17 SCAR=28.7
Pod undocumented
29 5042 ▶ croak "Event::Watcher::init wants 2 args" if @_ != 2;
Branch: 1 branch
BranchTrueFalseTotal
if @_ != 2 0 5042 5042
30 5042 my ($o, $arg) = @_;
31  
32 5042 for my $k (keys %$arg) {
33 24914 ▶ if ($k =~ s/^e_//) {
Branch: 1 branch
BranchTrueFalseTotal
if ($k =~ s/^e_//) 0 24914 24914
34 0 ▶ Carp::cluck "'e_$k' is renamed to '$k'"
Branch: 1 branch
BranchTrueFalseTotal
if --$warn_noise >= 0 0 0 0
35 if --$warn_noise >= 0;
36 0 $arg->{$k} = delete $arg->{"e_$k"};
37 }
38 }
39  
40 5042 ▶ if (!exists $arg->{desc}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $arg->{"desc"}) 5020 22 5042
41 # try to find caller but cope with optimized-away frames & etc
42 5020 for my $up (1..4) {
43 10040 my @fr = caller $up;
44 10040 ▶ next if !@fr || $fr[0] =~ m/^Event\b/;
Branch: 1 branch
BranchTrueFalseTotal
if not @fr or $fr[0] =~ /^Event\b/ 5020 5020 10040
Condition66%2/3
not @fr or $fr[0] =~ /^Event\b/
l!l&&r!l&&!r
050205020
MC/DC50%1/2
not @fr or $fr[0] =~ /^Event\b/
not @fr $fr[0] =~ /^Event\b/
Truth table66%2/3
not(A) or B
A= not @frB= $fr[0] =~ /^Event\b/
ABresult
1X1
011
000
45 5020 my ($file,$line) = @fr[1,2];
46 5020 $file =~ s,^.*/,,;
47 5020 $o->desc("?? $file:$line");
48 5020 last;
49 }
50 }
51  
52 # set up prio
53 {
54 25 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
55 5042 ▶ $o->prio($ { ref($o)."::DefaultPriority" } || Event::PRIO_NORMAL());
Condition100%2/2
${ref($o) . '::DefaultPriority';} || 4
l!l
45038
MC/DC100%1/1
${ref($o) . '::DefaultPriority';} || 4
${ref($o) . '::DefaultPriority';}
Truth table100%2/2
A
A= ${ref($o) . '::DefaultPriority';}
Aresult
11
00
56 5042 ▶ if (exists $arg->{nice}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $arg->{"nice"}) 3 5039 5042
57 3 $o->prio($o->prio + delete $arg->{nice});
58 }
59 }
60 $o->prio(-1)
61 5042 ▶ if delete $arg->{async};
Branch: 1 branch
BranchTrueFalseTotal
if delete $arg->{"async"} 1 5041 5042
62 $o->prio(delete $arg->{prio})
63 5042 ▶ if exists $arg->{prio};
Branch: 1 branch
BranchTrueFalseTotal
if exists $arg->{"prio"} 4952 90 5042
64  
65 # is parked?
66 5042 my $parked = delete $arg->{parked};
67  
68 5042 for my $k (keys %$arg) {
69 19943 my $m = $k;
70 19943 ▶ if ($o->can($m)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($o->can($m)) 14992 4951 19943
71 14992 $o->$m($arg->{$k});
72 14991 next;
73 }
74 }
75  
76 5041 ▶ Carp::cluck "creating ".ref($o)." desc='".$o->desc."'\n"
Branch: 1 branch
BranchTrueFalseTotal
if $Event::DebugLevel >= 3 0 5041 5041
77 if $Event::DebugLevel >= 3;
78
79 5041 ▶ $o->start unless $parked;
Branch: 1 branch
BranchTrueFalseTotal
unless $parked 5026 15 5041
80 5033 $o;
81 }
82  
83 3 ▶sub attributes {
Subroutine attributes: called CC=2 SCAR=6.9
Pod undocumented
84 25 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
85 3 my ($o) = @_;
86 3 ▶ my $pk = ref $o? ref $o : $o;
Branch: 1 branch
BranchTrueFalseTotal
ref $o ? : 1 2 3
87 3 @{"$ {pk}::ATTRIBUTE"}, map { attributes($_) } @{"$ {pk}::ISA"};
88 }
89  
90 0 ▶sub configure {
Subroutine configure: not called CC=3 SCAR=24.8
Pod undocumented
91 0 my $o = shift;
92 0 ▶ if (! @_) {
Branch: 1 branch
BranchTrueFalseTotal
if (not @_) { } 0 0 0
93 0 map { $_, $o->$_() } $o->attributes;
94 } else {
95 0 ▶ while (my ($k,$v)= splice @_, -2) { $o->$k($v)}
Branch: 1 branch
BranchTrueFalseTotal
if (() = splice(@_, -2)) 0 0 0
96 1 # whatever
97 0 }
98 }
99  
100 6 ▶sub private { # assumes $self is a HASH ref
Subroutine private: called CC=2 SCAR=6.9
Pod undocumented
101 6 my $self = shift;
102 6 my $pkg = caller;
103 6 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 2 4 6
104 2 $self->{$pkg} = shift
105 } else {
106 4 $self->{$pkg};
107 }
108 }
109  
110 3 ▶sub data { # assumes $self is a HASH ref
Subroutine data: called CC=2 SCAR=6.9
Pod undocumented
111 3 my $self = shift;
112 3 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 1 2 3
113 $self->{_user_data_} = shift
114 1 } else {
115 2 $self->{_user_data_};
116 }
117 }
118  
119 0 ▶sub clump {
Subroutine clump: not called CC=1 SCAR=6.9
Pod undocumented
120 0 require Carp;
121 0 Carp::cluck "clump is deprecated";
122 }
123  
124 package Event::Watcher::Tied;
125 25 ▶use vars qw(@ISA @ATTRIBUTE);
Subroutine BEGIN: called CC=1 SCAR=0.0
126 25 @ISA = 'Event::Watcher';
127 25 @ATTRIBUTE = qw(hard at flags);
128  
129 25 1;
« blib/lib/Event/type.pm ↑ Summary blib/lib/Event.pm »