File Coverage

blib/lib/Blockchain/Ethereum/ABI/Type/String.pm
Criterion Covered Total %
statement 24 24 100.0
branch 2 2 100.0
condition n/a
subroutine 7 7 100.0
pod 2 2 100.0
total 35 35 100.0


line stmt bran cond sub pod time code
1             package Blockchain::Ethereum::ABI::Type::String;
2              
3 4     4   268373 use v5.26;
  4         17  
4 4     4   25 use strict;
  4         7  
  4         128  
5 4     4   21 use warnings;
  4         16  
  4         463  
6              
7             # ABSTRACT: Solidity string type interface
8             our $AUTHORITY = 'cpan:REFECO'; # AUTHORITY
9             our $VERSION = '0.021'; # VERSION
10              
11 4     4   28 use parent 'Blockchain::Ethereum::ABI::Type';
  4         9  
  4         32  
12              
13 5     5   26 sub _configure { return }
14              
15             sub encode {
16 11     11 1 20 my $self = shift;
17              
18 11 100       33 return $self->_encoded if $self->_encoded;
19              
20 4         20 my $hex = unpack("H*", $self->{data});
21              
22             # for dynamic length basic types the length must be included
23 4         231 $self->_push_dynamic($self->_encode_length(length(pack("H*", $hex))));
24 4         21 $self->_push_dynamic($self->pad_right($hex));
25              
26 4         14 return $self->_encoded;
27             }
28              
29             sub decode {
30 1     1 1 2 my $self = shift;
31              
32 1         4 my @data = $self->{data}->@*;
33              
34 1         4 my $size = hex shift @data;
35 1         4 my $string_data = join('', @data);
36 1         10 my $packed_string = pack("H*", $string_data);
37 1         10 return substr($packed_string, 0, $size);
38             }
39              
40             1;
41              
42             __END__