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/27 03:39:15 UTC

[lucy-commits] svn commit: r1074974 - in /incubator/lucy/trunk/clownfish: lib/Clownfish/Class.pm lib/Clownfish/Parser.pm t/400-class.t

Author: marvin
Date: Sun Feb 27 02:39:15 2011
New Revision: 1074974

URL: http://svn.apache.org/viewvc?rev=1074974&view=rev
Log:
Replace "attributes" param to CFCClass constructor with add_attribute().

Modified:
    incubator/lucy/trunk/clownfish/lib/Clownfish/Class.pm
    incubator/lucy/trunk/clownfish/lib/Clownfish/Parser.pm
    incubator/lucy/trunk/clownfish/t/400-class.t

Modified: incubator/lucy/trunk/clownfish/lib/Clownfish/Class.pm
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/clownfish/lib/Clownfish/Class.pm?rev=1074974&r1=1074973&r2=1074974&view=diff
==============================================================================
--- incubator/lucy/trunk/clownfish/lib/Clownfish/Class.pm (original)
+++ incubator/lucy/trunk/clownfish/lib/Clownfish/Class.pm Sun Feb 27 02:39:15 2011
@@ -43,7 +43,6 @@ our %create_PARAMS = (
     inert             => undef,
     final             => undef,
     parcel            => undef,
-    attributes        => undef,
     exposure          => 'parcel',
 );
 
@@ -89,11 +88,6 @@ sub create {
     $args{inert} ||= 0;
     $args{final} ||= 0;
 
-    # Validate attributes.
-    my $attributes = delete $args{attributes} || {};
-    confess("Param 'attributes' not a hashref")
-        unless reftype($attributes) eq 'HASH';
-
     my $package = ref($either) || $either;
     $args{parcel} = Clownfish::Parcel->acquire( $args{parcel} );
     $args{exposure}  ||= 'parcel';
@@ -102,7 +96,7 @@ sub create {
         @args{qw( parcel exposure class_name class_cnick micro_sym
         docucomment source_class parent_class_name final inert )} );
 
-    $attributes{$self}        = $attributes;
+    $attributes{$self}        = {};
     $methods{$self}           = [];
     $overridden{$self}        = {};
 
@@ -127,6 +121,11 @@ sub DESTROY {
     $self->_destroy;
 }
 
+sub add_attribute { 
+    my ($self, $var, $value ) = @_;
+    $attributes{$self}->{$var} = $value; 
+}
+
 sub has_attribute { exists $_[0]->_get_attributes->{ $_[1] } }
 
 sub _get_attributes       { $attributes{ +shift } }
@@ -274,7 +273,6 @@ Retrieve a Class, if one has already bee
         parent_class_name => 'Crustacean::Claw', # default: undef
         inert             => undef,              # default: undef
         docucomment       => $documcom,          # default: undef,
-        attributes        => \%attributes,       # default: {}
     );
 
 Create and register a quasi-singleton.  May only be called once for each
@@ -297,8 +295,6 @@ instantiated.
 
 =item * B<docucomment> - A Clownfish::DocuComment describing this Class.
 
-=item * B<attributes> - An arbitrary hash of attributes.
-
 =back
 
 =head1 METHODS
@@ -345,6 +341,12 @@ Add a member variable to the class.  Val
 Add an inert (class) variable to the class.  Valid only before grow_tree() is
 called.
 
+=head2 add_attribute
+
+    $class->add_attribute($var, $value);
+
+Add an arbitrary attribute to the class.
+
 =head2 function 
 
     my $do_stuff_function = $class->function("do_stuff");

Modified: incubator/lucy/trunk/clownfish/lib/Clownfish/Parser.pm
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/clownfish/lib/Clownfish/Parser.pm?rev=1074974&r1=1074973&r2=1074974&view=diff
==============================================================================
--- incubator/lucy/trunk/clownfish/lib/Clownfish/Parser.pm (original)
+++ incubator/lucy/trunk/clownfish/lib/Clownfish/Parser.pm Sun Feb 27 02:39:15 2011
@@ -496,12 +496,14 @@ sub new_class {
         source_class      => $source_class,
         inert             => $class_modifiers{inert},
         final             => $class_modifiers{final},
-        attributes        => \%class_attributes,
     );
     $class->add_method($_)     for @methods;
     $class->add_function($_)   for @functions;
     $class->add_member_var($_) for @member_vars;
     $class->add_inert_var($_)  for @inert_vars;
+    while ( my ( $var, $val ) = each %class_attributes ) {
+        $class->add_attribute( $var, $val );
+    }
     return $class;
 }
 

Modified: incubator/lucy/trunk/clownfish/t/400-class.t
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/clownfish/t/400-class.t?rev=1074974&r1=1074973&r2=1074974&view=diff
==============================================================================
--- incubator/lucy/trunk/clownfish/t/400-class.t (original)
+++ incubator/lucy/trunk/clownfish/t/400-class.t Sun Feb 27 02:39:15 2011
@@ -62,8 +62,8 @@ my $foo_jr = Clownfish::Class->create(
     parcel            => 'Neato',
     class_name        => 'Foo::FooJr',
     parent_class_name => 'Foo',
-    attributes        => { dumpable => 1 },
 );
+$foo_jr->add_attribute( dumpable => 1 );
 
 ok( $foo_jr->has_attribute('dumpable'), 'has_attribute' );
 is( $foo_jr->get_struct_sym,  'FooJr',       "struct_sym" );
@@ -75,8 +75,8 @@ my $final_foo = Clownfish::Class->create
     parent_class_name => 'Foo::FooJr',
     source_class      => 'Foo::FooJr',
     final             => 1,
-    attributes        => { dumpable => 1 },
 );
+$final_foo->add_attribute( dumpable => 1 );
 ok( $final_foo->final, "final" );
 is( $final_foo->include_h, 'Foo/FooJr.h', "inlude_h uses source_class" );
 is( $final_foo->get_parent_class_name, 'Foo::FooJr',