EventMux/Dump.pm

filter: Statementstmt 73.0% 19 / 26 Branchbran 25.0% 2 / 8 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 83.3% 5 / 6 Podpod 100% 2 / 2 totaltotal 61.7% 29 / 47 CC 6 SCAR 15.4
CC
6
Cov
59%
mux
7.1
send
6.0
BEGIN
1.0
CRAP 4.7
« EventMux.pm ↑ Summary
1 package IO::EventMux::Dump;
2 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 3 ▶use IO::EventMux;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 3 ▶use base 'IO::EventMux';
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 =head1 NAME
9  
10 IO::EventMux::Dump - A transparent subclass of IO::EventMux that dumps input/output activity to STDOUT
11  
12 =head1 SYNOPSIS
13
14 use IO::EventMux::Dump;
15  
16 my $mux = IO::EventMux::Dump->new();
17  
18 $mux->add($my_fh);
19  
20 while (1) {
21 my $event = $mux->mux();
22  
23 # ... do something with $event->{type} and $event->{fh}
24 }
25  
26  
27 =cut
28  
29 =head2 B<send()>
30  
31 Wrapper for send call that will write filehandle fileno and data being send
32  
33 =cut
34  
35 0 ▶sub send {
Subroutine send: not called CC=2 SCAR=17.9
Pod documented
36 0 my ($self, $fh, @data) = @_;
37  
38 0 ▶ my $fh_id = ($fh) ? $fh->fileno : '-';
Branch: 1 branch
BranchTrueFalseTotal
$fh ? : 0 0 0
39 0 my $data = join('', @data);
40 0 $data =~ s/\n(.)/\n $1/sg;
41  
42 0 printf("%3s > %s", $fh_id, $data);
43  
44 0 $self->SUPER::send($fh, @data);
45 }
46  
47  
48 =head2 B<mux()>
49  
50 Wrapper for mux call that will write filehandle fileno and data from "read" events.
51  
52 =cut
53  
54 1 ▶sub mux {
Subroutine mux: called CC=5 SCAR=19.6
Pod documented
55 1 my $self = shift;
56 1 my $event = $self->SUPER::mux(@_);
57
58 1 ▶ my $fh_id = ($event->{fh} && $event->{fh}->fileno) ? $event->{fh}->fileno : '-';
Branch: 1 branch
BranchTrueFalseTotal
$event->{'fh'} && $event->{'fh'}->fileno ? : 1 0 1
Condition33%1/3
$event->{"fh"} and $event->{"fh"}->fileno
!ll&&!rl&&r
001
MC/DC0%0/2
$event->{"fh"} and $event->{"fh"}->fileno
$event->{"fh"} $event->{"fh"}->fileno
Truth table33%1/3
A and B
A= $event->{"fh"}B= $event->{"fh"}->fileno
ABresult
0X0
100
111
59  
60 1 ▶ if ($event->{type} eq 'read') {
Branch: 2 branches
BranchTrueFalseTotal
if ($event->{'type'} eq 'read') { } 1 0 1
elsif ($event->{'type'} ne 'sent') { } 0 0 0
61 1 printf("%3s < %s\n", $fh_id, $event->{data});
62 }
63 elsif ($event->{type} ne 'sent') { # 'sent' events are distracting to me
64 0 printf("%3s : %s\n", $fh_id, $event->{type});
65 }
66  
67 1 return $event;
68 }
69  
70 =head1 AUTHOR
71  
72 José Micó <jose.mico@gmail.com>
73  
74 =head1 COPYRIGHT AND LICENCE
75  
76 Copyright 2009: José Micó
77  
78 This library is free software; you can redistribute it and/or modify
79 it under the same terms as Perl itself.
80  
81 =cut
82  
83 3 1;
« EventMux.pm ↑ Summary