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;