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 #### diff -Naur old/lib/Tie/Scalar.pm new/lib/Tie/Scalar.pm --- old/lib/Tie/Scalar.pm 2018-09-09 12:46:47.358881592 +0200 +++ new/lib/Tie/Scalar.pm 2018-09-09 13:01:56.916476269 +0200 @@ -1,51 +1,40 @@ package Tie::Scalar; -our $VERSION = '1.04'; +our $VERSION = '1.05'; =head1 NAME -Tie::Scalar, Tie::StdScalar - base class definitions for tied scalars +Tie::Scalar - base class definition for tied scalars =head1 SYNOPSIS package NewScalar; - require Tie::Scalar; - @ISA = qw(Tie::Scalar); + use strict; + use warnings; + use parent 'Tie::Scalar'; sub FETCH { ... } # Provide a needed method sub TIESCALAR { ... } # Overrides inherited method - - package NewStdScalar; - require Tie::Scalar; - - @ISA = qw(Tie::StdScalar); - - # All methods provided by default, so define - # only what needs be overridden - sub FETCH { ... } - - package main; + use strict; + use warnings; + tie $new_scalar, 'NewScalar'; - tie $new_std_scalar, 'NewStdScalar'; =head1 DESCRIPTION -This module provides some skeletal methods for scalar-tying classes. See +This class provides some skeletal methods for scalar-tying classes. See L for a list of the functions required in tying a scalar to a -package. The basic B package provides a C method, as well -as methods C, C and C. The B -package provides all the methods specified in L. It inherits from -B and causes scalars tied to it to behave exactly like the -built-in scalars, allowing for selective overloading of methods. The C +package. The class provides a C method, as well +as methods C, C and C. The C method is provided as a means of grandfathering, for classes that forget to provide their own C method. For developers wishing to write their own tied-scalar classes, the methods -are summarized below. The L section not only documents these, but +are summarized below. L not only documents these, but has sample code as well: =over 4 @@ -93,6 +82,8 @@ =cut +use strict; +use warnings; use Carp; use warnings::register; @@ -135,30 +126,5 @@ croak "$pkg doesn't define a STORE method"; } -# -# The Tie::StdScalar package provides scalars that behave exactly like -# Perl's built-in scalars. Good base to inherit from, if you're only going to -# tweak a small bit. -# -package Tie::StdScalar; -@ISA = qw(Tie::Scalar); - -sub TIESCALAR { - my $class = shift; - my $instance = @_ ? shift : undef; - return bless \$instance => $class; -} - -sub FETCH { - return ${$_[0]}; -} - -sub STORE { - ${$_[0]} = $_[1]; -} - -sub DESTROY { - undef ${$_[0]}; -} 1; diff -Naur old/lib/Tie/StdScalar.pm new/lib/Tie/StdScalar.pm --- old/lib/Tie/StdScalar.pm 1970-01-01 01:00:00.000000000 +0100 +++ new/lib/Tie/StdScalar.pm 2018-09-09 13:01:18.284477721 +0200 @@ -0,0 +1,75 @@ +package Tie::StdScalar; + +our $VERSION = '1.05'; + +=head1 NAME + +Tie::StdScalar - base class definition for tied scalars + +=head1 SYNOPSIS + + package NewStdScalar; + + use strict; + use warnings + use parent 'Tie::StdScalar'; + + # All methods provided by default, so define + # only what needs be overridden + sub FETCH { ... } + + package main; + + use strict; + use warnings + use NewStdScalar; + + tie $new_std_scalar, 'NewStdScalar'; + +=head1 DESCRIPTION + +This class provides all the methods specified in L. +It causes scalars tied to it to behave exactly like the +built-in scalars, allowing for selective overloading of methods. + +For developers wishing to write their own tied-scalar classes, the methods +are summarized in L. L not only documents these, but +has sample code as well. + +=head1 MORE INFORMATION + +The L section uses a good example of tying scalars by associating +process IDs with priority. + +See also L + +=cut + +use strict; +use warnings; + +# +# The Tie::StdScalar package provides scalars that behave exactly like +# Perl's built-in scalars. Good base to inherit from, if you're only going to +# tweak a small bit. +# + +sub TIESCALAR { + my $class = shift; + my $instance = @_ ? shift : undef; + return bless \$instance => $class; +} + +sub FETCH { + return ${$_[0]}; +} + +sub STORE { + ${$_[0]} = $_[1]; +} + +sub DESTROY { + undef ${$_[0]}; +} + +1;