| GRID-Machine documentation | Contained in the GRID-Machine distribution. |
GRID::Machine::MakeAccessors - Home Made "Make accessors" for a Class
GRID::Machine::MakeAccessors::make_accessors($package, @legalattributes)
Builds getter-setters for each attribute
GRID::Machine::MakeAccessors::make_constructor($package, %legalattributes)
| GRID-Machine documentation | Contained in the GRID-Machine distribution. |
package GRID::Machine::MakeAccessors; use strict; use warnings;
sub make_accessors { # Install getter-setters my $package = caller; no strict 'refs'; for my $sub (@_) { *{$package."::$sub"} = sub { my $self = shift; $self->{$sub} = shift() if @_; return $self->{$sub}; }; } } sub make_constructor { # Install constructor my $package = caller; my %legal = @_; no strict 'refs'; *{$package."::new"} = sub { my $class = shift || die "Error: Provide a class\n"; my %args = (%legal, @_); my $a = ""; die "Illegal arg $a\n" if $a = first { !exists $legal{$_} } keys(%args); bless \%args, $class; }; } 1;