Class::MakeMethods::Emulator::MethodMaker - Emulate Class::MethodMaker


NAME

Class::MakeMethods::Emulator::MethodMaker - Emulate Class::MethodMaker


SYNOPSIS

  package MyObject;
  use Class::MakeMethods::Emulator::MethodMaker( 
    new_with_init => 'new',
    get_set       => [ qw / foo bar baz / ];
  );
  ... OR ...
  package MyObject;
  use Class::MakeMethods::Emulator::MethodMaker '-take_namespace';
  use Class::MethodMaker ( 
    new_with_init => 'new',
    get_set       => [ qw / foo bar baz / ];
  );


DESCRIPTION

This module provides emulation of Class::MethodMaker, using the Class::MakeMethods framework.

Although originally based on Class::MethodMaker, the calling convention for Class::MakeMethods differs in a variety of ways; most notably, the names given to various types of methods have been changed, and the format for specifying method attributes has been standardized. This package uses the aliasing capability provided by Class::MakeMethods, defining methods that modify the declaration arguments as necessary and pass them off to various subclasses of Class::MakeMethods.


COMPATIBILITY

Full compatibility is maintained with version 1.03; some of the changes in versions 1.04 through 1.10 are not yet included.

The test suite from Class::MethodMaker version 1.10 is included with this package, in the t/emulator_class_methodmaker/ directory. The unsupported tests have names ending in ``.todo''.

The tests are unchanged from those in the Class::MethodMaker distribution, except for the substitution of Class::MakeMethods::Emulator::MethodMaker in the place of Class::MethodMaker.

In cases where earlier distributions of Class::MethodMaker contained a different version of a test, it is also included. (Note that version 0.92's get_concat returned '' for empty values, but in version 0.96 this was changed to undef; this emulator follows the later behavior. To avoid ``use of undefined value'' warnings from the 0.92 version of get_concat.t, that test has been modified by appending a new flag after the name, 'get_concat --noundef', which restores the earlier behavior.)


USAGE

There are several ways to call this emulation module:


METHOD CATALOG

NOTE: The documentation below is derived from version 1.02 of Class::MethodMaker. Class::MakeMethods::Emulator::MethodMaker provides support for all of the features and examples shown below, with no changes required.


CONSTRUCTOR METHODS

new

Equivalent to Class::MakeMethods 'Template::Hash:new --with_values'.

new_with_init

Equivalent to Class::MakeMethods 'Template::Hash:new --with_init'.

new_hash_init

Equivalent to Class::MakeMethods 'Template::Hash:new --instance_with_methods'.

new_with_args

Equivalent to Class::MakeMethods 'Template::Hash:new --with_values'.

copy

Equivalent to Class::MakeMethods 'Template::Hash:new --copy_with_values'.


SCALAR ACCESSORS

get_set

Basically equivalent to Class::MakeMethods 'Template::Hash:scalar', except that various arguments are intercepted and converted into the parallel Class::MakeMethods::Template interface declarations.

get_concat

Equivalent to Class::MakeMethods 'Template::Hash:string' with a special interface declaration that provides the get_concat and clear behaviors.

counter

Equivalent to Class::MakeMethods 'Template::Hash:number --counter'.


OBJECT ACCESSORS

Basically equivalent to Class::MakeMethods 'Template::Hash:object' with an declaration that provides the ``delete_x'' interface. Due to a difference in expected argument syntax, the incoming arguments are revised before being delegated to Template::Hash:object.

object_list

Basically equivalent to Class::MakeMethods 'Template::Hash:object_list' with an declaration that provides the relevant helper methods. Due to a difference in expected argument syntax, the incoming arguments are revised before being delegated to Template::Hash:object_list.

forward

Basically equivalent to Class::MakeMethods 'Template::Universal:forward_methods'. Due to a difference in expected argument syntax, the incoming arguments are revised before being delegated to Template::Universal:forward_methods.

  forward => [ comp => 'method1', comp2 => 'method2' ]

Define pass-through methods for certain fields. The above defines that method method1 will be handled by component comp, whilst method method2 will be handled by component comp2.


REFERENCE ACCESSORS

list

Equivalent to Class::MakeMethods 'Template::Hash:array' with a custom method naming interface.

hash

Equivalent to Class::MakeMethods 'Template::Hash:hash' with a custom method naming interface.

tie_hash

Equivalent to Class::MakeMethods 'Template::Hash:tiedhash' with a custom method naming interface.

hash_of_lists

Equivalent to Class::MakeMethods 'Template::Hash:hash_of_arrays', or if the -static flag is present, to 'Template::Static:hash_of_arrays'.


STATIC ACCESSORS

static_get_set

Equivalent to Class::MakeMethods 'Template::Static:scalar' with a custom method naming interface.

static_list

Equivalent to Class::MakeMethods 'Template::Static:array' with a custom method naming interface.

static_hash

Equivalent to Class::MakeMethods 'Template::Static:hash' with a custom method naming interface.


GROUPED ACCESSORS

boolean

Equivalent to Class::MakeMethods 'Template::Static:bits' with a custom method naming interface.

grouped_fields

Creates get/set methods like get_set but also defines a method which returns a list of the slots in the group.

  use Class::MakeMethods::Emulator::MethodMaker
    grouped_fields => [
      some_group => [ qw / field1 field2 field3 / ],
    ];

Its argument list is parsed as a hash of group-name => field-list pairs. Get-set methods are defined for all the fields and a method with the name of the group is defined which returns the list of fields in the group.

struct

Equivalent to Class::MakeMethods 'Template::Hash::struct'.

Note: This feature is included but not documented in Class::MethodMaker version 1.


INDEXED ACCESSORS

listed_attrib

Equivalent to Class::MakeMethods 'Template::Flyweight:boolean_index' with a custom method naming interface.

key_attrib

Equivalent to Class::MakeMethods 'Template::Hash:string_index'.

key_with_create

Equivalent to Class::MakeMethods 'Template::Hash:string_index --find_or_new'.


CODE ACCESSORS

code

Equivalent to Class::MakeMethods 'Template::Hash:code'.

method

Equivalent to Class::MakeMethods 'Template::Hash:code --method'.

abstract

Equivalent to Class::MakeMethods 'Template::Universal:croak --abstract'.


ARRAY CONSTRUCTOR AND ACCESSORS

builtin_class (EXPERIMENTAL)

Equivalent to Class::MakeMethods 'Template::StructBuiltin:builtin_isa' with a modified argument order.


CONVERSION

If you wish to convert your code from use of the Class::MethodMaker emulator to direct use of Class::MakeMethods, you will need to adjust the arguments specified in your use or make calls.

Often this is simply a matter of replacing the names of aliased method-types listed below with the new equivalents.

For example, suppose that you code contained the following declaration:

  use Class::MethodMaker ( 
    counter => [ 'foo' ]
  );

Consulting the listings below you can find that counter is an alias for Hash:number --counter and you could thus revise your declaration to read:

  use Class::MakeMethods ( 
    'Hash:number --counter' => [ 'foo' ] 
  );

However, note that those methods marked ``(with custom interface)'' below have a different default naming convention for helper methods in Class::MakeMethods, and you will need to either supply a similar interface or alter your module's calling interface.

Also note that the forward, object, and object_list method types, marked ``(with modified arguments)'' below, require their arguments to be specified differently.

See the Class::MakeMethods::Template::Generic manpage for more information about the default interfaces of these method types.

Hash methods

The following equivalencies are declared for old meta-method names that are now handled by the Hash implementation:

  new              'Template::Hash:new --with_values'
  new_with_init    'Template::Hash:new --with_init'
  new_hash_init    'Template::Hash:new --instance_with_methods'
  copy             'Template::Hash:copy'
  get_set          'Template::Hash:scalar' (with custom interfaces)
  counter          'Template::Hash:number --counter'
  get_concat       'Template::Hash:string --get_concat' (with custom interface)
  boolean          'Template::Hash:bits' (with custom interface)
  list             'Template::Hash:array' (with custom interface)
  struct           'Template::Hash:struct'
  hash             'Template::Hash:hash' (with custom interface)
  tie_hash         'Template::Hash:tiedhash' (with custom interface)
  hash_of_lists    'Template::Hash:hash_of_arrays'
  code             'Template::Hash:code'
  method           'Template::Hash:code --method'
  object           'Template::Hash:object' (with custom interface and modified arguments)
  object_list      'Template::Hash:array_of_objects' (with custom interface and modified arguments)
  key_attrib       'Template::Hash:string_index'
  key_with_create  'Template::Hash:string_index --find_or_new'

Static methods

The following equivalencies are declared for old meta-method names that are now handled by the Static implementation:

  static_get_set   'Template::Static:scalar' (with custom interface)
  static_hash      'Template::Static:hash' (with custom interface)

Flyweight method

The following equivalency is declared for the one old meta-method name that us now handled by the Flyweight implementation:

  listed_attrib   'Template::Flyweight:boolean_index'

Struct methods

The following equivalencies are declared for old meta-method names that are now handled by the Struct implementation:

  builtin_class   'Template::Struct:builtin_isa'

Universal methods

The following equivalencies are declared for old meta-method names that are now handled by the Universal implementation:

  abstract         'Template::Universal:croak --abstract'
  forward          'Template::Universal:forward_methods' (with modified arguments)


EXTENDING

In order to enable third-party subclasses of MethodMaker to run under this emulator, several aliases or stub replacements are provided for internal Class::MethodMaker methods which have been eliminated or renamed.


BUGS

This module aims to provide a 100% compatible drop-in replacement for Class::MethodMaker; if you detect a difference when using this emulation, please inform the author.


SEE ALSO

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

See the Class::MakeMethods::Emulator manpage for more about this family of subclasses.

See the Class::MethodMaker manpage for more information about the original module.

A good introduction to Class::MethodMaker is provided by pages 222-234 of Object Oriented Perl, by Damian Conway (Manning, 1999).

  http://www.browsebooks.com/Conway/ 

 Class::MakeMethods::Emulator::MethodMaker - Emulate Class::MethodMaker