blib/lib/Net/EGTS/Packet/Response.pm untested

filter: Statementstmt 0.0% 0 / 71 Branchbran 0.0% 0 / 10 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 11 Podpod n/a totaltotal 0.0% 0 / 92 CC 1 SCAR 6.9
CC
1
Cov
0%
BEGIN
2.0
BEGIN
2.0
BEGIN
2.0
CRAP 2.0
1 use utf8;
2  
3 package Net::EGTS::Packet::Response;
4 use namespace::autoclean;
5 use Mouse;
6 extends qw(Net::EGTS::Packet);
7  
8 use Carp;
9 use List::MoreUtils qw(natatime);
10  
11 use Net::EGTS::Types;
12 use Net::EGTS::Codes;
13 use Net::EGTS::Util qw(usize);
14  
15 # Response Packet ID
16 has RPID => is => 'rw', isa => 'USHORT';
17 # Processing Result
18 has PR => is => 'rw', isa => 'BYTE';
19 # Service Data Record
20 has SDR => is => 'rw', isa => 'Maybe[BINARY]';
21  
22 after 'decode' => sub {
23 my ($self) = @_;
24 use bytes;
25  
26 die 'Packet not EGTS_PT_RESPONSE type'
27 unless $self->PT == EGTS_PT_RESPONSE;
28  
29 return unless defined $self->SFRD;
30 return unless length $self->SFRD;
31  
32 my $bin = $self->SFRD;
33 $self->RPID( $self->nip(\$bin => 'S') );
34 $self->PR( $self->nip(\$bin => 'C') );
35 $self->SDR( $self->nip(\$bin => 'a*' => length($bin)) );
36 };
37  
38 before 'encode' => sub {
39 my ($self) = @_;
40 use bytes;
41  
42 die 'Packet not EGTS_PT_RESPONSE type'
43 unless $self->PT == EGTS_PT_RESPONSE;
44  
45 my $bin = pack 'S C' => $self->RPID, $self->PR;
46 $bin .= pack 'a*' => $self->SDR if defined $self->SDR;
47  
48 $self->SFRD( $bin );
49 };
50  
51 around BUILDARGS => sub {
52 my $orig = shift;
53 my $class = shift;
54 return $class->$orig( @_, PT => EGTS_PT_RESPONSE );
55 };
56  
57 augment as_debug => sub {
58 my ($self) = @_;
59 use bytes;
60  
61 my @bytes = ((unpack('B*', $self->SFRD)) =~ m{.{8}}g);
62  
63 my @str;
64 push @str => sprintf('RPID: %s %s', splice @bytes, 0 => usize('S'));
65 push @str => sprintf('PR: %s', splice @bytes, 0 => usize('C'));
66  
67 my $it = natatime 4, @bytes;
68 my @chunks;
69 while (my @vals = $it->()) {
70 push @chunks, join(' ', @vals);
71 }
72 push @str => sprintf('SDR: %s', join("\n ", @chunks));
73  
74 return @str;
75 };
76  
77 __PACKAGE__->meta->make_immutable();