File Coverage

blib/lib/Blockchain/Contract/Solidity/ABI/Type/String.pm
Criterion Covered Total %
statement 26 26 100.0
branch 2 2 100.0
condition n/a
subroutine 7 7 100.0
pod 0 2 0.0
total 35 37 94.5


line stmt bran cond sub pod time code
1             package Blockchain::Contract::Solidity::ABI::Type::String;
2              
3 3     3   1778 use v5.26;
  3         12  
4 3     3   18 use strict;
  3         8  
  3         83  
5 3     3   17 use warnings;
  3         9  
  3         77  
6 3     3   17 no indirect;
  3         9  
  3         27  
7              
8 3     3   204 use parent qw(Blockchain::Contract::Solidity::ABI::Type);
  3         7  
  3         34  
9              
10             sub encode {
11 11     11 0 21 my $self = shift;
12 11 100       27 return $self->encoded if $self->encoded;
13              
14 4         18 my $hex = unpack("H*", $self->data);
15              
16             # for dynamic length basic types the length must be included
17 4         46 $self->push_dynamic($self->encode_length(length(pack("H*", $hex))));
18 4         20 $self->push_dynamic($self->pad_right($hex));
19              
20 4         14 return $self->encoded;
21             }
22              
23             sub decode {
24 1     1 0 2 my $self = shift;
25 1         5 my @data = $self->data->@*;
26              
27 1         2 my $size = hex shift @data;
28 1         4 my $string_data = join('', @data);
29 1         17 my $packed_string = pack("H*", $string_data);
30 1         6 return substr($packed_string, 0, $size);
31             }
32              
33             1;
34