Class::MethodMaker::V1Compat(3pm) | User Contributed Perl Documentation | Class::MethodMaker::V1Compat(3pm) |
Class::MethodMaker::V1Compat - V1 compatibility code for C::MM
This class is for internal implementation only. It is not a public API.
Class::MethodMaker version 2 strives for backward-compatibility with version 1 as far as possible. That is to say, classes built with version 1 should work with few if any changes. However, the calling conventions for building new classes are significantly different: this is necessary to achieve a greater consistency of arguments.
Version 2 takes all arguments within a single arrayref:
use Class::MethodMaker [ scalar => 'a' ];
If arguments are presented as a list, then Class::MethodMaker assumes that this is a version 1 call, and acts accordingly. Version 1 arguments are passed and internally rephrased to version 2 arguments, and passed off to the version 2 engine. Thus, the majority of version 1 calls can be upgraded to version 2 merely by rephrasing. However, there are a number of behaviours that in version 1 that are internally inconsistent. These behaviours are mimicked in version 1 mode as far as possible, but are not reproducible in version 2 (to allow version 2 clients to rely on a more internally consistent interface).
The nearest equivalent to each 1 component (slot) available in version 2 is shown below using the indicated data-structures & options to create a component called "a" that mimics the V1 component behaviour as closely as possible:
use Class::MethodMaker [ abstract => 'a' ];
use Class::MethodMaker [ scalar => 'a' ];
Let's face it, the v1 store-if-it's-a-coderef-else-retrieve semantics are rather broken. How do you pass a coderef as argument to one of these? It is on the TODO list to recognize code as fundamental restricted type (analogous to INTEGER), which would add in a *_invoke method.
use Class::MethodMaker [ copy => 'a' ];
The v2 method is the same as v1.
use Class::MethodMaker [ scalar => [{-type => Class::MethodMaker::Constants::INTEGER}, 'a'] ];
use Class::MethodMaker [ copy => [ -deep => 'a' ] ];
use Class::MethodMaker [ scalar => [{ -store_cb => sub { defined $_[1] ? ( defined $_[3] ? "$_[3] $_[1]" : $_[1] ) : undef; } }, 'a' ] ];
use Class::MethodMaker [ scalar => 'a' ];
use Class::MethodMaker [ hash => 'a' ];
use Class::MethodMaker [ list => 'a' ];
Note that the "*" method now sets the whole array if given arguments.
use Class::MethodMaker [ new => 'a' ];
use Class::MethodMaker [ new => [ -hash => 'a' ] ];
use Class::MethodMaker [ new => [ -hash => -init => 'a' ] ];
use Class::MethodMaker [ new => [ -init => 'a' ] ];
use Class::MethodMaker [ scalar => [{ -type => 'MyClass', -forward => [qw/ method1 method2 /] }, 'a' ] ];
use Class::MethodMaker [ hash => [{ -type => 'MyClass', -forward => [qw/ method1 method2 /], -tie_class => 'Tie::MyTie', -tie_args => [qw/ foo bar baz /], }, 'a' ] ];
use Class::MethodMaker [ array => [{ -type => 'MyClass', -forward => [qw/ method1 method2 /], -tie_class => 'Tie::MyTie', -tie_args => [qw/ foo bar baz /], }, 'a' ] ];
use Class::MethodMaker [ scalar => [{ -store_cb => sub { die "Already stored $_[3]" if @_ > 3; } }, 'a' ] ];
use Class::MethodMaker [ scalar => [{ -store_cb => sub { die "Already stored $_[3]" if @_ > 3; }, -static => 1, }, 'a' ] ];
use Class::MethodMaker [ new => [ -singleton => -hash => -init => 'a' ] ];
use Class::MethodMaker [ scalar => [ -static => 'a' ], ];
use Class::MethodMaker [ hash => [ -static => 'a' ], ];
use Class::MethodMaker [ list => [ -static => 'a' ], ];
use Class::MethodMaker [ hash => [ { -tie_class => 'MyTie', -tie_args => [qw/ foo bar baz /], } => 'a' ], ];
use Class::MethodMaker [ array => [ { -tie_class => 'MyTie', -tie_args => [qw/ foo bar baz /], } => 'a' ], ];
use Class::MethodMaker [ scalar => [ { -tie_class => 'MyTie', -tie_args => [qw/ foo bar baz /], } => 'a' ], ];
The following version 1 component (slot) types are not currently supported in version 2:
Email the development mailing list "class-mmaker-devel@lists.sourceforge.net".
Martyn J. Pearce
Copyright (c) 2003, 2004 Martyn J. Pearce. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
2022-10-19 | perl v5.36.0 |