package SlackBuild::Base; use strict; use warnings; use Carp; use parent 'Exporter'; no strict 'refs'; sub import { my $pkg = shift; # package my ($package, $filename, $line) = caller; foreach my $dfn (@_) { if ($dfn =~ m/^(?[a-zA-Z_][a-zA-Z_0-9]*) (?::(?.*))?$/x) { my $attribute = $+{attr}; my $flag = $+{flag} || 'rw'; if ($flag eq 'ro') { *{ $package . '::' . $attribute } = sub { my $self = shift; croak "too many arguments for ${package}::$attribute" if @_; return $self->{$attribute}; } } else { *{ $package . '::' . $attribute } = sub { my $self = shift; if (@_) { croak "too many arguments for ${package}::$attribute" if @_ > 1; $self->{$attribute} = shift; } return $self->{$attribute}; } } } else { croak "$filename:$line: bad attribute spec: $dfn" } } } 1;