@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);
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;
}
}
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} ){
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<'*$'>)
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<()>.
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
=head1 EXAMPLES
-=over
+=over 4
=item Example 1
=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.