blib/lib/IO/Socket/ByteCounter.pm

filter: Statementstmt 94.8% 55 / 58 Branchbran 35.7% 5 / 14 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 14 / 14 Podpod 25.0% 1 / 4 totaltotal 83.3% 75 / 90 CC 10 SCAR 13.5
CC
10
Cov
83%
record_bytes
8.7
import
2.1
_get_byte_size
2.0
CRAP 3.9
↑ Summary
1 package IO::Socket::ByteCounter;
2  
3 2 ▶use base 'IO::Socket';
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 2 our $VERSION = 0.3;
9  
10 2 ▶sub import {
Subroutine import: called CC=2 SCAR=7.6
11 2 ▶ shift->record_bytes(@_) if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 2 0 2
12 }
13  
14 4 ▶sub record_bytes {
Subroutine record_bytes: called CC=8 SCAR=21.7
Pod documented
15 4 my ( $self, @pkgs ) = @_;
16  
17 4 for my $pkg (@pkgs) {
18 2 ▶ $pkg = ref $pkg if ref $pkg;
Branch: 1 branch
BranchTrueFalseTotal
if ref $pkg 0 2 2
19  
20 2 my $inc = $pkg;
21 2 $inc =~ s{::}{/}g;
22 2 ▶ if ( !exists $INC{ $inc . '.pm' } ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $INC{$inc . '.pm'}) 0 2 2
23 0 eval "use $pkg;";
24 0 ▶ warn $@ if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
25 0 ▶ next if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
26 }
27  
28 2 ▶ no strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
29 2 ▶ next if ${"$pkg\::io_socket_bytecounter_on"};
Branch: 1 branch
BranchTrueFalseTotal
if ${"${pkg}::io_socket_bytecounter_on";} 0 2 2
30  
31 2 ▶ eval <<"OVERRIDE_END";
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine get_bytes_in: called CC=1 SCAR=0.0
Subroutine get_bytes_out: called CC=1 SCAR=0.0
Subroutine get_bytes_total: called CC=1 SCAR=0.0
Pod undocumented
Pod undocumented
Pod undocumented
32 \$$pkg\::io_socket_bytecounter_on = 1;
33 no warnings "redefine";
34  
35 #### IO::Socket methods ##
36 # IO::Socket::send
37 my \$send = \\&$pkg\::send;
38 \*$pkg\::send = sub {
39 my \$self = \$_[0];
40 \${\*\$self}{'io_socket_bytecounter_out'} += IO::Socket::ByteCounter->_get_byte_size(\$_[1]);
41 \$send->(\@_);
42 };
43  
44 # IO::Socket::recv
45 my \$recv = \\&$pkg\::recv;
46 \*$pkg\::recv = sub {
47 my \$self = \$_[0];
48 \${\*\$self}{'io_socket_bytecounter_in'} += \$_[2];
49 \$recv->(\@_);
50 };
51  
52 #### IO::Handle methods ##
53  
54  
55 #### new methods ##
56  
57 sub $pkg\::get_bytes_in {
58 my \$self = \$_[0];
59 \${\*\$self}{'io_socket_bytecounter_in'};
60 }
61  
62 sub $pkg\::get_bytes_out {
63 my \$self = \$_[0];
64 \${\*\$self}{'io_socket_bytecounter_out'};
65 }
66  
67 sub $pkg\::get_bytes_total {
68 my \$self = \$_[0];
69 \${\*\$self}{'io_socket_bytecounter_in'} + \${\*\$self}{'io_socket_bytecounter_out'};
70 }
71  
72 OVERRIDE_END
73 }
74  
75 4 ▶ return $@ ? 0 : 1;
Branch: 1 branch
BranchTrueFalseTotal
$@ ? : 0 4 4
76 }
77  
78 2 ▶sub _get_byte_size {
Subroutine _get_byte_size: called CC=2 SCAR=6.9
79 2 my ( $self, @strings ) = @_;
80 2 my $bytes = 0;
81  
82 {
83 2 ▶ use bytes;
Subroutine BEGIN: called CC=1 SCAR=0.0
84 2 for my $string (@strings) {
85 2 $bytes += length($string);
86 }
87 }
88  
89 2 return $bytes;
90 }
91  
92 2 1;
93  
94 __END__
↑ Summary