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

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

Annotate this POD

CPAN RT

New  1
Open  0
View Bugs
Report a bug
Source  

NAME ^

classgen - script that generates a class-module from a control file.

VERSION ^

3.03

SYNOPSIS ^

!!! A fake-module, just to make the documention in the classgen-script visible to CPAN !!!

classgen input.txt Output.pm # generate new class

perldoc Output.pm # review the fresh pod-skelton

vi Output.pm # edit specific methods

less Output_gs.pm # instance methods get-/set-

For historical reasons the synonym ".gs" is still inthis documentation. Please read it as "<file>_gs.pm".

DESCRIPTION ^

You specify the required instance-variables of a desired class by a control-file.

Classgen then creates a new package for you which contains the new()-method, accessor- and manipulator-methods for all instance-variables of that class. All instance-variables are blessed into an anonymous hash {}.

classgen adds a basic, simple perldoc skelton to support your documentation for new classes.

For a better overview version 3.03 splits the package into a .pm and a .gs file. The .gs file contains all standard get-/set-methods and will be reviewed only on occasion. The .pm will focus on the specific methods only. Printouts will become much shorter and your overview will increase.

Input format of the control file

The control file is an ASCII-file which must contain the 3 sections with specific keywords in the specified order:

        header:
        variables:

classgen will scan for these 2 sections and act accordingly. classgen will insist on using exactly these section-headers. It will die, if you don't.

Methods generated

classgen generates accessor- and manipulator-methods as required by the variables type. The order of methods is:

The specific() method is intended for copy&paste operation to easily append the generated class with more specific class-methods by the user.

A variable-name consists of <type><var_name>, with <type>=($,@,%). Via <type> methods are generated as:

        <method name><var_name>

Run perldoc Attribute.pm for an overview of all created methods.

Missing Methods for the created Objects

A serialize() method should be added. So far my personal lack of knowledge in this subject prevented me from supplying you with one. Conway examines some possibilities, which you can find at CPAN.

Other Objects involved

classgen will use instances from the

Subroutines used by classgen

Internal methods:

How to use classgen

In version 3.03 an archive functionality has been introduced. Before classgen creates the .pm and the .gs files from the control file, the old files are copied into the /archive directory with an increasing numeriacl starting index. So your previous edits are not lost.

How to produce undesired results (and how to avoid them)

Version 3.03: Problems from overwriting have been removed. Your edits are copied to the /archive directory first.

How to handle inheritance of classes

Derive two classes with classgen. In the header-section of the derived class you can add the required Perl-statements already in the control-file.

Make sure to include the base-class in an @ISA-statement and adapt the call to inherit_from() right after the blessing in the new() method of your derived class.

See also examples/inheritance/README

Open issues

I would like to know how classgen performs compared to other approaches to object-oriented-implementations. How can I find out how much memory my version actually consumes? - Please, gimme a hint ...

Instance-variables could also be blessed into [] or $. Initially I planned to offer these choices, too. It turned out to be more convenient to omit this for a start. Your benefit is that you can do less things wrong. As a by-product the control file becomes more handy ;-)

Background / Motivation

J.Rumbaughs "Object Oriented Modelling" showed me a very promissing way to tackle challenging software-projects. The idea is to identify relevant classes (objects), their relationship (associations), their dynamic behaviour (statediagrams) and their flow of data (functional model) - all on paper.

Once done and tested by various scenarios a very good specification has been grown. Then there are ways to implement these objects both in object-oriented (e.g. C++, Smalltalk, Eiffel) and NON-object-oriented languages (e.g. C, Fortran, Algol) or databases. - What a challange for Perl!

I tried Damian Conways excellent book "Object Oriented Perl", which has been published in fall 1999. I learned again, that there still "... are always more than one way to do it" when it comes to implementing objects in Perl:

Clearly, the first choice is the least desireable one. It is prone to typing errors and one spends more time on same methods again rather than on methods unique to the class (as I would prefer).

The other methods have some advantages and some disadvantages. The least tasty for me was that they tend to produce "obscure" code, at least in examples I looked at. That is, code where I had to spend a lot of thinking to understand what it does.

Rather, I'd prefer code which I can understand at just one glance (idealy ;-). Therefor classgen creates almost every get- and set-method you can think of. Should you need it, it is already there. Should you dislike it, simply throw methods away. Or even better, just do not care about their existence at all. Stay focused on what your class should be doing, not on the instance-variables.

There is another inportant reason for my approach. I feel OOP-code appears to be more 'cleaner' when it can be distributed over separated, individual files. Some of the approaches mentioned above tend to create and modify objects WITHIN another program. I think that shouldn't be done. Have a look at my 'peanuts' example.

Future Plans

classgen lets me create new classes within minutes rather than days. I myself am quite satisfied with the current performance. classgen was created more or less on-the-fly. Perhaps I will redesign it by a more consequent OMT-approach lateron.

But before doing so I'd need more input about the good's and bad's from you to make up my mind. The missing parts. The nice-to-have things and so on.

If you like classgen and want it to have more useful functions please let me know ;-)

ENVIRONMENT ^

Perhaps you may have to modify the first line in classgen due to different locations of perl on different operating systems. If so, you'll probably find classgen as (watch make install for details):

        /usr/bin/classgen

You can avoid this adaption if you simply call:

        perl classgen <input_file> <output_class>

DIAGNOSTICS ^

When running classgen you will see the message:

        #: 2
        var1head1
        N: 2

which is a relict from program development. It helped me to trace if the correct sections where identified. It does not harm very much and perhaps may be useful to find errors lateron. So, for the moment, it is just in the program.

classgen runs with the -w option. If you call classgen with the wrong number of arguments it will simply die. The subroutines should either return your requested result or "undef".

The ideal diagnostics is the diagnostic which is not there, but which function is performed. - To approach this ideal I did the following:

The sensitivity analysis part from the Taguchi-method has been used to measure sensitivity of classgen against errorness inputs from the control file (that is against variable usage-conditions). Only those kinds of errors which are likely to occure for a serious user, playing by the rules, where investigated. Those are for example:

This lead to creating the Comments.pm package, which provides just a few simple routines to detect and to correct the errors mentioned above.

Error Messages:

In alphabetical order:

BUGS ^

You should always put at least one instance-variable into your class. If you don't, you'll get a strange blessing ;-) . In most cases you probably will do so automatically, so I decided to leave this invonvenience until I know if it is worth while to re-concept classgen or not (cf. Future Plans).

FILES ^

Installation

Copy the .gz to a suitable directory. Run 'gunzip' and 'tar xvf '. Change to Class/Classgen. Execute:

        perl Makefile.PL
        make

As root do the final installation:

        make install

When you run Perl under Windows you may want to use nmake.exe instead of make (download e.g. from ftp://ftp.microsoft.com/Softlib/MSLFILES/nmake15.exe)

SEE ALSO ^

        Changes

Methods created by classgen

Run perldoc Attribute.pm

Run perldoc New.pm

Example: Starting up with classgen

You may also want to review the included example files, which creates the class Example.

perldoc

Please refer also to

Books I referred to

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.