1package FFI::Platypus::Record::TieArray;
2
3use strict;
4use warnings;
5use 5.008004;
6use Carp qw( croak );
7
8# ABSTRACT: Tied array interface for record array members
9our $VERSION = '1.56'; # VERSION
10
11
12sub TIEARRAY
13{
14  my $class = shift;
15  bless [ @_ ], $class;
16}
17
18sub FETCH
19{
20  my($self, $key) = @_;
21  my($obj, $member) = @$self;
22  $obj->$member($key);
23}
24
25sub STORE
26{
27  my($self, $key, $value) = @_;
28  my($obj, $member) = @$self;
29  $obj->$member($key, $value);
30}
31
32sub FETCHSIZE
33{
34  my($self) = @_;
35  $self->[2];
36}
37
38sub CLEAR
39{
40  my($self) = @_;
41  my($obj, $member) = @$self;
42
43  $obj->$member([]);
44}
45
46sub EXTEND
47{
48  my($self, $count) = @_;
49  croak "tried to extend a fixed length array" if $count > $self->[2];
50}
51
521;
53
54__END__
55
56=pod
57
58=encoding UTF-8
59
60=head1 NAME
61
62FFI::Platypus::Record::TieArray - Tied array interface for record array members
63
64=head1 VERSION
65
66version 1.56
67
68=head1 SYNOPSIS
69
70 package Foo;
71
72 use FFI::Platypus::Record;
73 use FFI::Platypus::Record::TieArray;
74
75 record_layout(qw(
76   int[20]  _bar
77 ));
78
79 sub bar
80 {
81   my($self, $arg) = @_;
82   $self->_bar($arg) if ref($arg) eq ' ARRAY';
83   tie my @list, 'FFI::Platypus::Record::TieArray',
84     $self, '_bar', 20;
85 }
86
87 package main;
88
89 my $foo = Foo->new;
90
91 my $bar5 = $foo->bar->[5];  # get the 5th element of the bar array
92 $foo->bar->[5] = 10;        # set the 5th element of the bar array
93 @{ $foo->bar } = ();        # set all elements in bar to 0
94 @{ $foo->bar } = (1..5);    # set the first five elements of the bar array
95
96=head1 DESCRIPTION
97
98B<WARNING>: This module is considered EXPERIMENTAL.  It may go away or
99be changed in incompatible ways, possibly without notice, but not
100without a good reason.
101
102This class provides a tie interface for record array members.
103
104In the future a short cut for using this with L<FFI::Platypus::Record>
105directly may be provided.
106
107=head1 SEE ALSO
108
109=over 4
110
111=item L<FFI::Platypus>
112
113The main Platypus documentation.
114
115=item L<FFI::Platypus::Record>
116
117Documentation on Platypus records.
118
119=back
120
121=head1 AUTHOR
122
123Author: Graham Ollis E<lt>plicease@cpan.orgE<gt>
124
125Contributors:
126
127Bakkiaraj Murugesan (bakkiaraj)
128
129Dylan Cali (calid)
130
131pipcet
132
133Zaki Mughal (zmughal)
134
135Fitz Elliott (felliott)
136
137Vickenty Fesunov (vyf)
138
139Gregor Herrmann (gregoa)
140
141Shlomi Fish (shlomif)
142
143Damyan Ivanov
144
145Ilya Pavlov (Ilya33)
146
147Petr Písař (ppisar)
148
149Mohammad S Anwar (MANWAR)
150
151Håkon Hægland (hakonhagland, HAKONH)
152
153Meredith (merrilymeredith, MHOWARD)
154
155Diab Jerius (DJERIUS)
156
157Eric Brine (IKEGAMI)
158
159szTheory
160
161José Joaquín Atria (JJATRIA)
162
163Pete Houston (openstrike, HOUSTON)
164
165=head1 COPYRIGHT AND LICENSE
166
167This software is copyright (c) 2015,2016,2017,2018,2019,2020 by Graham Ollis.
168
169This is free software; you can redistribute it and/or modify it under
170the same terms as the Perl 5 programming language system itself.
171
172=cut
173