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   1751 use v5.26;
  3         13  
4 3     3   35 use strict;
  3         6  
  3         84  
5 3     3   17 use warnings;
  3         7  
  3         74  
6 3     3   14 no indirect;
  3         6  
  3         17  
7              
8 3     3   225 use parent qw(Blockchain::Contract::Solidity::ABI::Type);
  3         8  
  3         16  
9              
10             sub encode {
11 11     11 0 20 my $self = shift;
12 11 100       50 return $self->encoded if $self->encoded;
13              
14 4         14 my $hex = unpack("H*", $self->data);
15              
16             # for dynamic length basic types the length must be included
17 4         25 $self->push_dynamic($self->encode_length(length(pack("H*", $hex))));
18 4         17 $self->push_dynamic($self->pad_right($hex));
19              
20 4         13 return $self->encoded;
21             }
22              
23             sub decode {
24 1     1 0 3 my $self = shift;
25 1         5 my @data = $self->data->@*;
26              
27 1         3 my $size = hex shift @data;
28 1         3 my $string_data = join('', @data);
29 1         7 my $packed_string = pack("H*", $string_data);
30 1         6 return substr($packed_string, 0, $size);
31             }
32              
33             1;
34