Module Design and Implementation
clear_model(), and so on. This extra method is unnecessary, since you can always call
$obj >id(undef) to clear the value of an attribute. Fortunately, Class::MethodMaker is
highly configurable. Here's a few variations on the default get_set:
package BOA::Probe;
use Class::MethodMaker
new => new ,
get_set => id , # creates id() and clear_id()
get_set => [ noclear => model ], # creates just model() ala Class::Struct
get_set => [ java =>[("Contents", # creates getContents() and setContents()
"Heading")] # creates getHeading() and setHeading()
];
You can also design your own get_set method templates, but I won't go into
the syntax here. Suffice it to say that if you have an accessor mutator scheme in
mind, Class::MethodMaker can save you the trouble of coding it.
Similar flexibility is available for the generated constructor. When using
Class::Struct, doing anything at all during object creation requires you to replace
the generated new() method. Class::MethodMaker has a more elegant solution:
package BOA::Probe;
use Class::MethodMaker
new_with_init => new ,
get_set => [ qw(id model contents heading status) ];
# called from the generated new()
sub init {
my $self = shift;
croak("Required id parameter missing!") unless @_;
$self >id(shift);
return $self;
}
Using new_with_init creates a constructor that calls init() in your module. You
receive as arguments the arguments passed to new(). One thing you might want to
do with init() is take a list of key value pairs and assign their values to the named
attributes. With Class::MethodMaker you can actually auto generate a constructor
that does this too:
package BOA::Probe;
use Class::MethodMaker
new_hash_init => new ,
get_set => [ qw(id model contents heading status) ];
91
91
footer
Our partners:
PHP: Hypertext Preprocessor Best Web Hosting
Java Web Hosting
Inexpensive Web Hosting
Jsp Web Hosting
Cheapest Web Hosting
Jsp Hosting
Cheap Hosting
Visionwebhosting.net Business web hosting division of Web
Design Plus. All rights reserved