Skip to content

Commit 7a2b6ad

Browse files
committed
perltie.pod: rework example code so EXTEND is a no-op
Most tied array implementations can and should NO-OP the EXTEND method, and the sample code should not conflate EXTEND with STORESIZE. EXTEND is actually less usefull used by the core than it could be as AvMAX() does not have an equivalent tied method. So we cannot check if we need to extend. This is related to [rt.cpan.org #39196] / Issue #17496.
1 parent d8e1e69 commit 7a2b6ad

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

pod/perltie.pod

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ spaces so we have a little more work to do here:
301301
croak "length of $value is greater than $self->{ELEMSIZE}";
302302
}
303303
# fill in the blanks
304-
$self->EXTEND( $index ) if $index > $self->FETCHSIZE();
304+
$self->STORESIZE( $index ) if $index > $self->FETCHSIZE();
305305
# right justify to keep element size for smaller elements
306306
$self->{ARRAY}->[$index] = sprintf "%$self->{ELEMSIZE}s", $value;
307307
}
@@ -351,16 +351,24 @@ X<EXTEND>
351351
Informative call that array is likely to grow to have I<count> entries.
352352
Can be used to optimize allocation. This method need do nothing.
353353

354-
In our example, we want to make sure there are no blank (C<undef>)
355-
entries, so C<EXTEND> will make use of C<STORESIZE> to fill elements
356-
as needed:
354+
In our example there is no reason to implement this method, so we leave
355+
it as a no-op. This method is only relevant to tied array implementations
356+
where there is the possibility of having the allocated size of the array
357+
be larger than is visible to a perl programmer inspecting the size of the
358+
array. Many tied array implementations will have no reason to implement it.
357359

358360
sub EXTEND {
359361
my $self = shift;
360362
my $count = shift;
361-
$self->STORESIZE( $count );
363+
# nothing to see here, move along.
362364
}
363365

366+
B<NOTE:> It is generally an error to make this equivalent to STORESIZE.
367+
Perl may from time to time call EXTEND without wanting to actually change
368+
the array size directly. Any tied array should function correctly if this
369+
method is a no-op, even if perhaps they might not be as efficient as they
370+
would if this method was implemented.
371+
364372
=item EXISTS this, key
365373
X<EXISTS>
366374

0 commit comments

Comments
 (0)