line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
24
|
|
|
24
|
|
162
|
use strict; |
|
24
|
|
|
|
|
42
|
|
|
24
|
|
|
|
|
859
|
|
2
|
|
|
|
|
|
|
package Event::Watcher; |
3
|
24
|
|
|
24
|
|
120
|
use base 'Exporter'; |
|
24
|
|
|
|
|
41
|
|
|
24
|
|
|
|
|
2405
|
|
4
|
24
|
|
|
24
|
|
149
|
use Carp; |
|
24
|
|
|
|
|
45
|
|
|
24
|
|
|
|
|
1390
|
|
5
|
24
|
|
|
24
|
|
155
|
use vars qw(@EXPORT_OK @ATTRIBUTE); |
|
24
|
|
|
|
|
75
|
|
|
24
|
|
|
|
|
2189
|
|
6
|
|
|
|
|
|
|
@EXPORT_OK = qw(ACTIVE SUSPEND R W E T); |
7
|
|
|
|
|
|
|
@ATTRIBUTE = qw(cb cbtime desc debug prio reentrant repeat max_cb_tm); |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
sub register { |
10
|
24
|
|
|
24
|
|
157
|
no strict 'refs'; |
|
24
|
|
|
|
|
46
|
|
|
24
|
|
|
|
|
9581
|
|
11
|
122
|
|
|
122
|
0
|
337
|
my $package = caller; |
12
|
|
|
|
|
|
|
|
13
|
122
|
|
|
|
|
200
|
my $name = $package; |
14
|
122
|
|
|
|
|
789
|
$name =~ s/^.*:://; |
15
|
|
|
|
|
|
|
|
16
|
122
|
|
|
|
|
221
|
my $sub = \&{"$package\::new"}; |
|
122
|
|
|
|
|
459
|
|
17
|
122
|
50
|
|
|
|
391
|
die "can't find $package\::new" |
18
|
|
|
|
|
|
|
if !$sub; |
19
|
122
|
|
|
|
|
805
|
*{"Event::".$name} = sub { |
20
|
3885
|
|
|
3885
|
|
1900398
|
shift; |
21
|
3885
|
|
|
|
|
10044
|
$sub->("Event::".$name, @_); |
22
|
122
|
|
|
|
|
513
|
}; |
23
|
|
|
|
|
|
|
|
24
|
122
|
50
|
|
|
|
503
|
&Event::add_hooks if @_; |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
my $warn_noise = 10; |
28
|
|
|
|
|
|
|
sub init { |
29
|
3884
|
50
|
|
3884
|
0
|
8060
|
croak "Event::Watcher::init wants 2 args" if @_ != 2; |
30
|
3884
|
|
|
|
|
6446
|
my ($o, $arg) = @_; |
31
|
|
|
|
|
|
|
|
32
|
3884
|
|
|
|
|
9437
|
for my $k (keys %$arg) { |
33
|
19124
|
50
|
|
|
|
35199
|
if ($k =~ s/^e_//) { |
34
|
0
|
0
|
|
|
|
0
|
Carp::cluck "'e_$k' is renamed to '$k'" |
35
|
|
|
|
|
|
|
if --$warn_noise >= 0; |
36
|
0
|
|
|
|
|
0
|
$arg->{$k} = delete $arg->{"e_$k"}; |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
3884
|
100
|
|
|
|
8776
|
if (!exists $arg->{desc}) { |
41
|
|
|
|
|
|
|
# try to find caller but cope with optimized-away frames & etc |
42
|
3862
|
|
|
|
|
6802
|
for my $up (1..4) { |
43
|
7724
|
|
|
|
|
36256
|
my @fr = caller $up; |
44
|
7724
|
100
|
66
|
|
|
36128
|
next if !@fr || $fr[0] =~ m/^Event\b/; |
45
|
3862
|
|
|
|
|
8016
|
my ($file,$line) = @fr[1,2]; |
46
|
3862
|
|
|
|
|
10863
|
$file =~ s,^.*/,,; |
47
|
3862
|
|
|
|
|
15497
|
$o->desc("?? $file:$line"); |
48
|
3862
|
|
|
|
|
8422
|
last; |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
# set up prio |
53
|
|
|
|
|
|
|
{ |
54
|
24
|
|
|
24
|
|
201
|
no strict 'refs'; |
|
24
|
|
|
|
|
65
|
|
|
24
|
|
|
|
|
6476
|
|
|
3884
|
|
|
|
|
5079
|
|
55
|
3884
|
|
100
|
|
|
4451
|
$o->prio($ { ref($o)."::DefaultPriority" } || Event::PRIO_NORMAL()); |
56
|
3884
|
100
|
|
|
|
7963
|
if (exists $arg->{nice}) { |
57
|
3
|
|
|
|
|
11
|
$o->prio($o->prio + delete $arg->{nice}); |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
$o->prio(-1) |
61
|
3884
|
100
|
|
|
|
6769
|
if delete $arg->{async}; |
62
|
|
|
|
|
|
|
$o->prio(delete $arg->{prio}) |
63
|
3884
|
100
|
|
|
|
11095
|
if exists $arg->{prio}; |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
# is parked? |
66
|
3884
|
|
|
|
|
5677
|
my $parked = delete $arg->{parked}; |
67
|
|
|
|
|
|
|
|
68
|
3884
|
|
|
|
|
8334
|
for my $k (keys %$arg) { |
69
|
15311
|
|
|
|
|
18704
|
my $m = $k; |
70
|
15311
|
100
|
|
|
|
34828
|
if ($o->can($m)) { |
71
|
11518
|
|
|
|
|
33335
|
$o->$m($arg->{$k}); |
72
|
11517
|
|
|
|
|
19753
|
next; |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
3883
|
50
|
|
|
|
7719
|
Carp::cluck "creating ".ref($o)." desc='".$o->desc."'\n" |
77
|
|
|
|
|
|
|
if $Event::DebugLevel >= 3; |
78
|
|
|
|
|
|
|
|
79
|
3883
|
100
|
|
|
|
162205
|
$o->start unless $parked; |
80
|
3875
|
|
|
|
|
9713
|
$o; |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
sub attributes { |
84
|
24
|
|
|
24
|
|
175
|
no strict 'refs'; |
|
24
|
|
|
|
|
66
|
|
|
24
|
|
|
|
|
7790
|
|
85
|
3
|
|
|
3
|
0
|
6
|
my ($o) = @_; |
86
|
3
|
100
|
|
|
|
18
|
my $pk = ref $o? ref $o : $o; |
87
|
3
|
|
|
|
|
5
|
@{"$ {pk}::ATTRIBUTE"}, map { attributes($_) } @{"$ {pk}::ISA"}; |
|
3
|
|
|
|
|
14
|
|
|
2
|
|
|
|
|
9
|
|
|
3
|
|
|
|
|
20
|
|
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
sub configure { |
91
|
0
|
|
|
0
|
0
|
0
|
my $o = shift; |
92
|
0
|
0
|
|
|
|
0
|
if (! @_) { |
93
|
0
|
|
|
|
|
0
|
map { $_, $o->$_() } $o->attributes; |
|
0
|
|
|
|
|
0
|
|
94
|
|
|
|
|
|
|
} else { |
95
|
0
|
|
|
|
|
0
|
while (my ($k,$v)= splice @_, -2) { $o->$k($v)} |
|
0
|
|
|
|
|
0
|
|
96
|
|
|
|
|
|
|
1 # whatever |
97
|
0
|
|
|
|
|
0
|
} |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
sub private { # assumes $self is a HASH ref |
101
|
6
|
|
|
6
|
0
|
19
|
my $self = shift; |
102
|
6
|
|
|
|
|
11
|
my $pkg = caller; |
103
|
6
|
100
|
|
|
|
14
|
if (@_) { |
104
|
2
|
|
|
|
|
9
|
$self->{$pkg} = shift |
105
|
|
|
|
|
|
|
} else { |
106
|
4
|
|
|
|
|
15
|
$self->{$pkg}; |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
sub data { # assumes $self is a HASH ref |
111
|
3
|
|
|
3
|
0
|
8
|
my $self = shift; |
112
|
3
|
100
|
|
|
|
8
|
if (@_) { |
113
|
|
|
|
|
|
|
$self->{_user_data_} = shift |
114
|
1
|
|
|
|
|
6
|
} else { |
115
|
2
|
|
|
|
|
10
|
$self->{_user_data_}; |
116
|
|
|
|
|
|
|
} |
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
sub clump { |
120
|
0
|
|
|
0
|
0
|
|
require Carp; |
121
|
0
|
|
|
|
|
|
Carp::cluck "clump is deprecated"; |
122
|
|
|
|
|
|
|
} |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
package Event::Watcher::Tied; |
125
|
24
|
|
|
24
|
|
199
|
use vars qw(@ISA @ATTRIBUTE); |
|
24
|
|
|
|
|
57
|
|
|
24
|
|
|
|
|
1973
|
|
126
|
|
|
|
|
|
|
@ISA = 'Event::Watcher'; |
127
|
|
|
|
|
|
|
@ATTRIBUTE = qw(hard at flags); |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
1; |