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