diff options
author | Jarkko Hietaniemi <jhi@iki.fi> | 2001-11-14 21:55:51 +0000 |
---|---|---|
committer | Jarkko Hietaniemi <jhi@iki.fi> | 2001-11-14 21:55:51 +0000 |
commit | 271fb08e7248a5c6238f2dd42e6dc29065dd806f (patch) | |
tree | 54114c0a04889d7e647ce9297a4de9f4f1a809f1 /lib/Attribute | |
parent | 9246c65e7445d45babd69ada378ff7f5f266c771 (diff) | |
download | perl-271fb08e7248a5c6238f2dd42e6dc29065dd806f.tar.gz |
Upgrade to Attribute::Handlers 0.76.
p4raw-id: //depot/perl@13006
Diffstat (limited to 'lib/Attribute')
-rw-r--r-- | lib/Attribute/Handlers.pm | 39 | ||||
-rw-r--r-- | lib/Attribute/Handlers/Changes | 10 | ||||
-rw-r--r-- | lib/Attribute/Handlers/README | 19 | ||||
-rwxr-xr-x | lib/Attribute/Handlers/demo/Demo.pm | 1 | ||||
-rwxr-xr-x | lib/Attribute/Handlers/demo/Descriptions.pm | 1 | ||||
-rwxr-xr-x | lib/Attribute/Handlers/demo/MyClass.pm | 1 | ||||
-rwxr-xr-x | lib/Attribute/Handlers/demo/demo_cycle.pl | 14 | ||||
-rwxr-xr-x | lib/Attribute/Handlers/demo/demo_hashdir.pl | 2 | ||||
-rw-r--r-- | lib/Attribute/Handlers/t/multi.t | 2 |
9 files changed, 65 insertions, 24 deletions
diff --git a/lib/Attribute/Handlers.pm b/lib/Attribute/Handlers.pm index 5e8f86162c..59c0934373 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 4df4edb9e7..1b5e620482 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 e8f07833bd..c9e067c8e6 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 d82693574b..e763d23b90 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 e904dbb7f7..023f6f752f 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 60948eb42d..079b2cc3ad 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 771de94ea0..5f307a7036 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 2e7a4e285d..75e252b1a0 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 5f4e59e0ec..773606d55e 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}++; |