blib/lib/Net/BitTorrent/Protocol/BEP06.pm untested

filter: Statementstmt 0.0% 0 / 29 Branchbran 0.0% 0 / 16 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 4 Podpod n/a totaltotal 0.0% 0 / 49 SCAR 6.9
CC
1
Cov
0%
BEGIN
2.0
BEGIN
2.0
BEGIN
2.0
CRAP 2.0
1 use v5.40;
2 use feature 'class';
3 no warnings 'experimental::class';
4 class Net::BitTorrent::Protocol::BEP06 v2.0.0 : isa(Net::BitTorrent::Protocol::BEP55) {
5  
6 # BEP 06 Message IDs
7 use constant {
8 HAVE_ALL => 0x0E, # 14
9 HAVE_NONE => 0x0F, # 15
10 SUGGEST_PIECE => 0x0D, # 13
11 REJECT_REQUEST => 0x10, # 16
12 ALLOWED_FAST => 0x11, # 17
13 };
14 method send_have_all () { $self->send_message(HAVE_ALL) }
15 method send_have_none () { $self->send_message(HAVE_NONE) }
16  
17 method send_suggest ($index) {
18 $self->send_message( SUGGEST_PIECE, pack( 'N', $index ) );
19 }
20  
21 method send_reject ( $index, $begin, $length ) {
22 $self->send_message( REJECT_REQUEST, pack( 'N N N', $index, $begin, $length ) );
23 }
24  
25 method send_allowed_fast ($index) {
26 $self->send_message( ALLOWED_FAST, pack( 'N', $index ) );
27 }
28  
29 method _handle_message ( $id, $payload ) {
30 if ( $id == HAVE_ALL ) {
31 $self->_emit('have_all');
32 }
33 elsif ( $id == HAVE_NONE ) {
34 $self->_emit('have_none');
35 }
36 elsif ( $id == SUGGEST_PIECE ) {
37 return $self->_emit_log( 'warn', 'SUGGEST_PIECE payload too short' ) if length($payload) != 4;
38 $self->_emit( suggest => unpack( 'N', $payload ) );
39 }
40 elsif ( $id == REJECT_REQUEST ) {
41 return $self->_emit_log( 'warn', 'REJECT payload too short' ) if length($payload) != 12;
42 $self->_emit( reject => unpack( 'N N N', $payload ) );
43 }
44 elsif ( $id == ALLOWED_FAST ) {
45 return $self->_emit_log( 'warn', 'ALLOWED_FAST payload too short' ) if length($payload) != 4;
46 $self->_emit( allowed_fast => unpack( 'N', $payload ) );
47 }
48 else {
49 $self->SUPER::_handle_message( $id, $payload );
50 }
51 }
52 } 1;