Michael Schlüter > Class-Classgen-classgen-3.03 > Class::Classgen::Attribute

Download:
Class-Classgen-classgen-3.03.tar.gz

Dependencies

Annotate this POD

CPAN RT

New  1
Open  0
View/Report Bugs
Module Version: 3.03   Source  

NAME ^

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

VERSION ^

3.03

SYNOPSIS ^

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.

DESCRIPTION ^

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.

General syntax for generated methods

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.

Generated methods for $scalars

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):

Example: control file contains $var of class Example.

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();

Generated methods for %hashes

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):

Generated methods for @lists

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):

Internal methods

A few methods are needed to provide all this:

ENVIRONMENT ^

Nothing special. Just use Perl5.

DIAGNOSTICS ^

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

BUGS ^

No bugs known.

FILES ^

Please refer to classgen.

SEE ALSO ^

perldoc classgen

AUTHOR ^

Name: Michael Schlueter email: mschlue@cpan.org

COPYRIGHT ^

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.

syntax highlighting: