File Coverage

blib/lib/REFECO/Blockchain/Contract/Solidity/ABI/Type/Array.pm
Criterion Covered Total %
statement 48 50 96.0
branch 12 14 85.7
condition 6 8 75.0
subroutine 11 11 100.0
pod 1 6 16.6
total 78 89 87.6


line stmt bran cond sub pod time code
1              
2             use strict;
3 5     5   2360 use warnings;
  5         12  
  5         134  
4 5     5   24 no indirect;
  5         10  
  5         433  
5 5     5   38  
  5         11  
  5         25  
6             use Carp;
7 5     5   193 use parent qw(REFECO::Blockchain::Contract::Solidity::ABI::Type);
  5         10  
  5         341  
8 5     5   28  
  5         7  
  5         31  
9             my $self = shift;
10             return unless $self->data;
11 20     20 0 34  
12 20 100       68 for my $item ($self->data->@*) {
13             push $self->instances->@*,
14 17         39 REFECO::Blockchain::Contract::Solidity::ABI::Type::new_type(
15 36         90 signature => $self->remove_parent,
16             data => $item
17             );
18             }
19             }
20              
21             my $self = shift;
22             return $self->encoded if $self->encoded;
23              
24 39     39 0 66 my $length = scalar $self->data->@*;
25 39 100       100 # for dynamic length arrays the length must be included
26             $self->push_static($self->encode_length($length))
27 17         42 unless $self->fixed_length;
28              
29 17 100       52 croak "Invalid array size, signature @{[$self->fixed_length]}, data: $length"
30             if $self->fixed_length && $length > $self->fixed_length;
31              
32 17 100 100     40 my $offset = $self->get_initial_offset();
  1         4  
33              
34             for my $instance ($self->instances->@*) {
35 16         57 $self->push_static($self->encode_offset($offset))
36             if $instance->is_dynamic;
37 16         66  
38 32 100       66 $self->push_dynamic($instance->encode);
39             $offset += scalar $instance->encode()->@*;
40             }
41 32         73  
42 32         80 return $self->encoded;
43             }
44              
45 16         37 my $self = shift;
46             my @data = $self->data->@*;
47              
48             my $size = $self->fixed_length // shift $self->data->@*;
49 3     3 0 6 push $self->instances->@*, REFECO::Blockchain::Contract::Solidity::ABI::Type::new_type(signature => $self->remove_parent)
50 3         6 for 0 .. $size - 1;
51              
52 3   66     7 return $self->read_stack_set_data;
53             }
54 3         13  
55             my $self = shift;
56 3         20 $self->signature =~ /(\[(\d+)?\]$)/;
57             return substr $self->signature, 0, length($self->signature) - length($1 // '');
58             }
59              
60 43     43 0 70 my $self = shift;
61 43         96 if ($self->signature =~ /\[(\d+)?\]$/) {
62 43   50     98 return $1;
63             }
64             return undef;
65             }
66 44     44 1 68  
67 44 50       91 my $self = shift;
68 44         404 return 1 if $self->is_dynamic;
69              
70 0         0 my $size = $self->fixed_length;
71              
72             my $instance_size = 1;
73             for my $instance ($self->instances->@*) {
74 2     2 0 5 $instance_size += $instance->static_size;
75 2 50       4 }
76              
77 2         5 return $size * $instance_size;
78             }
79 2         4  
80 2         7 1;
81 0         0