Subject: | Backwards compat broken in Pipeline::Store::ISA->get |
Hey James,
There's 2 bugs I've found in Pipeline::Store::ISA:
1. set / get stores multiple identical values in the 'isa_store'. this results in a get() returning the same object more than once.
2. get sometimes returns single objects in an arrayref (breaks backwards compat).
The patch attached fixes (1) with a hash, and (2) by checking the size of the array of objects found. It's as backwards compat as it's gonna get. If you are willing to break this (it was broken anyway since last time I used it ;-), you might fix (2) by simply returning the whole array of objects in get():
return @objs;
Haven't thought of the knock-on effects though...
hth,
-Steve
Only in Pipeline-3.09/lib/Pipeline/Store: #ISA.pm#
diff -ru Pipeline-3.09/lib/Pipeline/Store/ISA.pm Pipeline-3.09_01/lib/Pipeline/Store/ISA.pm
--- Pipeline-3.09/lib/Pipeline/Store/ISA.pm Fri Apr 2 13:37:37 2004
+++ Pipeline-3.09_01/lib/Pipeline/Store/ISA.pm Fri Apr 2 13:34:43 2004
@@ -8,7 +8,7 @@
use Class::ISA;
-our $VERSION=3.09;
+our $VERSION=3.09_01;
sub init {
my $self = shift;
@@ -43,9 +43,10 @@
my $store = $self->isa_store;
foreach my $isa (@isa) {
if (!exists $self->isa_store->{ $isa }) {
- $store->{ $isa } = [];
+ $store->{ $isa } = {};
}
- push @{$store->{ $isa }}, ref($obj);
+ $store->{ $isa }->{ ref($obj) } = 1;
+ #push @{$store->{ $isa }}, ref($obj);
}
$self->obj_store->{ref($obj)} = $obj;
$self->emit("setting object " . ref($obj));
@@ -63,10 +64,11 @@
return $self->obj_store->{ $key };
} elsif (exists( $self->isa_store->{$key})) {
my @objs;
- foreach my $thing ( @{$self->isa_store->{ $key }} ) {
+ foreach my $thing ( keys %{$self->isa_store->{ $key }} ) {
push @objs, $self->get( $thing );
}
- return [ @objs ];
+ return [ @objs ] if (@objs > 1);
+ return @objs;
} else {
$self->emit("no object $key");
return undef;
@@ -106,7 +108,8 @@
=item set( OBJECT )
-The C<set> method stores an object specified by OBJECT in itself.
+The C<set> method stores an object specified by OBJECT in itself. Replaces
+existing objects of the same type.
=item get( SCALAR )