line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package TAP::Base; |
2
|
|
|
|
|
|
|
|
3
|
44
|
|
|
44
|
|
67289
|
use strict; |
|
44
|
|
|
|
|
107
|
|
|
44
|
|
|
|
|
1384
|
|
4
|
44
|
|
|
44
|
|
268
|
use warnings; |
|
44
|
|
|
|
|
105
|
|
|
44
|
|
|
|
|
1530
|
|
5
|
|
|
|
|
|
|
|
6
|
44
|
|
|
44
|
|
332
|
use base 'TAP::Object'; |
|
44
|
|
|
|
|
108
|
|
|
44
|
|
|
|
|
11386
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
=head1 NAME |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
TAP::Base - Base class that provides common functionality to L |
11
|
|
|
|
|
|
|
and L |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
=head1 VERSION |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
Version 3.40_01 |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
=cut |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
our $VERSION = '3.40_01'; |
20
|
|
|
|
|
|
|
|
21
|
44
|
|
|
|
|
110
|
use constant GOT_TIME_HIRES => do { |
22
|
44
|
|
|
44
|
|
3341
|
eval 'use Time::HiRes qw(time);'; |
|
44
|
|
|
|
|
26909
|
|
|
44
|
|
|
|
|
66671
|
|
|
44
|
|
|
|
|
229
|
|
23
|
44
|
50
|
|
|
|
32126
|
$@ ? 0 : 1; |
24
|
44
|
|
|
44
|
|
335
|
}; |
|
44
|
|
|
|
|
143
|
|
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
=head1 SYNOPSIS |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
package TAP::Whatever; |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
use base 'TAP::Base'; |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
# ... later ... |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
my $thing = TAP::Whatever->new(); |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
$thing->callback( event => sub { |
37
|
|
|
|
|
|
|
# do something interesting |
38
|
|
|
|
|
|
|
} ); |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
=head1 DESCRIPTION |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
C provides callback management. |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
=head1 METHODS |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
=head2 Class Methods |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
=cut |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
sub _initialize { |
51
|
606
|
|
|
606
|
|
2715
|
my ( $self, $arg_for, $ok_callback ) = @_; |
52
|
|
|
|
|
|
|
|
53
|
606
|
|
|
|
|
2382
|
my %ok_map = map { $_ => 1 } @$ok_callback; |
|
3539
|
|
|
|
|
11216
|
|
54
|
|
|
|
|
|
|
|
55
|
606
|
|
|
|
|
3606
|
$self->{ok_callbacks} = \%ok_map; |
56
|
|
|
|
|
|
|
|
57
|
606
|
100
|
|
|
|
3076
|
if ( my $cb = delete $arg_for->{callbacks} ) { |
58
|
5
|
|
|
|
|
33
|
while ( my ( $event, $callback ) = each %$cb ) { |
59
|
10
|
|
|
|
|
54
|
$self->callback( $event, $callback ); |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
604
|
|
|
|
|
2471
|
return $self; |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
=head3 C |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
Install a callback for a named event. |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
=cut |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
sub callback { |
73
|
154
|
|
|
154
|
1
|
12505
|
my ( $self, $event, $callback ) = @_; |
74
|
|
|
|
|
|
|
|
75
|
154
|
|
|
|
|
394
|
my %ok_map = %{ $self->{ok_callbacks} }; |
|
154
|
|
|
|
|
1874
|
|
76
|
|
|
|
|
|
|
|
77
|
154
|
100
|
|
|
|
820
|
$self->_croak('No callbacks may be installed') |
78
|
|
|
|
|
|
|
unless %ok_map; |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
$self->_croak( "Callback $event is not supported. Valid callbacks are " |
81
|
|
|
|
|
|
|
. join( ', ', sort keys %ok_map ) ) |
82
|
152
|
100
|
|
|
|
659
|
unless exists $ok_map{$event}; |
83
|
|
|
|
|
|
|
|
84
|
149
|
|
|
|
|
422
|
push @{ $self->{code_for}{$event} }, $callback; |
|
149
|
|
|
|
|
880
|
|
85
|
|
|
|
|
|
|
|
86
|
149
|
|
|
|
|
785
|
return; |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
sub _has_callbacks { |
90
|
280
|
|
|
280
|
|
976
|
my $self = shift; |
91
|
280
|
|
|
|
|
708
|
return keys %{ $self->{code_for} } != 0; |
|
280
|
|
|
|
|
2901
|
|
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
sub _callback_for { |
95
|
1244
|
|
|
1244
|
|
11244
|
my ( $self, $event ) = @_; |
96
|
1244
|
|
|
|
|
4449
|
return $self->{code_for}{$event}; |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
sub _make_callback { |
100
|
960
|
|
|
960
|
|
4787
|
my $self = shift; |
101
|
960
|
|
|
|
|
2626
|
my $event = shift; |
102
|
|
|
|
|
|
|
|
103
|
960
|
|
|
|
|
3869
|
my $cb = $self->_callback_for($event); |
104
|
960
|
100
|
|
|
|
4008
|
return unless defined $cb; |
105
|
150
|
|
|
|
|
582
|
return map { $_->(@_) } @$cb; |
|
151
|
|
|
|
|
1053
|
|
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=head3 C |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
Return the current time using Time::HiRes if available. |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=cut |
113
|
|
|
|
|
|
|
|
114
|
625
|
|
|
625
|
1
|
5556
|
sub get_time { return time() } |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=head3 C |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
Return true if the time returned by get_time is high resolution (i.e. if Time::HiRes is available). |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
=cut |
121
|
|
|
|
|
|
|
|
122
|
0
|
|
|
0
|
1
|
0
|
sub time_is_hires { return GOT_TIME_HIRES } |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
=head3 C |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
Return array reference of the four-element list of CPU seconds, |
127
|
|
|
|
|
|
|
as with L. |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
=cut |
130
|
|
|
|
|
|
|
|
131
|
551
|
|
|
551
|
1
|
6245
|
sub get_times { return [ times() ] } |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
1; |