diff -Naur old/lib/Tie/Array.pm new/lib/Tie/Array.pm --- old/lib/Tie/Array.pm 2018-09-09 12:21:08.579390275 +0200 +++ new/lib/Tie/Array.pm 2018-09-09 12:37:13.387307122 +0200 @@ -3,7 +3,8 @@ use 5.006_001; use strict; use Carp; -our $VERSION = '1.07'; +use Tie::StdArray; +our $VERSION = '1.08'; # Pod documentation after __END__ below. @@ -82,32 +83,6 @@ croak "$pkg doesn't define a DELETE method"; } -package Tie::StdArray; -our @ISA = 'Tie::Array'; - -sub TIEARRAY { bless [], $_[0] } -sub FETCHSIZE { scalar @{$_[0]} } -sub STORESIZE { $#{$_[0]} = $_[1]-1 } -sub STORE { $_[0]->[$_[1]] = $_[2] } -sub FETCH { $_[0]->[$_[1]] } -sub CLEAR { @{$_[0]} = () } -sub POP { pop(@{$_[0]}) } -sub PUSH { my $o = shift; push(@$o,@_) } -sub SHIFT { shift(@{$_[0]}) } -sub UNSHIFT { my $o = shift; unshift(@$o,@_) } -sub EXISTS { exists $_[0]->[$_[1]] } -sub DELETE { delete $_[0]->[$_[1]] } - -sub SPLICE -{ - my $ob = shift; - my $sz = $ob->FETCHSIZE; - my $off = @_ ? shift : 0; - $off += $sz if $off < 0; - my $len = @_ ? shift : $sz-$off; - return splice(@$ob,$off,$len,@_); -} - 1; __END__ @@ -119,8 +94,10 @@ =head1 SYNOPSIS package Tie::NewArray; - use Tie::Array; - @ISA = ('Tie::Array'); + + use strict; + use warnings; + use parent 'Tie::Array'; # mandatory methods sub TIEARRAY { ... } @@ -142,18 +119,13 @@ sub EXTEND { ... } sub DESTROY { ... } - package Tie::NewStdArray; - use Tie::Array; - - @ISA = ('Tie::StdArray'); - - # all methods provided by default - package main; + use strict; + use warnings; + use Tie::NewArray; + $object = tie @somearray,'Tie::NewArray'; - $object = tie @somearray,'Tie::StdArray'; - $object = tie @somearray,'Tie::NewStdArray'; @@ -168,11 +140,6 @@ C, C and C in terms of basic C, C, C, C. -The B package provides efficient methods required for tied arrays -which are implemented as blessed references to an "inner" perl array. -It inherits from B, and should cause tied arrays to behave exactly -like standard arrays, allowing for selective overloading of methods. - For developers wishing to write their own tied arrays, the required methods are briefly defined below. See the L section for more detailed descriptive, as well as example code: @@ -270,6 +237,37 @@ =back +=head1 Legacy + +Old versions of Tie::Array up to 1.07 included the class B, +requiring the following workaround to inherit from B: + + package NewStdArray; + + use strict; + use warnings; + + use Tie::Hash; + our @ISA = qw( Tie::StdHash ); + +To provide compatibility with old code, B automatically loads +B. + +New code should load and inherit from B and B +via C: + + package NewArray; + + use strict; + use warnings; + use parent 'Tie::Array'; + + package NewStdArray; + + use strict; + use warnings; + use parent 'Tie::StdArray'; + =head1 CAVEATS There is no support at present for tied @ISA. There is a potential conflict diff -Naur old/lib/Tie/StdArray.pm new/lib/Tie/StdArray.pm --- old/lib/Tie/StdArray.pm 1970-01-01 01:00:00.000000000 +0100 +++ new/lib/Tie/StdArray.pm 2018-09-09 12:43:12.403810384 +0200 @@ -0,0 +1,92 @@ +package Tie::StdArray; + +use 5.006_001; +use strict; +use Carp; +our $VERSION = '1.08'; + +# Pod documentation after __END__ below. + +sub DESTROY { } +sub EXTEND { } + +sub TIEARRAY { bless [], $_[0] } +sub FETCHSIZE { scalar @{$_[0]} } +sub STORESIZE { $#{$_[0]} = $_[1]-1 } +sub STORE { $_[0]->[$_[1]] = $_[2] } +sub FETCH { $_[0]->[$_[1]] } +sub CLEAR { @{$_[0]} = () } +sub POP { pop(@{$_[0]}) } +sub PUSH { my $o = shift; push(@$o,@_) } +sub SHIFT { shift(@{$_[0]}) } +sub UNSHIFT { my $o = shift; unshift(@$o,@_) } +sub EXISTS { exists $_[0]->[$_[1]] } +sub DELETE { delete $_[0]->[$_[1]] } + +sub SPLICE +{ + my $ob = shift; + my $sz = $ob->FETCHSIZE; + my $off = @_ ? shift : 0; + $off += $sz if $off < 0; + my $len = @_ ? shift : $sz-$off; + return splice(@$ob,$off,$len,@_); +} + +1; + +__END__ + +=head1 NAME + +Tie::StdArray - base class for tied arrays + +=head1 SYNOPSIS + + package Tie::NewStdArray; + + use strict; + use warnings; + use parent 'Tie::StdArray'; + + # all methods provided by default + + package main; + + use strict; + use warnings; + use Tie::NewStdArray; + + $object = tie @somearray,'Tie::NewStdArray'; + +=head1 DESCRIPTION + +This module provides methods for array-tying classes. See +L for a list of the functions required in order to tie an array +to a package. + +This class provides stub C, and C methods that do nothing, +and provides efficient methods required for tied arrays +which are implemented as blessed references to an "inner" perl array. +It should cause tied arrays to behave exactly +like standard arrays, allowing for selective overloading of methods. + +For developers wishing to write their own tied arrays, the required methods +are briefly defined in L. See the L section for more +detailed descriptive, as well as example code. + +=head1 MORE INFORMATION + +See L + +=head1 CAVEATS + +There is no support at present for tied @ISA. There is a potential conflict +between magic entries needed to notice setting of @ISA, and those needed to +implement 'tie'. + +=head1 AUTHOR + +Nick Ing-Simmons Enik@tiuk.ti.comE + +=cut