From: Jarkko Hietaniemi <jhi@iki.fi>
Date: Wed, 14 Nov 2001 21:55:51 +0000 (+0000)
Subject: Upgrade to Attribute::Handlers 0.76.
X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=271fb08e7248a5c6238f2dd42e6dc29065dd806f;p=p5sagit%2Fp5-mst-13.2.git

Upgrade to Attribute::Handlers 0.76.

p4raw-id: //depot/perl@13006
---

diff --git a/lib/Attribute/Handlers.pm b/lib/Attribute/Handlers.pm
index 5e8f861..59c0934 100644
--- a/lib/Attribute/Handlers.pm
+++ b/lib/Attribute/Handlers.pm
@@ -2,7 +2,7 @@ package Attribute::Handlers;
 use 5.006;
 use Carp;
 use warnings;
-$VERSION = '0.75';
+$VERSION = '0.76';
 # $DB::single=1;
 
 my %symcache;
@@ -44,8 +44,7 @@ sub import {
     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 @@ Attribute::Handlers - Simpler definition of attribute handlers
 
 =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 @@ variables. For example:
                 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 @@ could also be written:
 
         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.
diff --git a/lib/Attribute/Handlers/Changes b/lib/Attribute/Handlers/Changes
index 4df4edb..1b5e620 100644
--- a/lib/Attribute/Handlers/Changes
+++ b/lib/Attribute/Handlers/Changes
@@ -61,3 +61,13 @@ Revision history for Perl extension Attribute::Handlers
 	- 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).
diff --git a/lib/Attribute/Handlers/README b/lib/Attribute/Handlers/README
index e8f0783..c9e067c 100644
--- a/lib/Attribute/Handlers/README
+++ b/lib/Attribute/Handlers/README
@@ -1,5 +1,5 @@
 ==============================================================================
-                Release of version 0.75 of Attribute::Handlers
+                Release of version 0.76 of Attribute::Handlers
 ==============================================================================
 
 
@@ -51,22 +51,15 @@ COPYRIGHT
 
 ==============================================================================
 
-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).
 
 
 ==============================================================================
diff --git a/lib/Attribute/Handlers/demo/Demo.pm b/lib/Attribute/Handlers/demo/Demo.pm
index d826935..e763d23 100755
--- a/lib/Attribute/Handlers/demo/Demo.pm
+++ b/lib/Attribute/Handlers/demo/Demo.pm
@@ -1,6 +1,7 @@
 $DB::single = 1;
 
 package Demo;
+$VERSION = '1.00';
 use Attribute::Handlers;
 no warnings 'redefine';
 
diff --git a/lib/Attribute/Handlers/demo/Descriptions.pm b/lib/Attribute/Handlers/demo/Descriptions.pm
index e904dbb..023f6f7 100755
--- a/lib/Attribute/Handlers/demo/Descriptions.pm
+++ b/lib/Attribute/Handlers/demo/Descriptions.pm
@@ -1,4 +1,5 @@
 package Descriptions;
+$VERSION = '1.00';
 
 use Attribute::Handlers;
 
diff --git a/lib/Attribute/Handlers/demo/MyClass.pm b/lib/Attribute/Handlers/demo/MyClass.pm
index 60948eb..079b2cc 100755
--- a/lib/Attribute/Handlers/demo/MyClass.pm
+++ b/lib/Attribute/Handlers/demo/MyClass.pm
@@ -1,4 +1,5 @@
 package MyClass;
+$VERSION = '1.00';
 use v5.6.0;
 use base Attribute::Handlers;
 no warnings 'redefine';
diff --git a/lib/Attribute/Handlers/demo/demo_cycle.pl b/lib/Attribute/Handlers/demo/demo_cycle.pl
index 771de94..5f307a7 100755
--- a/lib/Attribute/Handlers/demo/demo_cycle.pl
+++ b/lib/Attribute/Handlers/demo/demo_cycle.pl
@@ -3,7 +3,12 @@ package Selfish;
 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 @@ package main;
 use Attribute::Handlers autotieref => { Selfish => Selfish };
 
 my $next : Selfish("me");
-
 print "$next\n";
+
+my $last : Selfish("you","them","who?");
+print "$last\n";
+
+my $other : Selfish(["you","them","who?"]);
+print "$other\n";
diff --git a/lib/Attribute/Handlers/demo/demo_hashdir.pl b/lib/Attribute/Handlers/demo/demo_hashdir.pl
index 2e7a4e2..75e252b 100755
--- a/lib/Attribute/Handlers/demo/demo_hashdir.pl
+++ b/lib/Attribute/Handlers/demo/demo_hashdir.pl
@@ -5,3 +5,5 @@ my %dot : Dir('.', DIR_UNLINK);
 print join "\n", keys %dot;
 
 delete $dot{killme};
+
+print join "\n", keys %dot;
diff --git a/lib/Attribute/Handlers/t/multi.t b/lib/Attribute/Handlers/t/multi.t
index 5f4e59e..773606d 100644
--- a/lib/Attribute/Handlers/t/multi.t
+++ b/lib/Attribute/Handlers/t/multi.t
@@ -126,6 +126,6 @@ $loud++;
 my @noisy : Noisy(34);
 $noisy[0]++;
 
-my %rowdy : Rowdy(37);
+my %rowdy : Rowdy(37,'this arg should be ignored');
 $rowdy{key}++;