Class::Std 0.0.8 review
Download
|
|
Class::Std is a Perl module to support for creating standard "inside-out" classes.
SYNOPSIS
package MyClass;
use Class::Std;
# Create storage for object attributes...
my %name : ATTR;
my %rank : ATTR;
my %snum : ATTR;
my %public_data : ATTR;
# Handle initialization of objects of this class...
sub BUILD {
my ($self, $obj_ID, $arg_ref) = @_;
$name{$obj_ID} = check_name( $arg_ref->{name} );
$rank{$obj_ID} = check_rank( $arg_ref->{rank} );
$snum{$obj_ID} = _gen_uniq_serial_num();
}
# Handle cleanup of objects of this class...
sub DEMOLISH {
my ($self, $obj_ID) = @_;
_recycle_serial_num( $snum{$obj_ID} );
}
# Handle unknown method calls...
sub AUTOMETHOD {
my ($self, $obj_ID, @other_args) = @_;
# Return any public data...
if ( m/A get_(.*)/ ) { # Method name passed in $_
my $get_what = $1;
return sub {
return $public_data{$obj_ID}{$get_what};
}
}
warn "Can't call $method_name on ", ref $self, " object";
return; # The call is declined by not returning a sub ref
}
This module provides tools that help to implement the "inside out object" class structure in a convenient and standard way.
Requirements:
Perl
Class::Std 0.0.8 keywords