You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucy.apache.org by ma...@apache.org on 2011/02/01 06:01:33 UTC

[lucy-commits] svn commit: r1065909 - /incubator/lucy/trunk/clownfish/lib/Clownfish/Variable.pm

Author: marvin
Date: Tue Feb  1 05:01:33 2011
New Revision: 1065909

URL: http://svn.apache.org/viewvc?rev=1065909&view=rev
Log:
Change Clownfish::Variable to inside-out pattern.

Modified:
    incubator/lucy/trunk/clownfish/lib/Clownfish/Variable.pm

Modified: incubator/lucy/trunk/clownfish/lib/Clownfish/Variable.pm
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/clownfish/lib/Clownfish/Variable.pm?rev=1065909&r1=1065908&r2=1065909&view=diff
==============================================================================
--- incubator/lucy/trunk/clownfish/lib/Clownfish/Variable.pm (original)
+++ incubator/lucy/trunk/clownfish/lib/Clownfish/Variable.pm Tue Feb  1 05:01:33 2011
@@ -22,6 +22,8 @@ use Clownfish::Type;
 use Clownfish::Util qw( verify_args a_isa_b );
 use Carp;
 
+our %type;
+
 our %new_PARAMS = (
     type        => undef,
     micro_sym   => undef,
@@ -32,15 +34,22 @@ our %new_PARAMS = (
 );
 
 sub new {
-    my $either = shift;
-    verify_args( \%new_PARAMS, @_ ) or confess $@;
-    my $self = $either->SUPER::new( %new_PARAMS, @_ );
+    my ( $either, %args ) = @_;
+    verify_args( \%new_PARAMS, %args ) or confess $@;
+    my $type = delete $args{type};
     confess "invalid type"
-        unless a_isa_b( $self->get_type, "Clownfish::Type" );
+        unless a_isa_b( $type, "Clownfish::Type" );
+    my $self = $either->SUPER::new( %new_PARAMS, %args );
+    $type{$self} = $type;
     return $self;
 }
 
-sub get_type { shift->{type} }
+sub DESTROY {
+    my $self = shift;
+    delete $type{$self};
+}
+
+sub get_type { $type{ +shift } }
 
 sub equals {
     my ( $self, $other ) = @_;