File Coverage

blib/lib/EV/Watcher/Bind.pm
Criterion Covered Total %
statement 25 33 75.7
branch n/a
condition 0 3 0.0
subroutine 5 7 71.4
pod n/a
total 30 43 69.7


line stmt bran cond sub pod time code
1             # $Id: /mirror/perl/EV-Watcher-Bind/trunk/lib/EV/Watcher/Bind.pm 9173 2007-11-15T11:33:58.291707Z daisuke $
2             #
3             # Copyright (c) 2007 Daisuke Maki
4             # All rights reserved.
5              
6             package EV::Watcher::Bind;
7 1     1   1291 use strict;
  1         2  
  1         44  
8 1     1   6 use warnings;
  1         1  
  1         38  
9 1     1   3021 use EV;
  1         5720  
  1         223  
10             our $VERSION = '0.00001';
11              
12             BEGIN
13             {
14             my $mk_wrapper = sub {
15 16         19 my ($original) = @_;
16             return sub {
17             # the EV API always ends with a callback. pop that callback, and
18             # take the rest of the arguments as the binding arguments
19 0     0   0 my @binds;
20             my $x;
21 0   0     0 do {
22 0         0 $x = pop @_;
23 0         0 unshift @binds, $x;
24             } while (@_ && ref $x ne 'CODE');
25              
26 0         0 my $callback = shift @binds;
27 0         0 my $w;
28 0     0   0 $w = $original->(@_, sub { $callback->(@binds, $w) });
  0         0  
29 16         206 };
30 1     1   5 };
31              
32 1         4 my @names = qw(io timer periodic signal child idle prepare check);
33 1         2 my @suffix = ('', '_ns');
34 1         2 foreach my $name (@names) {
35 8         9 foreach my $suffix (@suffix) {
36 1     1   10 no strict 'refs';
  1         2  
  1         134  
37 16         28 my $fullname = "EV::${name}${suffix}";
38 16         17 my $bindname = "${fullname}_bind";
39 16         76 my $original = *{ $fullname }{CODE};
  16         34  
40 16         27 *{ $bindname } = $mk_wrapper->($original);
  16         129  
41             }
42             }
43             }
44              
45              
46             1;
47              
48             __END__