blib/lib/SPVM/Immutable/ByteList.pm untested

filter: Statementstmt n/a Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a SCAR -
1 package SPVM::Immutable::ByteList;
2  
3 1;
4  
5 =head1 Name
6  
7 SPVM::Immutable::ByteList - Immutable byte Array
8  
9 =head1 Description
10  
11 The Immutable::ByteList has methods to manipulate an immutable byte array.
12  
13 =head1 Usage
14
15 use Immutable::ByteList;
16
17 # Create a byte list
18 my $list = Immutable::ByteList->new;
19 my $list = Immutable::ByteList->new([(byte)1, 2, 3]);
20
21 # Create a byte list with array length
22 my $list = Immutable::ByteList->new_len(10);
23
24 # Get list length
25 my $length = $list->length;
26
27 # Get value.
28 my $element = $list->get(2);
29
30 # Convert list to array.
31 my $array = $list->to_array;
32
33 =head1 Fields
34  
35 =head2 length
36  
37 has length : ro int;
38  
39 Gets the C<length> field.
40  
41 This field is the length of the elements of the list.
42  
43 =head1 Class Methods
44  
45 =head2 new
46  
47 C<static method new : L<Immutable::ByteList|SPVM::Immutable::ByteList> ($array : byte[] = undef);>
48  
49 Creates a new L<Immutable::ByteList|SPVM::Immutable::ByteList> object using L</"new_len">.
50  
51 The passed length to L</"new_len"> is the length of $array. If the array is undef, the length is 0.
52  
53 The elements of $array are copied to the elements of the the created array.
54  
55 Examples:
56  
57 my $list = Immutable::ByteList->new;
58 my $list = Immutable::ByteList->new([(byte)1, 2, 3]);
59  
60 =head2 new_len
61  
62 C<static method new_len : L<Immutable::ByteList|SPVM::Immutable::ByteList> ($length : int);>
63  
64 Creates a new L<Immutable::ByteList|SPVM::Immutable::ByteList> object with $length.
65  
66 Exceptions:
67  
68 $length must be greater than or equal to 0. Otherwise an exception is thrown.
69  
70 =head1 Instance Methods
71  
72 =head2 get
73  
74 C<method get : int ($index : int);>
75  
76 Gets the element of the position of $index.
77  
78 If $index is a netative value, $index is set to L</"length"> plus $index.
79  
80 Exceptions:
81  
82 $index must be greater than or equal to 0. Otherwise an exception is thrown.
83  
84 $index must be less than the length of $list. Otherwise an exception is thrown.
85  
86 =head2 to_array
87  
88 C<method to_array : byte[] ();>
89  
90 Converts the list to an array.
91  
92 =head1 Copyright & License
93  
94 Copyright (c) 2023 Yuki Kimoto
95  
96 MIT License