NetWare tweaks from Guruprasad.
[p5sagit/p5-mst-13.2.git] / lib / Class / Struct.pm
index 14d28fa..5c68bf3 100644 (file)
@@ -14,7 +14,7 @@ require Exporter;
 @ISA = qw(Exporter);
 @EXPORT = qw(struct);
 
-$VERSION = '0.59';
+$VERSION = '0.60';
 
 ## Tested on 5.002 and 5.003 without class membership tests:
 my $CHECK_CLASS_MEMBERSHIP = ($] >= 5.003_95);
@@ -54,10 +54,14 @@ sub printem {
 sub import {
     my $self = shift;
 
-    if ( @_ % 2 == 0 ) {
-      &struct;
-    } else {
+    if ( @_ == 0 ) {
       $self->export_to_level( 1, $self, @EXPORT );
+    } elsif ( @_ == 1 ) {
+       # This is admittedly a little bit silly:
+       # do we ever export anything else than 'struct'...?
+      $self->export_to_level( 1, $self, @_ );
+    } else {
+      &struct;
     }
 }
 
@@ -199,11 +203,13 @@ sub struct {
             if( defined $arrays{$name} ){
                 $out .= "    my \$i;\n";
                 $out .= "    \@_ ? (\$i = shift) : return \$r->$elem;\n"; 
+                $out .= "    if (ref(\$i) eq 'ARRAY' && !\@_) { \$r->$elem = \$i; return \$r }\n";
                 $sel = "->[\$i]";
             }
             elsif( defined $hashes{$name} ){
                 $out .= "    my \$i;\n";
-                $out .= "    \@_ ? (\$i = shift) : return \$r->$elem;\n"; 
+                $out .= "    \@_ ? (\$i = shift) : return \$r->$elem;\n";
+                $out .= "    if (ref(\$i) eq 'HASH' && !\@_) { \$r->$elem = \$i; return \$r }\n";
                 $sel = "->{\$i}";
             }
             elsif( defined $classes{$name} ){
@@ -357,7 +363,7 @@ optionally preceded by a C<'*'>.
 The accessor method provided by C<struct> for an element depends
 on the declared type of the element.
 
-=over
+=over 4
 
 =item Scalar (C<'$'> or C<'*$'>)
 
@@ -385,6 +391,10 @@ is C<'@'>, the accessor returns the array element value.  If the
 element type is C<'*@'>, a reference to the array element is
 returned.
 
+As a special case, when the accessor is called with an array reference
+as the sole argument, this causes an assignment of the whole array element.
+The object reference is returned.
+
 =item Hash (C<'%'> or C<'*%'>)
 
 The element is a hash, initialized by default to C<()>.
@@ -399,6 +409,10 @@ assigned to the hash element.  If the element type is C<'%'>, the
 accessor returns the hash element value.  If the element type is
 C<'*%'>, a reference to the hash element is returned.
 
+As a special case, when the accessor is called with a hash reference
+as the sole argument, this causes an assignment of the whole hash element.
+The object reference is returned.
+
 =item Class (C<'Class_Name'> or C<'*Class_Name'>)
 
 The element's value must be a reference blessed to the named
@@ -433,7 +447,7 @@ See Example 3 below for an example of initialization.
 
 =head1 EXAMPLES
 
-=over
+=over 4
 
 =item Example 1
 
@@ -542,7 +556,7 @@ struct's constructor.
 
 =head1 Author and Modification History
 
-Modified by Casey Tweten, 2000-11-08, v0.59.
+Modified by Casey West, 2000-11-08, v0.59.
 
     Added the ability for compile time class creation.