On Fri, Jun 29, 2001 at 12:14:23AM -0400, Richard J. Barbalace wrote:
> I don't really want to export the variables; I'm not modifying them in
> the parent package, just copying and expanding them in the inheriting
> package.

Well then, you are copying and modifying as simply as it can be done. 
Again, though, I would avoid using variables like that, and instead go for a
class method approach:

    package Foo;

    sub attributes { return (foo => undef) }

    sub set {
        my($self, $attribute, $value) = (shift, shift, shift);
        my %attr = $self->attributes;
        if (defined $attr{$attribute}) {
            ...
        } else {
            ...
        }
    }


    package Foo::Bar

    use base qw(Foo);

    sub attributes {
        my $self = shift;
        return ($self->SUPER::attributes(), foo_bar => '.*')
    }


This will get costly, so perhaps some caching is in order.  The point is,
classes shouldn't be getting to class data except through class methods.


> I have not been able to find a perl module that would allow this sort
> of inheritance and data validation; does anyone know of one that does
> this?  Or can anyone suggest a better way of doing what I want?

If you haven't already, you should check the Class:: modules on CPAN to see
if something already does this.  However, data validation is so arbitrary
that the closest you can get is probably something that sets up your
inherited accessors and then calls back to your code, if you provide it, for
verifying the data.


Michael
--
Administrator                      www.shoebox.net
Programmer, System Administrator   www.gallanttech.com
--

Reply via email to