| 1 |
use Test2::V0 -no_srand => 1; |
| 2 |
|
| 3 |
do { |
| 4 |
package |
| 5 |
Foo; |
| 6 |
|
| 7 |
use FFI::Platypus::Record; |
| 8 |
use FFI::Platypus::Record::TieArray; |
| 9 |
|
| 10 |
record_layout(qw( |
| 11 |
int[20] _bar |
| 12 |
)); |
| 13 |
|
| 14 |
sub bar |
| 15 |
{ |
| 16 |
my($self) = @_; |
| 17 |
tie my @list, 'FFI::Platypus::Record::TieArray', $self, '_bar', 20; |
| 18 |
\@list; |
| 19 |
} |
| 20 |
}; |
| 21 |
|
| 22 |
|
| 23 |
my $foo = Foo->new( _bar => [1..20] ); |
| 24 |
isa_ok $foo, 'Foo'; |
| 25 |
|
| 26 |
is $foo->bar->[1], 2; |
| 27 |
$foo->bar->[1] = 22; |
| 28 |
is $foo->bar->[1], 22; |
| 29 |
|
| 30 |
is scalar(@{ $foo->bar }), 20; |
| 31 |
is $#{ $foo->bar}, 19; |
| 32 |
|
| 33 |
@{ $foo->bar } = (); |
| 34 |
|
| 35 |
is $foo->bar->[$_], 0 for 0..19; |
| 36 |
|
| 37 |
@{ $foo->bar } = (0..5); |
| 38 |
|
| 39 |
is $foo->bar->[$_], $_ for 0..5; |
| 40 |
is $foo->bar->[$_], 0 for 6..19; |
| 41 |
|
| 42 |
done_testing; |