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.
parameter
volatile
Creates and initializes an empty Class::MethodMapper. Calls set() with its arguments.
set()
Sets the complete map for this object. See FestVox::InitMap for a good example of a method map; it is the big one that FestVox::PointyClicky itself uses. This should be generalized to let you set which map, as get_map() below.
get_map()
Get the map of a particular type, e.g. 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.
type
Delete the mapping for each variable in @mapnames.
@mapnames
Get the meta data of a given type for a named variable in th method map.
meta
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.
Just what you would think. Sets the meta variable type of var to value.
var
value
Set the variable 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.
'value'
domain
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'
options
Return the value of 'var' if it is defined and in the method map.
loops over all the keys that have type 'type' and calls
&$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.
saves all 'parameter' type key/value pairs to 'filename'
loads earlier saved values of the object keys back by calling
&$callback ($self, @args);
it expects the callback to return a ($key, $value) list. keeps looping till the callback function returns an undefined key.
loads values from the file 'filename', which is in the format that save_config writes out.
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.
get()
active
active()
$self-
1
Terribly underdocumented.
Copyright (c) 2000 Kevin A. Lenzo and Alan W Black, Carnegie Mellon Unversity.
To install Class::MethodMapper, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Class::MethodMapper
CPAN shell
perl -MCPAN -e shell install Class::MethodMapper
For more information on module installation, please visit the detailed CPAN module installation guide.