[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index][Thread Index][Top&Search][Original]

Re: Class::Fields, a base/fields.pm rewrite



In <20000109005600.C22261@athens.aocn.com>, Michael G Schwern writes:
:For example, this is the import routine from fields.pm:
:
:sub import {
:    my $class = shift;
:    my $package = caller(0);
:    my $fields = \%{"$package\::FIELDS"};
:    my $fattr = ($attr{$package} ||= []);
:
:    foreach my $f (@_) {
:        if (my $fno = $fields->{$f}) {
:            require Carp;
:            if ($fattr->[$fno-1] & _INHERITED) {
:                Carp::carp("Hides field '$f' in base class") if $^W;
:            } else {
:                Carp::croak("Field name '$f' already in use");
:            }
:        }
:        $fields->{$f} = @$fattr + 1;
:        push(@$fattr, ($f =~ /^_/) ? _PRIVATE : _PUBLIC);
:    }
:}
:
:Not pleasent to look at, unclear what its doing and requires intimate
:understanding of what %attr is all about.

Doesn't seem _that_ difficult to me.

:
:Here's my proposed replacement:
:
:use Class::Fields::Fuxor;       # for add_fields()
:use Class::Fields::Attribs;     # for PUBLIC and PRIVATE
:sub import {
:    # Dump the class.
:    shift;
:        
:    my $package = caller(0);
:        
:    return SUCCESS unless @_;
:
:    add_fields($package, PRIVATE, grep {/^_/} @_);
:    add_fields($package, PUBLIC,  grep {!/^_/} @_);
:}

Note that this looks likely to change the order the fields are added.

Hugo


Follow-Ups from:
Michael G Schwern <schwern@pobox.com>
References to:
Michael G Schwern <schwern@pobox.com>
Gurusamy Sarathy <gsar@ActiveState.com>

[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index][Thread Index][Top&Search][Original]