File Coverage

blib/lib/Net/BitTorrent/Protocol/BEP06.pm
Criterion Covered Total %
statement 14 14 100.0
branch n/a
condition n/a
subroutine 5 5 100.0
pod n/a
total 19 19 100.0


line stmt bran cond sub pod time code
1 20     20   286 use v5.40;
  20         71  
2 20     20   150 use feature 'class';
  20         37  
  20         3272  
3 20     20   142 no warnings 'experimental::class';
  20         55  
  20         2200  
4 20     20   10158 class Net::BitTorrent::Protocol::BEP06 v2.0.0 : isa(Net::BitTorrent::Protocol::BEP55) {
  20         65  
  20         1392  
5              
6             # BEP 06 Message IDs
7             use constant {
8 20         12540 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 20     20   142 };
  20         43  
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             $self->_emit( suggest => unpack( 'N', $payload ) );
38             }
39             elsif ( $id == REJECT_REQUEST ) {
40             $self->_emit( reject => unpack( 'N N N', $payload ) );
41             }
42             elsif ( $id == ALLOWED_FAST ) {
43             $self->_emit( allowed_fast => unpack( 'N', $payload ) );
44             }
45             else {
46             $self->SUPER::_handle_message( $id, $payload );
47             }
48             }
49             } 1;