Change 13006 by jhi@alpha on 2001/11/14 21:55:51
Upgrade to Attribute::Handlers 0.76.
Affected files ...
.... //depot/perl/lib/Attribute/Handlers.pm#8 edit
.... //depot/perl/lib/Attribute/Handlers/Changes#3 edit
.... //depot/perl/lib/Attribute/Handlers/README#3 edit
.... //depot/perl/lib/Attribute/Handlers/demo/Demo.pm#3 edit
.... //depot/perl/lib/Attribute/Handlers/demo/Descriptions.pm#3 edit
.... //depot/perl/lib/Attribute/Handlers/demo/MyClass.pm#3 edit
.... //depot/perl/lib/Attribute/Handlers/demo/demo_cycle.pl#3 edit
.... //depot/perl/lib/Attribute/Handlers/demo/demo_hashdir.pl#3 edit
.... //depot/perl/lib/Attribute/Handlers/t/multi.t#2 edit
Differences ...
==== //depot/perl/lib/Attribute/Handlers.pm#8 (text) ====
Index: perl/lib/Attribute/Handlers.pm
--- perl/lib/Attribute/Handlers.pm.~1~ Wed Nov 14 15:00:06 2001
+++ perl/lib/Attribute/Handlers.pm Wed Nov 14 15:00:06 2001
@@ -2,7 +2,7 @@
use 5.006;
use Carp;
use warnings;
-$VERSION = '0.75';
+$VERSION = '0.76';
# $DB::single=1;
my %symcache;
@@ -44,8 +44,7 @@
while (@_) {
my $cmd = shift;
if ($cmd =~ /^autotie((?:ref)?)$/) {
- my $tiedata = '($was_arrayref ? $data : @$data)';
- $tiedata = ($1 ? '$ref, ' : '') . $tiedata;
+ my $tiedata = ($1 ? '$ref, ' : '') . '@$data';
my $mapping = shift;
_usage_AH_ $class unless ref($mapping) eq 'HASH';
while (my($attr, $tieclass) = each %$mapping) {
@@ -187,8 +186,8 @@
=head1 VERSION
-This document describes version 0.75 of Attribute::Handlers,
-released September 3, 2001.
+This document describes version 0.76 of Attribute::Handlers,
+released November 15, 2001.
=head1 SYNOPSIS
@@ -502,9 +501,28 @@
print $next;
}
-In fact, this pattern is so widely applicable that Attribute::Handlers
+Note that, because the C<Cycle> attribute receives its arguments in the
+C<$data> variable, if the attribute is given a list of arguments, C<$data>
+will consist of a single array reference; otherwise, it will consist of the
+single argument directly. Since Tie::Cycle requires its cycling values to
+be passed as an array reference, this means that we need to wrap
+non-array-reference arguments in an array constructor:
+
+ $data = [ $data ] unless ref $data eq 'ARRAY';
+
+Typically, however, things are the other way around: the tieable class expects
+its arguments as a flattened list, so the attribute looks like:
+
+ sub UNIVERSAL::Cycle : ATTR(SCALAR) {
+ my ($package, $symbol, $referent, $attr, $data, $phase) = @_;
+ my @data = ref $data eq 'ARRAY' ? @$data : $data;
+ tie $$referent, 'Tie::Whatever', @data;
+ }
+
+
+This software pattern is so widely applicable that Attribute::Handlers
provides a way to automate it: specifying C<'autotie'> in the
-C<use Attribute::Handlers> statement. So, the previous example,
+C<use Attribute::Handlers> statement. So, the cycling example,
could also be written:
use Attribute::Handlers autotie => { Cycle => 'Tie::Cycle' };
@@ -513,11 +531,16 @@
package main;
- my $next : Cycle('A'..'Z'); # $next is now a tied variable
+ my $next : Cycle(['A'..'Z']); # $next is now a tied variable
while (<>) {
print $next;
+Note that we now have to pass the cycling values as an array reference,
+since the C<autotie> mechanism passes C<tie> a list of arguments as a list
+(as in the Tie::Whatever example), I<not> as an array reference (as in
+the original Tie::Cycle example at the start of this section).
+
The argument after C<'autotie'> is a reference to a hash in which each key is
the name of an attribute to be created, and each value is the class to which
variables ascribed that attribute should be tied.
==== //depot/perl/lib/Attribute/Handlers/Changes#3 (text) ====
Index: perl/lib/Attribute/Handlers/Changes
--- perl/lib/Attribute/Handlers/Changes.~1~ Wed Nov 14 15:00:06 2001
+++ perl/lib/Attribute/Handlers/Changes Wed Nov 14 15:00:06 2001
@@ -61,3 +61,13 @@
- Changed licence for inclusion in core distribution
- Fixed 'autotie' for tied classes with multi-level names (thanks Jeff)
+
+
+0.76 Thu Nov 15 06:31:51 2001
+
+ - Fixed documentation nit (thanks Rick)
+
+ - Improving intuitiveness of autotie mechanism (thanks Marcel)
+
+ - Added $VERSION numbrs to demo modules (seems bizarre to me, but
+ they're core too now).
==== //depot/perl/lib/Attribute/Handlers/README#3 (text) ====
Index: perl/lib/Attribute/Handlers/README
--- perl/lib/Attribute/Handlers/README.~1~ Wed Nov 14 15:00:06 2001
+++ perl/lib/Attribute/Handlers/README Wed Nov 14 15:00:06 2001
@@ -1,5 +1,5 @@
==============================================================================
- Release of version 0.75 of Attribute::Handlers
+ Release of version 0.76 of Attribute::Handlers
==============================================================================
@@ -51,22 +51,15 @@
==============================================================================
-CHANGES IN VERSION 0.75
+CHANGES IN VERSION 0.76
- - Cleaned up AUTOLOAD
+ - Fixed documentation nit (thanks Rick)
- - Numerous bug fixes (thanks Pete)
+ - Improving intuitiveness of autotie mechanism (thanks Marcel)
- - Fixed handling of attribute data that includes a newline (thanks Pete)
-
- - Added "autotieref" option (thanks Pete)
-
- - Switched off $DB::single
-
- - Changed licence for inclusion in core distribution
-
- - Fixed 'autotie' for tied classes with multi-level names (thanks Jeff)
+ - Added $VERSION numbrs to demo modules (seems bizarre to me, but
+ they're core too now).
==============================================================================
==== //depot/perl/lib/Attribute/Handlers/demo/Demo.pm#3 (xtext) ====
Index: perl/lib/Attribute/Handlers/demo/Demo.pm
--- perl/lib/Attribute/Handlers/demo/Demo.pm.~1~ Wed Nov 14 15:00:06 2001
+++ perl/lib/Attribute/Handlers/demo/Demo.pm Wed Nov 14 15:00:06 2001
@@ -1,6 +1,7 @@
$DB::single = 1;
package Demo;
+$VERSION = '1.00';
use Attribute::Handlers;
no warnings 'redefine';
==== //depot/perl/lib/Attribute/Handlers/demo/Descriptions.pm#3 (xtext) ====
Index: perl/lib/Attribute/Handlers/demo/Descriptions.pm
--- perl/lib/Attribute/Handlers/demo/Descriptions.pm.~1~ Wed Nov 14 15:00:06
2001
+++ perl/lib/Attribute/Handlers/demo/Descriptions.pm Wed Nov 14 15:00:06 2001
@@ -1,4 +1,5 @@
package Descriptions;
+$VERSION = '1.00';
use Attribute::Handlers;
==== //depot/perl/lib/Attribute/Handlers/demo/MyClass.pm#3 (xtext) ====
Index: perl/lib/Attribute/Handlers/demo/MyClass.pm
--- perl/lib/Attribute/Handlers/demo/MyClass.pm.~1~ Wed Nov 14 15:00:06 2001
+++ perl/lib/Attribute/Handlers/demo/MyClass.pm Wed Nov 14 15:00:06 2001
@@ -1,4 +1,5 @@
package MyClass;
+$VERSION = '1.00';
use v5.6.0;
use base Attribute::Handlers;
no warnings 'redefine';
==== //depot/perl/lib/Attribute/Handlers/demo/demo_cycle.pl#3 (xtext) ====
Index: perl/lib/Attribute/Handlers/demo/demo_cycle.pl
--- perl/lib/Attribute/Handlers/demo/demo_cycle.pl.~1~ Wed Nov 14 15:00:06 2001
+++ perl/lib/Attribute/Handlers/demo/demo_cycle.pl Wed Nov 14 15:00:06 2001
@@ -3,7 +3,12 @@
sub TIESCALAR {
use Data::Dumper 'Dumper';
print Dumper [ \@_ ];
- bless {}, $_[0];
+ bless [ @_[1..$#_] ], $_[0];
+}
+
+sub FETCH {
+ use Data::Dumper 'Dumper';
+ Dumper [ @{$_[0]} ];
}
package main;
@@ -11,5 +16,10 @@
use Attribute::Handlers autotieref => { Selfish => Selfish };
my $next : Selfish("me");
+print "$next\n";
+
+my $last : Selfish("you","them","who?");
+print "$last\n";
-print "$next\n";
+my $other : Selfish(["you","them","who?"]);
+print "$other\n";
==== //depot/perl/lib/Attribute/Handlers/demo/demo_hashdir.pl#3 (xtext) ====
Index: perl/lib/Attribute/Handlers/demo/demo_hashdir.pl
--- perl/lib/Attribute/Handlers/demo/demo_hashdir.pl.~1~ Wed Nov 14 15:00:06
2001
+++ perl/lib/Attribute/Handlers/demo/demo_hashdir.pl Wed Nov 14 15:00:06 2001
@@ -5,3 +5,5 @@
print join "\n", keys %dot;
delete $dot{killme};
+
+print join "\n", keys %dot;
==== //depot/perl/lib/Attribute/Handlers/t/multi.t#2 (text) ====
Index: perl/lib/Attribute/Handlers/t/multi.t
--- perl/lib/Attribute/Handlers/t/multi.t.~1~ Wed Nov 14 15:00:06 2001
+++ perl/lib/Attribute/Handlers/t/multi.t Wed Nov 14 15:00:06 2001
@@ -126,6 +126,6 @@
my @noisy : Noisy(34);
$noisy[0]++;
-my %rowdy : Rowdy(37);
+my %rowdy : Rowdy(37,'this arg should be ignored');
$rowdy{key}++;
End of Patch.