
Attribute.pm - generates all get- and set-methods for new classes created by classgen.

3.03

Within classgen called as:
use Attribute; # work with object Attribute
my $attr = Attribute->new(); # derive a new Attribute instance $attr
Let Ex.pm be a generated class, with internal variables $var, %entry and @list:
use Ex.pm; # use generated class
my $ex=Ex->new(); # creating a new object
$ex->set_var('this is a test'); # setting instance variable $var
$ex->set_h_entry( 12, twelve ); # like $entry{12}='twelve'
$ex->set_h_entry( 60, sixty ); #
$ex->set_l_list( 3, -100 ); # like $list[3]=-100;
$x=$ex->get_var(); # like $x=$var;
$x=$ex->get_h_entry(12);
@keys=$ex->get_keys_h_entry(); # get all keys of internal %entry
etc.

It is good OOP-style to access and manipulate instance variables of a class NEVER by a direct call, but via appropriate methods. You should always follow this concept to avoid problems when inheriting from your object oriented code.
classgen has been designed for exactly this purpose: To have all necessary methods available for all instance variables. Right from the start.
The methods name itself should uniquely identify the type of instance variable accessed or modified. So the general method convention is:
With this convention you will always know what to expect, e.g.:
use Example;
$ex = Example->new();
...
print $ex->get_number; # access instance variable $number
print $ex->get_l_cities; # access instance variable @cities
print $ex->get_keys_h_country; # get keys of inst.var. %country
For %hashes and @lists it is sometimes necessary to access the reference of the instance variable. Then use:
Some other methods deviate from these rules when purpose and involved type of instance variable are self evident. See below.
For all $scalar instance variables in classgens control file Attribute.pm generates (the phrase 'scalar' is replaced by the actual name of the $scalar instance variable):
Attribute generates clear_var(), get_var() and set_var. Class Example can be used like:
use Example; # use object Example
use strict; # recommended
my $ex = Example->new(); # creating a new Example instance
$ex->clear_var(); # set $var in Example to undef
$ex->set_var( "what a wonderful day" );
print $ex->get_var();
For all %hash instance variables in classgens control file Attribute.pm generates (the phrase 'hash' is replaced by the actual name of the %hash instance variable):
For all @list instance variables in classgens control file Attribute.pm generates (the phrase 'list' is replaced by the actual name of the @list instance variable):
A few methods are needed to provide all this:

Nothing special. Just use Perl5.

There is no special diagnostics. Attribute.pm is used within classgen which is called with the -w option.

No bugs known.

Please refer to classgen.

perldoc classgen

Name: Michael Schlueter email: mschlue@cpan.org

Copyright (c) 2000, Michael Schlueter. All Rights Reserved. This module is free software. It may be used, redistributed and/or modified under the same terms as Perl itself.