Class::MethodMapper - Abstract Class wrapper for AutoLoader |
Class::MethodMapper - Abstract Class wrapper for AutoLoader
BEGIN { @MMDerived::ISA = qw(Class::MethodMapper Exporter AutoLoader); }
sub new { my $class = shift; my @args = @_;
my $self = Class::MethodMapper->new(); bless $self, $class;
my %map = ( 'time_style' => { 'type' => 'parameter', 'doc' => 'How recording duration is decided', 'domain' => 'enum', 'options' => [qw(track prompt fixed click_stop deadman)], 'value' => 'prompt', },
'iter_plan' => { 'type' => 'volatile', 'doc' => 'Currently active plan for iteration: perl code.', 'value' => 'play; color("yellow"); hold(0.75); color("red"); ' . 'record; color;' , # see FestVox::ScriptLang
}, );
$self->set_map(%map); $self->set(@args) if @args; $self; }
Class::MethodMapper takes a hash of hashes and creates
get()
and set()
methods, with (some) validation, for the
maps listed. Generally, a parameter
is something that
can be saved and restored, whereas a volatile
is not
serialized at save-time.
new(@args)
set()
with its arguments.
set_map(%map)
get_map()
below.
get_map($type)
parameter
. Note
that the object itself is the top-level (complete) map,
since Class::MethodMapper writes into variables in the object
of the same name; the 'map' itself is just the variables
of that type
.
delete_map(@mapnames)
@mapnames
.
meta
data of a given type for a named variable
in th method map.
type e.g. 'volatile', 'parameter' doc some human-readable string do describe this value current value; useful for initialization domain e.g. 'enum' or 'ref' options if domain is 'enum', an array reference of allowed values if domain is 'ref', 'ARRAY', 'HASH' or the name of a class.
meta
variable type
of var
to value
.
var
to
the value 'value'
. Checks if var
is in the method
map, and complains if it is not. Does basic type checking
if the meta
variable domain
is defined.
This means it checks if the value is an element in the array
reference in options
if domain
is 'enum' and checks if
the value is indeed a reference of the specified type
if domain
is 'ref'
get('var')
&$callback ($self, $key, $value, @args);
for each of them, where $key is the value of each key and $value is the hashref for its value.
&$callback ($self, @args);
it expects the callback to return a ($key, $value) list. keeps looping till the callback function returns an undefined key.
var()
var
itself is promoted to method status; if given no
argument, it is considered a get()
, and if given
argument(s), it is considered a set()
. Thus, if you
had a parameter called active
in the method map,
Class::MethodMapper would use AutoLoader to create a active()
method (if ever called), so that $self-
active> would
return the current value, and $self-
active(1)> would
set it to 1
.
Terribly underdocumented.
Copyright (c) 2000 Kevin A. Lenzo and Alan W Black, Carnegie Mellon Unversity.
Class::MethodMapper - Abstract Class wrapper for AutoLoader |