blib/lib/SPVM/Immutable/StringList.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::StringList;
2  
3 1;
4  
5 =head1 Name
6  
7 SPVM::Immutable::StringList - Immutable string array
8  
9 =head1 Usage
10
11 use Immutable::StringList;
12
13 # Create a string list
14 my $list = Immutable::StringList->new;
15 my $list = Immutable::StringList->new(["abc", "def", "ghi"]);
16
17 # Create a string list
18 my $list = Immutable::StringList->new_len(10);
19
20 # Get list length
21 my $length = $list->length;
22
23 # Get string value.
24 my $element = $list->get(2);
25
26 # Convert Immutable::StringList to string array.
27 my $array = $list->to_array;
28  
29 =head1 Description
30  
31 The Immutable::StringList class has methods to manipulate an immutable string 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::StringList|SPVM::Immutable::StringList> ($array : string[] = undef);>
48  
49 Create a new L<Immutable::StringList|SPVM::Immutable::StringList> object using L</"new_len">.
50  
51 The passed length to L</"new_len"> is the length of the array. If the array is undef, the length is 0.
52  
53 The each string of the array is copied and to each value of the the created array and each string is made read-only.
54  
55 Examples:
56  
57 my $list = Immutable::StringList->new;
58 my $list = Immutable::StringList->new(["abc", "def", "ghi"]);
59  
60 =head2 new_len
61  
62 C<static method new_len : L<Immutable::StringList|SPVM::Immutable::StringList> ($length : int);>
63  
64 Creates a new L<Immutable::StringList|SPVM::Immutable::StringList> 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 : string ($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 : string[] ();>
89  
90 Converts the list to an array.
91  
92 =head1 Copyright & License
93  
94 Copyright (c) 2023 Yuki Kimoto
95  
96 MIT License