MakeMe...Modules(3pm)

πŸ“¦
version 1.01 Β· 5 versions
, in ubuntu noble, ubuntu resolute, ubuntu stonking

✨ MakeMe...Modules(3pm) ✨

okay bestie, this is the Class::MakeMethods::Docs::RelatedModules page β€” aka Survey of Class Builders β€” from User Contributed Perl Documentation. It’s giving β€œlet me compare all the CPAN class-builder girlies so you don’t have to,” and honestly? iconic. πŸ’…


πŸŽ€ 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:

  • 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.

πŸ“ accessors

Distribution

CPAN. Uploaded Sep 2003.

Comments

I have not yet reviewed this module in detail.

Example

package MyObject;
use accessors qw( foo bar baz );

πŸ’œ Attribute::Property

Distribution

CPAN.

Comments

I have not yet reviewed this module in detail.


πŸŽ€ 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

Unknown.

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

CPAN.

Usage

Import, or call function, with declaration arguments; or if desired, make methods on-demand with Autoload, or declare subroutines with a special Attribute.

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

Distribution

CPAN. Last update 7/02.

Usage

Call function with declaration arguments.

Mechanism

Generates and installs closures (I think).

Instance Type

Hash (I think).

Subclasses Cleanly

Unknown.

Standard Methods

Constructor and various scalar and reference accessors.

Extensible

Unknown.

Comments

I haven't yet reviewed this module closely.


πŸ¦‹ 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.
  • Emulator β€” Yes, Class::MakeMethods::Emulator::Struct.

Example time, bestie β€” this is literally the whole vibe:

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

Class::StructTemplate πŸ¦‹

  • Distribution β€” CPAN. Last update 12/00.
  • Usage β€” Unknown.
  • Mechanism β€” Unknown.

No documentation available. πŸ™ˆ We stay guessing, respectfully.


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 ✨

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

It also provides a list of abstract methods that have not been implemented by a subclass. Very β€œyou forgot to implement me” energy.

  • Distribution β€” CPAN. Last update 3/01.
  • Extensible β€” Unknown.
  • Mechanism β€” Uses Class::Data::Inheritable and installs additional closures.

CodeGen::PerlBean 🌸

  • Distribution β€” CPAN.
  • Usage β€” Call function with declaration arguments.
  • Mechanism β€” Generates and writes source code to a file.
  • Instance Type β€” Hash (I think).
  • Subclasses Cleanly β€” Unknown.
  • Standard Methods β€” Constructor and various scalar and reference accessors.
  • Extensible β€” Unknown.
  • Comments β€” I haven't yet reviewed this module closely. πŸ™ˆ

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 β€” short, sweet, and iconic:

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. Not me leaving them in the queue, but okay β€” they’re noted:

  • 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. That’s the main character right there.


✨ 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. Slay, legally.


Footer vibe check, bestie: source/version is perl v5.36.0, dated 2022-10-13. That’s a wrap β€” go forth and make those methods cute. πŸ’…πŸ«Ά

πŸ“¦ where this page comes from