The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Class::MakeMethods::RelatedModules - Survey of Class Builders

SYNOPSIS

  http://search.cpan.org/search?mode=module&query=Class

DESCRIPTION

There are a variety of modules on CPAN dedicated to the purpose of generating common constructor and accessor methods. Below, I survey several of these, summarizing some basic features and technical approaches, and comparing them to Class::MakeMethods and other modules.

Caution

Please note that these comments are for basic comparison purposes only and may be incorrect or out of date. Please consult the documentation from a current version of each module for more specific details. Corrections and clarifications would by welcomed by the author at the email address below.

Points of Comparison

In general, I compared the following characteristics:

Distribution

Is it included with Perl, or on CPAN? Is it being actively maintained?

Usage

How do you go about declaring your class's methods?

Mechanism

How are they generated and delivered?

Instance type

Are the objects of your class blessed hashes, or something else?

Core Methods

Does the module provide a constructor and basic accessors? Are there specialized methods for hash-ref, array-ref, and object-ref accessors?

Extensible

Can you subclass the package to create new types of methods, or is there some other way to extend it?

Other Methods

Other types of methods provided.

Emulator

Does Class::MakeMethods provide a drop-in replacement for this module?

Comments

Other characteristics or features of note.

RELATED MODULES

Class::Accessor

Distribution

CPAN. Last update 4/01.

Usage

Inherit and call function with declaration arguments

Mechanism

Generates and installs closures

Instance Type

Hash.

Subclasses Cleanly

Cleanly.

Standard Methods

Scalar accessors.

Extensible

Yes.

Comments

Accessor methods call overwritable self-<get(key) and self-<set(key, value) methods.

Also includes Class::Accessor::Fast, which creates direct hash keys accessors without calling get and set methods.

Emulator

Yes, but only for the Fast variation; see Class::MakeMethods::Emulator::AccessorFast.

Example
  package MyObject;
  @ISA = qw(Class::Accessor);
  MyObject->mk_accessors(qw( simple ordered mapping obj_ref ));

Class::Class

Distribution

CPAN. Last update 1/00.

Usage

Inherit and fill %MEMBERS hash; methods created when first object is created

Mechanism

Generates and installs closures

Instance Type

Hash.

Subclasses Cleanly

Yes.

Standard Methods

Constructor and various accessors.

Extensible

No.

Example

Usage is similar to Class::Struct:

  package MyObject;
  use Class::Class; 
  @ISA = qw(Class::Class);
  %MEMBERS = ( 
    simple  => '$',
    ordered => '@',
    mapping => '%',
    obj_ref => 'FooObject' 
  ); 
Other Method Types

Provides a polymorph() method that is similar to Class::Method's "ClassName:class_name -require".

Class::Constructor

Distribution

CPAN. Last update 11/01.

Usage

Inherit and call function with declaration arguments

Mechanism

Generates and installs closures

Instance Type

Hash.

Subclasses Cleanly

Cleanly.

Standard Methods

Hash constructor, with bells.

Extensible

No.

Emulator

No, but possible.

Example
  package MyObject;
  @ISA = qw(Class::Constructor);
  MyObject->mk_constructor( Name => 'new' );

Class::Classgen

Distribution

CPAN. Last update 12/00.

Usage

Pre-processor run against declaration files.

Mechanism

Assembles and saves code file

Instance Type

Hash.

Subclasses Cleanly

Yes. (I think.)

Standard Methods

Constructor and various accessors.

Extensible

No. (I think.)

Example
  header:
      package MyObject;
  variables:
      $simple
      @ordered
      %mapping
      $obj_ref

Class::Contract

Distribution

CPAN. Last update 5/01.

Usage

Call function with declaration arguments

Mechanism

Generates and installs closures

Instance Type

Scalar reference with external data storage.

Subclasses Cleanly

Yes.

Standard Methods

Constructor and various accessors.

Extensible

Yes. (I think.)

Comments

Supports pre- and post-conditions, class invariants, and other software engineering goodies.

Example
  package MyObject;
  use Class::Contract;
  contract {
    ctor 'new';
    attr 'simple'  => SCALAR;
    attr 'ordered' => ARRAY;  
    attr 'mapping' => HASH;   
    attr 'obj_ref' => 'FooObject';   
  }

Class::Data::Inheritable

Distribution

CPAN. Last update 4/00.

Usage

Inherit and call function with declaration arguments

Mechanism

Generates and installs closures

Instance Type

Class data, with inheritance.

Subclasses Cleanly

Yes, specifically.

Standard Methods

Scalar accessors.

Extensible

No.

Example

Usage is similar to Class::Accessor:

  package MyObject;
  @ISA = qw(Class::Data::Inheritable);
  MyObject->mk_classdata(qw( simple ordered mapping obj_ref ));
Emulator

Yes, Class::MakeMethods::Emulator::Inheritable, passes original test suite.

Class::Delegate

Distribution

CPAN. Uploaded 12/0.

Comments

I have not yet reviewed this module in detail.

Class::Delegation

Distribution

CPAN. Uploaded 12/01.

Comments

I have not yet reviewed this module in detail.

Class::Generate

Distribution

CPAN. Last update 11/00.

Usage

Call function with declaration arguments

Mechanism

Assembles and evals code string, or saves code file.

Instance Type

Hash.

Subclasses Cleanly

Yes.

Standard Methods

Constructor and accessors (scalar, array, hash, object, object array, etc).

Extensible

?

Comments

Handles private/protected limitations, pre and post conditions, assertions, and more.

Example

Usage is similar to Class::Struct:

  package MyObject;
  use Class::Generate;
  class MyObject => [ 
    simple  => '$',
    ordered => '@',
    mapping => '%',
    obj_ref => 'FooObject' 
  ]; 

Class::Hook

Distribution

CPAN. Uploaded 12/01.

Comments

I have not yet reviewed this module in detail.

Class::Holon

Distribution

CPAN. Experimental/Alpha release 07/2001.

Instance Type

Hash, array, or flyweight-index.

Subclasses Cleanly

No. (I think.)

Standard Methods

Constructor and scalar accessors; flywieght objects also get scalar mutator methods.

Extensible

No. (I think.)

Comments

I'm not sure I understand the intent of this module; perhaps future versions will make this clearer....

Class::MethodMaker

Distribution

CPAN. Last update 1/01.

Usage

Import, or call function, with declaration arguments

Mechanism

Generates and installs closures

Instance Type

Hash, Static.

Subclasses Cleanly

Yes.

Standard Methods

Constructor and various accessors.

Extensible

Yes.

Example

Usage is similar to Class::MakeMethods:

  package MyObject;
  use Class::MethodMaker (
    new     =>   'new',
    get_set =>   'simple',
    list    =>   'ordered',
    hash    =>   'mapping',
    object  => [ 'FooObject' => 'obj_ref' ],
  );
Emulator

Yes, Class::MakeMethods::Emulator::MethodMaker, passes original test suite.

Class::MakeMethods

Distribution

Intended for CPAN release RSN.

Usage

Import, or call function, with declaration arguments

Mechanism

Generates and installs closures

Instance Type

Hash, Array, Scalar, Static, Class data, others.

Subclasses Cleanly

Yes.

Standard Methods

Constructor and various accessors.

Extensible

Yes.

Example

Usage is similar to Class::MethodMaker:

  package MyObject;
  use Class::MakeMethods::Hash (
    new    =>   'new',
    scalar =>   'simple',
    array  =>   'ordered',
    hash   =>   'mapping',
    object => [ 'obj_ref', { class=>'FooObject' } ],
  );

Class::SelfMethods

Distribution

CPAN. Last update 2/00.

Usage

Inherit; methods created via AUTOLOAD

Mechanism

Generates and installs closures (I think)

Instance Type

Hash.

Subclasses Cleanly

Yes.

Standard Methods

Constructor and scalar/code accessors (see Comments).

Extensible

No.

Comments

Individual objects may be assigned a subroutine that will be called as a method on subsequent accesses. If an instance does not have a value for a given accessor, looks for a method defined with a leading underscore.

Class::Struct

Distribution

Included in the standard Perl distribution. Replaces Class::Template.

Usage

Call function with declaration arguments

Mechanism

Assembles and evals code string

Instance Type

Hash or Array

Subclasses Cleanly

No.

Standard Methods

Constructor and various accessors.

Extensible

No.

  package MyObject;
  use Class::Struct;
  struct( 
    simple  => '$',
    ordered => '@',
    mapping => '%',
    obj_ref => 'FooObject' 
  );
Emulator

Yes, Class::MakeMethods::Emulator::Struct.

Class::StructTemplate

Distribution

CPAN. Last update 12/00.

No documentation available.

Usage

???

Mechanism

???

Class::Template

Distribution

CPAN. Out of date.

Usage

Call function with declaration arguments (I think)

Mechanism

Assembles and evals code string (I think)

Instance Type

Hash.

Subclasses Cleanly

Yes. (I think.)

Standard Methods

Constructor and various accessors.

Extensible

No. (I think.)

Example

Usage is similar to Class::Struct:

  package MyObject;
  use Class::Template;
  members MyObject { 
    simple  => '$',
    ordered => '@',
    mapping => '%',
    obj_ref => 'FooObject' 
  };

Class::Virtual

Generates methods that fail with a message indicating that they were not implemented by the subclass. (Cf. 'Template::Universal:croak -abstract'.)

Also provides a list of abstract methods that have not been implemented by a subclass.

    CPAN. Last update 3/01.

    Extensible

    ?

    Mechanism

    Uses Class::Data::Inheritable and installs additional closures.

HTML::Mason::MethodMaker

Distribution

CPAN.

Usage

Package import with declaration arguments

Mechanism

Generates and installs closures

Instance Type

Hash.

Standard Methods

Scalar accessors.

Extensible

No.

Example
  use HTML::Mason::MethodMaker ( 
    read_write => [ qw( simple ordered mapping obj_ref ) ] 
  );

SEE ALSO

See Class::MakeMethods for general information about this module.

See Class::MakeMethods::ReadMe for distribution, installation, version and support information.

AUTHOR

  M. Simon Cavalletto, Evolution Online Systems, simonm@evolution.com

LICENSE

Copyright (c) 2000, 2001 Evolution Online Systems, Inc.

This documentation may be used, redistributed and/or modified under the same terms as Perl.

8 POD Errors

The following errors were encountered while parsing the POD:

Around line 370:

'=item' outside of any '=over'

Around line 378:

You forgot a '=back' before '=head2'

Around line 380:

'=item' outside of any '=over'

Around line 390:

You forgot a '=back' before '=head2'

Around line 444:

'=item' outside of any '=over'

Around line 452:

You forgot a '=back' before '=head2'

Around line 745:

You can't have =items (as at line 749) unless the first thing after the =over is an =item

Around line 795:

You forgot a '=back' before '=head1'