| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package TAPx::Base; |
|
2
|
|
|
|
|
|
|
|
|
3
|
12
|
|
|
12
|
|
2689
|
use strict; |
|
|
12
|
|
|
|
|
22
|
|
|
|
12
|
|
|
|
|
638
|
|
|
4
|
12
|
|
|
12
|
|
66
|
use vars qw($VERSION); |
|
|
12
|
|
|
|
|
23
|
|
|
|
12
|
|
|
|
|
6000
|
|
|
5
|
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
=head1 NAME |
|
7
|
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
TAPx::Base - Base class that provides common functionality to L and L |
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
=head1 VERSION |
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
Version 0.50_07 |
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
=cut |
|
15
|
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
$VERSION = '0.50_07'; |
|
17
|
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
19
|
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
package TAPx::Whatever; |
|
21
|
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
use TAPx::Base; |
|
23
|
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
use vars qw($VERSION @ISA); |
|
25
|
|
|
|
|
|
|
@ISA = qw(TAPx::Base); |
|
26
|
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
# ... later ... |
|
28
|
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
my $thing = TAPx::Whatever->new(); |
|
30
|
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
$thing->callback( event => sub { |
|
32
|
|
|
|
|
|
|
# do something interesting |
|
33
|
|
|
|
|
|
|
} ); |
|
34
|
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
36
|
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
C provides callback management. |
|
38
|
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
=head1 METHODS |
|
40
|
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
=head2 Class methods |
|
42
|
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
=head3 C |
|
44
|
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
=cut |
|
46
|
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
sub new { |
|
48
|
99
|
|
|
99
|
1
|
23091
|
my ( $class, $arg_for ) = @_; |
|
49
|
|
|
|
|
|
|
|
|
50
|
99
|
|
|
|
|
298
|
my $self = bless {}, $class; |
|
51
|
99
|
|
|
|
|
836
|
return $self->_initialize($arg_for); |
|
52
|
|
|
|
|
|
|
} |
|
53
|
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub _initialize { |
|
55
|
99
|
|
|
99
|
|
207
|
my ( $self, $arg_for, $ok_callback ) = @_; |
|
56
|
|
|
|
|
|
|
|
|
57
|
99
|
|
|
|
|
275
|
my %ok_map = map { $_ => 1 } @$ok_callback; |
|
|
501
|
|
|
|
|
1681
|
|
|
58
|
|
|
|
|
|
|
|
|
59
|
99
|
|
|
|
|
487
|
$self->{ok_callbacks} = \%ok_map; |
|
60
|
|
|
|
|
|
|
|
|
61
|
99
|
100
|
|
|
|
416
|
if ( exists $arg_for->{callbacks} ) { |
|
62
|
5
|
|
|
|
|
7
|
while ( my ( $event, $callback ) = each %{ $arg_for->{callbacks} } ) { |
|
|
12
|
|
|
|
|
55
|
|
|
63
|
9
|
|
|
|
|
31
|
$self->callback( $event, $callback ); |
|
64
|
|
|
|
|
|
|
} |
|
65
|
|
|
|
|
|
|
} |
|
66
|
|
|
|
|
|
|
|
|
67
|
97
|
|
|
|
|
417
|
return $self; |
|
68
|
|
|
|
|
|
|
} |
|
69
|
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
=head3 C |
|
71
|
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
Install a callback for a named event. |
|
73
|
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
=cut |
|
75
|
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
sub callback { |
|
77
|
17
|
|
|
17
|
1
|
8673
|
my ( $self, $event, $callback ) = @_; |
|
78
|
|
|
|
|
|
|
|
|
79
|
17
|
|
|
|
|
30
|
my %ok_map = %{ $self->{ok_callbacks} }; |
|
|
17
|
|
|
|
|
73
|
|
|
80
|
|
|
|
|
|
|
|
|
81
|
17
|
100
|
|
|
|
52
|
$self->_croak('No callbacks may be installed') |
|
82
|
|
|
|
|
|
|
unless %ok_map; |
|
83
|
|
|
|
|
|
|
|
|
84
|
15
|
100
|
|
|
|
121
|
$self->_croak( "Callback $event is not supported. Valid callbacks are " |
|
85
|
|
|
|
|
|
|
. join( ', ', sort keys %ok_map ) ) |
|
86
|
|
|
|
|
|
|
unless exists $ok_map{$event}; |
|
87
|
|
|
|
|
|
|
|
|
88
|
12
|
|
|
|
|
47
|
$self->{code_for}{$event} = $callback; |
|
89
|
|
|
|
|
|
|
} |
|
90
|
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
sub _callback_for { |
|
92
|
1061
|
|
|
1061
|
|
6214
|
my ( $self, $event ) = @_; |
|
93
|
1061
|
|
|
|
|
4091
|
return $self->{code_for}{$event}; |
|
94
|
|
|
|
|
|
|
} |
|
95
|
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
sub _make_callback { |
|
97
|
703
|
|
|
703
|
|
1913
|
my $self = shift; |
|
98
|
703
|
|
|
|
|
1273
|
my $event = shift; |
|
99
|
|
|
|
|
|
|
|
|
100
|
703
|
|
|
|
|
1412
|
my $cb = $self->_callback_for($event); |
|
101
|
703
|
100
|
|
|
|
3195
|
return unless defined $cb; |
|
102
|
12
|
|
|
|
|
61
|
return $cb->(@_); |
|
103
|
|
|
|
|
|
|
} |
|
104
|
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
sub _croak { |
|
106
|
13
|
|
|
13
|
|
23
|
my ( $self, $message ) = @_; |
|
107
|
13
|
|
|
|
|
87
|
require Carp; |
|
108
|
13
|
|
|
|
|
2598
|
Carp::croak($message); |
|
109
|
|
|
|
|
|
|
} |
|
110
|
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
1; |