Event/Callback.pm untested

filter: Statementstmt 0.0% 0 / 69 Branchbran 0.0% 0 / 14 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 26 Podpod 0.0% 0 / 19 totaltotal 0.0% 0 / 128 CC 8 SCAR 21.3
CC
8
Cov
0%
handler
30.0
sock2handler
20.0
BEGIN
2.0
CRAP 8.4
1  
2 package IO::Event::Callback;
3  
4 use strict;
5 use warnings;
6  
7 use IO::Event;
8  
9 our @handlers;
10 BEGIN {
11 @handlers = qw(input connection read_ready werror eof output
12 outputdone connected connect_failed died timer exception
13 outputoverflow);
14 }
15  
16 sub new
17 {
18 my ($pkg, $filehandle, %h) = @_;
19  
20 my $ro = $h{read_only};
21 my $wo = $h{write_only};
22 delete $h{read_only};
23 delete $h{write_only};
24  
25 my $self = handler($pkg, %h);
26  
27 return IO::Event->new($filehandle, $self, read_only => $ro, write_only => $wo);
28 }
29  
30 sub ie_input { $_[0]->{'ie_input'}->(@_) };
31 sub ie_connection { $_[0]->{'ie_connection'}->(@_) };
32 sub ie_read_ready { $_[0]->{'ie_read_ready'}->(@_) };
33 sub ie_werror { $_[0]->{'ie_werror'}->(@_) };
34 sub ie_eof { $_[0]->{'ie_eof'}->(@_) };
35 sub ie_output { $_[0]->{'ie_output'}->(@_) };
36 sub ie_outputdone { $_[0]->{'ie_outputdone'}->(@_) };
37 sub ie_connected { $_[0]->{'ie_connected'}->(@_) };
38 sub ie_connect_failed { $_[0]->{'ie_connect_failed'}->(@_) };
39 sub ie_died { $_[0]->{'ie_died'}->(@_) };
40 sub ie_timer { $_[0]->{'ie_timer'}->(@_) };
41 sub ie_exception { $_[0]->{'ie_exception'}->(@_) };
42 sub ie_outputoverflow { $_[0]->{'ie_outputoverflow'}->(@_) };
43  
44 sub handler
45 {
46 my ($pkg, %h) = @_;
47  
48 my $self = bless {}, $pkg;
49  
50 for my $h (@handlers) {
51 my $key =
52 exists($h{$h}) ? $h :
53 exists($h{"ie_$h"}) ? "ie_$h" : undef;
54 if ($key) {
55 $self->{"ie_$h"} = $h{$key};
56 delete $h{$key};
57 } else {
58 $self->{"ie_$h"} = sub {};
59 }
60 }
61 my @k = keys %h;
62 die "unexpected parameters: @k" if @k;
63 return $self;
64 }
65  
66 sub sock2handler
67 {
68 my ($pkg, $sref) = @_;
69 my %h;
70 for my $h (@handlers) {
71 next unless exists $sref->{$h};
72 my $key =
73 exists($sref->{$h}) ? $h :
74 exists($sref->{"ie_$h"}) ? "ie_$h" : next;
75 $h{$h} = $sref->{$key};
76 delete $sref->{$key};
77 }
78 my $handler = handler($pkg,%h);
79 }
80  
81 package IO::Event::INET::Callback;
82  
83 use strict;
84 use warnings;
85  
86 sub new
87 {
88 my ($pkg, %sock) = @_;
89 my $handler = IO::Event::Callback->sock2handler(\%sock);
90 return IO::Event::INET->new(%sock, Handler => $handler);
91 }
92  
93 package IO::Event::UNIX::Callback;
94  
95 use strict;
96 use warnings;
97  
98 sub new
99 {
100 my ($pkg, %sock) = @_;
101 my $handler = IO::Event::Callback->sock2handler(\%sock);
102 return IO::Event::UNIX->new(%sock, Handler => $handler);
103 }
104  
105 1;
106  
107 __END__