Scroll to navigation

MakeMethods::Docs::RelatedModules(3) User Contributed Perl Documentation MakeMethods::Docs::RelatedModules(3)

NAME

Class::MakeMethods::Docs::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:

Is it included with Perl, or on CPAN? Is it being actively maintained?
How do you go about declaring your class's methods?
How are they generated and delivered?
Are the objects of your class blessed hashes, or something else?
Does the module provide a constructor and basic accessors? Are there specialized methods for hash-ref, array-ref, and object-ref accessors?
Can you subclass the package to create new types of methods, or is there some other way to extend it?
Other types of methods provided.
Does Class::MakeMethods provide a drop-in replacement for this module?
Other characteristics or features of note.

RELATED MODULES

accessors

CPAN. Uploaded Sep 2003.
I have not yet reviewed this module in detail.
  package MyObject;
  use accessors qw( foo bar baz );
    

Attribute::Property

CPAN.
I have not yet reviewed this module in detail.

Class::Accessor

CPAN. Last update 4/01.
Inherit and call function with declaration arguments
Generates and installs closures
Hash.
Cleanly.
Scalar accessors.
Yes.
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.

Yes, but only for the Fast variation; see Class::MakeMethods::Emulator::AccessorFast.
  package MyObject;
  @ISA = qw(Class::Accessor);
  MyObject->mk_accessors(qw( simple ordered mapping obj_ref ));
    

Class::Class

CPAN. Last update 1/00.
Inherit and fill %MEMBERS hash; methods created when first object is created
Generates and installs closures
Hash.
Yes.
Constructor and various accessors.
No.
Usage is similar to Class::Struct:

  package MyObject;
  use Class::Class; 
  @ISA = qw(Class::Class);
  %MEMBERS = ( 
    simple  => '$',
    ordered => '@',
    mapping => '%',
    obj_ref => 'FooObject' 
  );
    
Provides a polymorph() method that is similar to Class::Method's "ClassName:class_name -require".

Class::Constructor

CPAN. Last update 11/01.
Inherit and call function with declaration arguments
Generates and installs closures
Hash.
Cleanly.
Hash constructor, with bells.
No.
No, but possible.
  package MyObject;
  @ISA = qw(Class::Constructor);
  MyObject->mk_constructor( Name => 'new' );
    

Class::Classgen

CPAN. Last update 12/00.
Pre-processor run against declaration files.
Assembles and saves code file
Hash.
Yes. (I think.)
Constructor and various accessors.
No. (I think.)
  header:
      package MyObject;
  variables:
      $simple
      @ordered
      %mapping
      $obj_ref
    

Class::Contract

CPAN. Last update 5/01.
Call function with declaration arguments
Generates and installs closures
Scalar reference with external data storage.
Yes.
Constructor and various accessors.
Yes. (I think.)
Supports pre- and post-conditions, class invariants, and other software engineering goodies.
  package MyObject;
  use Class::Contract;
  contract {
    ctor 'new';
    attr 'simple'  => SCALAR;
    attr 'ordered' => ARRAY;  
    attr 'mapping' => HASH;   
    attr 'obj_ref' => 'FooObject';   
  }
    

Class::Data::Inheritable

CPAN. Last update 4/00.
Inherit and call function with declaration arguments
Generates and installs closures
Class data, with inheritance.
Yes, specifically.
Scalar accessors.
No.
Usage is similar to Class::Accessor:

  package MyObject;
  @ISA = qw(Class::Data::Inheritable);
  MyObject->mk_classdata(qw( simple ordered mapping obj_ref ));
    
Yes, Class::MakeMethods::Emulator::Inheritable, passes original test suite.

Class::Delegate

CPAN. Uploaded 12/0.
I have not yet reviewed this module in detail.

Class::Delegation

CPAN. Uploaded 12/01.
I have not yet reviewed this module in detail.

Class::Generate

CPAN. Last update 11/00.
Call function with declaration arguments
Assembles and evals code string, or saves code file.
Hash.
Yes.
Constructor and accessors (scalar, array, hash, object, object array, etc).
Unknown.
Handles private/protected limitations, pre and post conditions, assertions, and more.
Usage is similar to Class::Struct:

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

Class::Hook

CPAN. Uploaded 12/01.
I have not yet reviewed this module in detail.

Class::Holon

CPAN. Experimental/Alpha release 07/2001.
Hash, array, or flyweight-index.
No. (I think.)
Constructor and scalar accessors; flywieght objects also get scalar mutator methods.
No. (I think.)
I'm not sure I understand the intent of this module; perhaps future versions will make this clearer....

Class::MethodMaker

CPAN. Last update 1/01.
Import, or call function, with declaration arguments
Generates and installs closures
Hash, Static.
Yes.
Constructor and various accessors.
Yes.
Usage is similar to Class::MakeMethods:

  package MyObject;
  use Class::MethodMaker (
    new     =>   'new',
    get_set =>   'simple',
    list    =>   'ordered',
    hash    =>   'mapping',
    object  => [ 'FooObject' => 'obj_ref' ],
  );
    
Yes, Class::MakeMethods::Emulator::MethodMaker, passes original test suite.

Class::MakeMethods

CPAN.
Import, or call function, with declaration arguments; or if desired, make methods on-demand with Autoload, or declare subroutines with a special Attribute.
Generates and installs closures
Hash, Array, Scalar, Static, Class data, others.
Yes.
Constructor and various accessors.
Yes.
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::Maker

CPAN. Last update 7/02.
Call function with declaration arguments.
Generates and installs closures (I think).
Hash (I think).
Unknown.
Constructor and various scalar and reference accessors.
Unknown.
I haven't yet reviewed this module closely.

Class::SelfMethods

CPAN. Last update 2/00.
Inherit; methods created via AUTOLOAD
Generates and installs closures (I think)
Hash.
Yes.
Constructor and scalar/code accessors (see Comments).
No.
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

Included in the standard Perl distribution. Replaces Class::Template.
Call function with declaration arguments
Assembles and evals code string
Hash or Array
No.
Constructor and various accessors.
No.

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

Class::StructTemplate

CPAN. Last update 12/00.

No documentation available.

Unknown.
Unknown.

Class::Template

CPAN. Out of date.
Call function with declaration arguments (I think)
Assembles and evals code string (I think)
Hash.
Yes. (I think.)
Constructor and various accessors.
No. (I think.)
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.
Unknown.
Uses Class::Data::Inheritable and installs additional closures.

CodeGen::PerlBean

CPAN.
Call function with declaration arguments.
Generates and writes source code to a file.
Hash (I think).
Unknown.
Constructor and various scalar and reference accessors.
Unknown.
I haven't yet reviewed this module closely.

HTML::Mason::MethodMaker

CPAN.
Package import with declaration arguments
Generates and installs closures
Hash.
Scalar accessors.
No.
  use HTML::Mason::MethodMaker ( 
    read_write => [ qw( simple ordered mapping obj_ref ) ] 
  );
    

TO DO

The following modules are relevant but have not yet been cataloged above.

Attribute::Property

Class::Accessor::Chained

Class::Accessor::Lvalue

Class::Accessor::Ref

Class::AutoClass

Class::Builder

Class::Member

Class::Trigger

SEE ALSO

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

CREDITS AND COPYRIGHT

Developed By

  M. Simon Cavalletto, simonm@cavalletto.org
  Evolution Softworks, www.evoscript.org

Copyright 2002 Matthew Simon Cavalletto.

Portions copyright 2000, 2001 Evolution Online Systems, Inc.

License

You may use, modify, and distribute this document under the same terms as Perl.

POD ERRORS

Hey! The above document had some coding errors, which are explained below:

'=item' outside of any '=over'
You forgot a '=back' before '=head2'
2012-01-11 perl v5.40.0