File Coverage

blib/lib/REFECO/Blockchain/Contract/Solidity/ABI/Type/Tuple.pm
Criterion Covered Total %
statement 51 51 100.0
branch 9 10 90.0
condition 1 2 50.0
subroutine 11 11 100.0
pod 0 5 0.0
total 72 79 91.1


line stmt bran cond sub pod time code
1             package REFECO::Blockchain::Contract::Solidity::ABI::Type::Tuple;
2              
3 5     5   91 use v5.26;
  5         19  
4 5     5   30 use strict;
  5         12  
  5         125  
5 5     5   26 use warnings;
  5         10  
  5         121  
6 5     5   36 no indirect;
  5         10  
  5         36  
7              
8 5     5   271 use Carp;
  5         13  
  5         325  
9 5     5   441 use parent qw(REFECO::Blockchain::Contract::Solidity::ABI::Type);
  5         305  
  5         26  
10              
11             sub configure {
12 33     33 0 70 my $self = shift;
13 33 100       103 return unless $self->data;
14              
15 8         30 my @splited_signatures = $self->split_tuple_signature->@*;
16              
17 8         38 for (my $sig_index = 0; $sig_index < @splited_signatures; $sig_index++) {
18 29         91 push $self->instances->@*,
19             REFECO::Blockchain::Contract::Solidity::ABI::Type::new_type(
20             signature => $splited_signatures[$sig_index],
21             data => $self->data->[$sig_index]);
22             }
23              
24             }
25              
26             sub split_tuple_signature {
27 18     18 0 33 my $self = shift;
28 18         53 my $tuple_signatures = substr($self->signature, 1, length($self->signature) - 2);
29 18         250 $tuple_signatures =~ s/((\((?>[^)(]*(?2)?)*\))|[^,()]*)(*SKIP),/$1\n/g;
30 18         78 my @types = split('\n', $tuple_signatures);
31 18         71 return \@types;
32             }
33              
34             sub encode {
35 35     35 0 91 my $self = shift;
36 35 100       100 return $self->encoded if $self->encoded;
37              
38 22         79 my $offset = $self->get_initial_offset;
39              
40 16         49 for my $instance ($self->instances->@*) {
41 50         160 $instance->encode;
42 50 100       154 if ($instance->is_dynamic) {
43 14         62 $self->push_static($self->encode_offset($offset));
44 14         38 $self->push_dynamic($instance->encoded);
45 14         44 $offset += scalar $instance->encoded->@*;
46 14         54 next;
47             }
48              
49 36         103 $self->push_static($instance->encoded);
50             }
51              
52 16         56 return $self->encoded;
53             }
54              
55             sub decode {
56 11     11 0 21 my $self = shift;
57              
58 11 100       29 unless (scalar $self->instances->@* > 0) {
59 4         17 push $self->instances->@*, REFECO::Blockchain::Contract::Solidity::ABI::Type::new_type(signature => $_) for $self->split_tuple_signature->@*;
60             }
61              
62 11         51 return $self->read_stack_set_data;
63             }
64              
65             sub static_size {
66 6     6 0 12 my $self = shift;
67 6 50       17 return 1 if $self->is_dynamic;
68 6         14 my $size = 1;
69 6         21 my $instance_size = 0;
70 6         16 for my $signature ($self->split_tuple_signature->@*) {
71 12         36 my $instance = REFECO::Blockchain::Contract::Solidity::ABI::Type::new_type(signature => $signature);
72 12   50     39 $instance_size += $instance->static_size // 0;
73             }
74              
75 6         19 return $size * $instance_size;
76             }
77              
78             1;
79