summaryrefslogtreecommitdiff
path: root/lib/Class
diff options
context:
space:
mode:
authorAndreas Brachold <vdr07@deltab.de>2007-08-13 18:41:27 +0000
committerAndreas Brachold <vdr07@deltab.de>2007-08-13 18:41:27 +0000
commitbcbf441e09fb502cf64924ff2530fa144bdf52c5 (patch)
treef377707a2dac078db8cd0c7d7abfe69ac1006d71 /lib/Class
downloadxxv-bcbf441e09fb502cf64924ff2530fa144bdf52c5.tar.gz
xxv-bcbf441e09fb502cf64924ff2530fa144bdf52c5.tar.bz2
* Move files to trunk
Diffstat (limited to 'lib/Class')
-rw-r--r--lib/Class/MakeMethods.pm1520
-rw-r--r--lib/Class/MakeMethods/Attribute.pm143
-rw-r--r--lib/Class/MakeMethods/Autoload.pm182
-rw-r--r--lib/Class/MakeMethods/Basic.pm98
-rw-r--r--lib/Class/MakeMethods/Basic/Array.pm422
-rw-r--r--lib/Class/MakeMethods/Basic/Global.pm298
-rw-r--r--lib/Class/MakeMethods/Basic/Hash.pm362
-rw-r--r--lib/Class/MakeMethods/Composite.pm218
-rw-r--r--lib/Class/MakeMethods/Composite/Array.pm794
-rw-r--r--lib/Class/MakeMethods/Composite/Global.pm588
-rw-r--r--lib/Class/MakeMethods/Composite/Hash.pm719
-rw-r--r--lib/Class/MakeMethods/Composite/Inheritable.pm613
-rw-r--r--lib/Class/MakeMethods/Composite/Universal.pm150
-rw-r--r--lib/Class/MakeMethods/Docs/Catalog.pod888
-rw-r--r--lib/Class/MakeMethods/Docs/Changes.pod661
-rw-r--r--lib/Class/MakeMethods/Docs/Examples.pod554
-rw-r--r--lib/Class/MakeMethods/Docs/ReadMe.pod279
-rw-r--r--lib/Class/MakeMethods/Docs/RelatedModules.pod962
-rw-r--r--lib/Class/MakeMethods/Docs/ToDo.pod296
-rw-r--r--lib/Class/MakeMethods/Emulator.pm165
-rw-r--r--lib/Class/MakeMethods/Emulator/AccessorFast.pm102
-rw-r--r--lib/Class/MakeMethods/Emulator/Inheritable.pm162
-rw-r--r--lib/Class/MakeMethods/Emulator/MethodMaker.pm676
-rw-r--r--lib/Class/MakeMethods/Emulator/Singleton.pm85
-rw-r--r--lib/Class/MakeMethods/Emulator/Struct.pm154
-rw-r--r--lib/Class/MakeMethods/Emulator/accessors.pm122
-rw-r--r--lib/Class/MakeMethods/Emulator/mcoder.pm116
-rw-r--r--lib/Class/MakeMethods/Evaled.pm97
-rw-r--r--lib/Class/MakeMethods/Evaled/Hash.pm349
-rw-r--r--lib/Class/MakeMethods/Standard.pm68
-rw-r--r--lib/Class/MakeMethods/Standard/Array.pm555
-rw-r--r--lib/Class/MakeMethods/Standard/Global.pm405
-rw-r--r--lib/Class/MakeMethods/Standard/Hash.pm501
-rw-r--r--lib/Class/MakeMethods/Standard/Inheritable.pm428
-rw-r--r--lib/Class/MakeMethods/Standard/Universal.pm336
-rw-r--r--lib/Class/MakeMethods/Template.pm1255
-rw-r--r--lib/Class/MakeMethods/Template/Array.pm102
-rw-r--r--lib/Class/MakeMethods/Template/Class.pm103
-rw-r--r--lib/Class/MakeMethods/Template/ClassInherit.pm144
-rw-r--r--lib/Class/MakeMethods/Template/ClassName.pm330
-rw-r--r--lib/Class/MakeMethods/Template/ClassVar.pm178
-rw-r--r--lib/Class/MakeMethods/Template/Flyweight.pm43
-rw-r--r--lib/Class/MakeMethods/Template/Generic.pm2349
-rw-r--r--lib/Class/MakeMethods/Template/Global.pm97
-rw-r--r--lib/Class/MakeMethods/Template/Hash.pm229
-rw-r--r--lib/Class/MakeMethods/Template/Inheritable.pm154
-rw-r--r--lib/Class/MakeMethods/Template/InsideOut.pm218
-rw-r--r--lib/Class/MakeMethods/Template/PackageVar.pm168
-rw-r--r--lib/Class/MakeMethods/Template/Ref.pm207
-rw-r--r--lib/Class/MakeMethods/Template/Scalar.pm80
-rw-r--r--lib/Class/MakeMethods/Template/Static.pm41
-rw-r--r--lib/Class/MakeMethods/Template/Struct.pm41
-rw-r--r--lib/Class/MakeMethods/Template/StructBuiltin.pm148
-rw-r--r--lib/Class/MakeMethods/Template/Universal.pm415
-rw-r--r--lib/Class/MakeMethods/Utility/ArraySplicer.pm243
-rw-r--r--lib/Class/MakeMethods/Utility/DiskCache.pm165
-rw-r--r--lib/Class/MakeMethods/Utility/Inheritable.pm126
-rw-r--r--lib/Class/MakeMethods/Utility/Ref.pm171
-rw-r--r--lib/Class/MakeMethods/Utility/TextBuilder.pm207
59 files changed, 21282 insertions, 0 deletions
diff --git a/lib/Class/MakeMethods.pm b/lib/Class/MakeMethods.pm
new file mode 100644
index 0000000..2865a4c
--- /dev/null
+++ b/lib/Class/MakeMethods.pm
@@ -0,0 +1,1520 @@
+### Class::MakeMethods
+ # Copyright 2002, 2003 Matthew Simon Cavalletto
+ # See documentation, license, and other information after _END_.
+
+package Class::MakeMethods;
+
+require 5.00307; # for the UNIVERSAL::isa method.
+use strict;
+use Carp;
+
+use vars qw( $VERSION );
+$VERSION = 1.010;
+
+use vars qw( %CONTEXT %DIAGNOSTICS );
+
+########################################################################
+### MODULE IMPORT: import(), _import_version()
+########################################################################
+
+sub import {
+ my $class = shift;
+
+ if ( scalar @_ and $_[0] =~ m/^\d/ ) {
+ $class->_import_version( shift );
+ }
+
+ if ( scalar @_ == 1 and $_[0] eq '-isasubclass' ) {
+ shift;
+ my $target_class = ( caller )[0];
+ no strict;
+ push @{"$target_class\::ISA"}, $class;
+ }
+
+ $class->make( @_ ) if ( scalar @_ );
+}
+
+sub _import_version {
+ my $class = shift;
+ my $wanted = shift;
+
+ no strict;
+ my $version = ${ $class.'::VERSION '};
+
+ # If passed a version number, ensure that we measure up.
+ # Based on similar functionality in Exporter.pm
+ if ( ! $version or $version < $wanted ) {
+ my $file = "$class.pm";
+ $file =~ s!::!/!g;
+ $file = $INC{$file} ? " ($INC{$file})" : '';
+ _diagnostic('mm_version_fail', $class, $wanted, $version || '(undef)', $file);
+ }
+}
+
+########################################################################
+### METHOD GENERATION: make()
+########################################################################
+
+sub make {
+ local $CONTEXT{MakerClass} = shift;
+
+ # Find the first class in the caller() stack that's not a subclass of us
+ local $CONTEXT{TargetClass};
+ my $i = 0;
+ do {
+ $CONTEXT{TargetClass} = ( caller($i ++) )[0];
+ } while UNIVERSAL::isa($CONTEXT{TargetClass}, __PACKAGE__ );
+
+ my @methods;
+
+ # For compatibility with 5.004, which fails to splice use's constant @_
+ my @declarations = @_;
+
+ if (@_ % 2) { _diagnostic('make_odd_args', $CONTEXT{MakerClass}); }
+ while ( scalar @declarations ) {
+ # The list passed to import should alternate between the names of the
+ # meta-method to call to generate the methods, and arguments to it.
+ my ($name, $args) = splice(@declarations, 0, 2);
+ unless ( defined $name ) {
+ croak "Undefined name";
+ }
+
+ # Leading dash on the first argument of a pair means it's a
+ # global/general option to be stored in CONTEXT.
+ if ( $name =~ s/^\-// ) {
+
+ # To prevent difficult-to-predict retroactive behaviour, start by
+ # flushing any pending methods before letting settings take effect
+ if ( scalar @methods ) {
+ _install_methods( $CONTEXT{MakerClass}, @methods );
+ @methods = ();
+ }
+
+ if ( $name eq 'MakerClass' ) {
+ # Switch base package for remainder of args
+ $CONTEXT{MakerClass} = _find_subclass($CONTEXT{MakerClass}, $args);
+ } else {
+ $CONTEXT{$name} = $args;
+ }
+
+ next;
+ }
+
+ # Argument normalization
+ my @args = (
+ ! ref($args) ? split(' ', $args) : # If a string, it is split on spaces.
+ ref($args) eq 'ARRAY' ? (@$args) : # If an arrayref, use its contents.
+ ( $args ) # If a hashref, it is used directly
+ );
+
+ # If the type argument contains an array of method types, do the first
+ # now, and put the others back in the queue to be processed subsequently.
+ if ( ref($name) eq 'ARRAY' ) {
+ ($name, my @name) = @$name;
+ unshift @declarations, map { $_=>[@args] } @name;
+ }
+
+ # If the type argument contains space characters, use the first word
+ # as the type, and prepend the remaining items to the argument list.
+ if ( $name =~ /\s/ ) {
+ my @items = split ' ', $name;
+ $name = shift( @items );
+ unshift @args, @items;
+ }
+
+ # If name contains a colon or double colon, treat the preceeding part
+ # as the subclass name but only for this one set of methods.
+ local $CONTEXT{MakerClass} = _find_subclass($CONTEXT{MakerClass}, $1)
+ if ($name =~ s/^(.*?)\:{1,2}(\w+)$/$2/);
+
+ # Meta-method invocation via named_method or direct method call
+ my @results = (
+ $CONTEXT{MakerClass}->can('named_method') ?
+ $CONTEXT{MakerClass}->named_method( $name, @args ) :
+ $CONTEXT{MakerClass}->can($name) ?
+ $CONTEXT{MakerClass}->$name( @args ) :
+ croak "Can't generate $CONTEXT{MakerClass}->$name() methods"
+ );
+ # warn "$CONTEXT{MakerClass} $name - ", join(', ', @results) . "\n";
+
+ ### A method-generator may be implemented in any of the following ways:
+
+ # SELF-CONTAINED: It may return nothing, if there are no methods
+ # to install, or if it has installed the methods itself.
+ # (We also accept a single false value, for backward compatibility
+ # with generators that are written as foreach loops, which return ''!)
+ if ( ! scalar @results or scalar @results == 1 and ! $results[0] ) { }
+
+ # ALIAS: It may return a string containing a meta-method type to run
+ # instead. Put the arguments back in the queue and go through again.
+ elsif ( scalar @results == 1 and ! ref $results[0]) {
+ unshift @declarations, $results[0], \@args;
+ }
+
+ # REWRITER: It may return one or more array reference containing a meta-
+ # method type and arguments which should be created to complete this
+ # request. Put the arguments back in the queue and go through again.
+ elsif ( ! grep { ref $_ ne 'ARRAY' } @results ) {
+ unshift @declarations, ( map { shift(@$_), $_ } @results );
+ }
+
+ # CODE REFS: It may provide a list of name, code pairs to install
+ elsif ( ! scalar @results % 2 and ! ref $results[0] ) {
+ push @methods, @results;
+ }
+
+ # GENERATOR OBJECT: It may return an object reference which will construct
+ # the relevant methods.
+ elsif ( UNIVERSAL::can( $results[0], 'make_methods' ) ) {
+ push @methods, ( shift @results )->make_methods(@results, @args);
+ }
+
+ else {
+ _diagnostic('make_bad_meta', $name, join(', ', map "'$_'", @results));
+ }
+ }
+
+ _install_methods( $CONTEXT{MakerClass}, @methods );
+
+ return;
+}
+
+########################################################################
+### DECLARATION PARSING: _get_declarations()
+########################################################################
+
+sub _get_declarations {
+ my $class = shift;
+
+ my @results;
+ my %defaults;
+
+ while (scalar @_) {
+ my $m_name = shift @_;
+ if ( ! defined $m_name or ! length $m_name ) {
+ _diagnostic('make_empty')
+ }
+
+ # Various forms of default parameters
+ elsif ( substr($m_name, 0, 1) eq '-' ) {
+ if ( substr($m_name, 1, 1) ne '-' ) {
+ # Parse default values in the format "-param => value"
+ $defaults{ substr($m_name, 1) } = shift @_;
+ } elsif ( length($m_name) == 2 ) {
+ # Parse hash of default values in the format "-- => { ... }"
+ ref($_[0]) eq 'HASH' or _diagnostic('make_unsupported', $m_name.$_[0]);
+ %defaults = ( %defaults, %{ shift @_ } );
+ } else {
+ # Parse "special" arguments in the format "--foobar"
+ $defaults{ '--' } .= $m_name;
+ }
+ }
+
+ # Parse string and string-then-hash declarations
+ elsif ( ! ref $m_name ) {
+ if ( scalar @_ and ref $_[0] eq 'HASH' and ! exists $_[0]->{'name'} ) {
+ push @results, { %defaults, 'name' => $m_name, %{ shift @_ } };
+ } else {
+ push @results, { %defaults, 'name' => $m_name };
+ }
+ }
+
+ # Parse hash-only declarations
+ elsif ( ref $m_name eq 'HASH' ) {
+ if ( length $m_name->{'name'} ) {
+ push @results, { %defaults, %$m_name };
+ } else {
+ _diagnostic('make_noname');
+ }
+ }
+
+ # Normalize: If we've got an array of names, replace it with those names
+ elsif ( ref $m_name eq 'ARRAY' ) {
+ my @items = @{ $m_name };
+ # If array is followed by an params hash, each one gets the same params
+ if ( scalar @_ and ref $_[0] eq 'HASH' and ! exists $_[0]->{'name'} ) {
+ my $params = shift;
+ @items = map { $_, $params } @items
+ }
+ unshift @_, @items;
+ next;
+ }
+
+ else {
+ _diagnostic('make_unsupported', $m_name);
+ }
+
+ }
+
+ return @results;
+}
+
+########################################################################
+### FUNCTION INSTALLATION: _install_methods()
+########################################################################
+
+sub _install_methods {
+ my ($class, %methods) = @_;
+
+ no strict 'refs';
+
+ # print STDERR "CLASS: $class\n";
+ my $package = $CONTEXT{TargetClass};
+
+ my ($name, $code);
+ while (($name, $code) = each %methods) {
+
+ # Skip this if the target package already has a function by the given name.
+ next if ( ! $CONTEXT{ForceInstall} and
+ defined *{$package. '::'. $name}{CODE} );
+
+ if ( ! ref $code ) {
+ local $SIG{__DIE__};
+ local $^W;
+ my $coderef = eval $code;
+ if ( $@ ) {
+ _diagnostic('inst_eval_syntax', $name, $@, $code);
+ } elsif ( ref $coderef ne 'CODE' ) {
+ _diagnostic('inst_eval_result', $name, $coderef, $code);
+ }
+ $code = $coderef;
+ } elsif ( ref $code ne 'CODE' ) {
+ _diagnostic('inst_result', $name, $code);
+ }
+
+ # Add the code refence to the target package
+ # _diagnostic('debug_install', $package, $name, $code);
+ local $^W = 0 if ( $CONTEXT{ForceInstall} );
+ *{$package . '::' . $name} = $code;
+
+ }
+ return;
+}
+
+########################################################################
+### SUBCLASS LOADING: _find_subclass()
+########################################################################
+
+# $pckg = _find_subclass( $class, $optional_package_name );
+sub _find_subclass {
+ my $class = shift;
+ my $package = shift or die "No package for _find_subclass";
+
+ $package = $package =~ s/^::// ? $package :
+ "Class::MakeMethods::$package";
+
+ (my $file = $package . '.pm' ) =~ s|::|/|go;
+ return $package if ( $::INC{ $file } );
+
+ no strict 'refs';
+ return $package if ( @{$package . '::ISA'} );
+
+ local $SIG{__DIE__} = '';
+ eval { require $file };
+ $::INC{ $package } = $::INC{ $file };
+ if ( $@ ) { _diagnostic('mm_package_fail', $package, $@) }
+
+ return $package
+}
+
+########################################################################
+### CONTEXT: _context(), %CONTEXT
+########################################################################
+
+sub _context {
+ my $class = shift;
+ return %CONTEXT if ( ! scalar @_ );
+ my $key = shift;
+ return $CONTEXT{$key} if ( ! scalar @_ );
+ $CONTEXT{$key} = shift;
+}
+
+BEGIN {
+ $CONTEXT{Debug} ||= 0;
+}
+
+########################################################################
+### DIAGNOSTICS: _diagnostic(), %DIAGNOSTICS
+########################################################################
+
+sub _diagnostic {
+ my $case = shift;
+ my $message = $DIAGNOSTICS{$case};
+ $message =~ s/\A\s*\((\w)\)\s*//;
+ my $severity = $1 || 'I';
+ if ( $severity eq 'Q' ) {
+ carp( sprintf( $message, @_ ) ) if ( $CONTEXT{Debug} );
+ } elsif ( $severity eq 'W' ) {
+ carp( sprintf( $message, @_ ) ) if ( $^W );
+ } elsif ( $severity eq 'F' ) {
+ croak( sprintf( $message, @_ ) )
+ } else {
+ confess( sprintf( $message, @_ ) )
+ }
+}
+
+
+BEGIN { %DIAGNOSTICS = (
+
+ ### BASE CLASS DIAGNOSTICS
+
+ # _diagnostic('debug_install', $package, $name, $code)
+ debug_install => q|(W) Installing function %s::%s (%s)|,
+
+ # _diagnostic('make_odd_args', $CONTEXT{MakerClass})
+ make_odd_args => q|(F) Odd number of arguments passed to %s method generator|,
+
+ # _diagnostic('make_bad_meta', $name, join(', ', map "'$_'", @results)
+ make_bad_meta => q|(I) Unexpected return value from method constructor %s: %s|,
+
+ # _diagnostic('inst_eval_syntax', $name, $@, $code)
+ inst_eval_syntax => q|(I) Unable to compile generated method %s(): %s| .
+ qq|\n (There's probably a syntax error in this generated code.)\n%s\n|,
+
+ # _diagnostic('inst_eval_result', $name, $coderef, $code)
+ inst_eval_result => q|(I) Unexpected return value from compilation of %s(): '%s'| .
+ qq|\n (This generated code should have returned a code ref.)\n%s\n|,
+
+ # _diagnostic('inst_result', $name, $code)
+ inst_result => q|(I) Unable to install code for %s() method: '%s'|,
+
+ # _diagnostic('mm_package_fail', $package, $@)
+ mm_package_fail => q|(F) Unable to dynamically load %s: %s|,
+
+ # _diagnostic('mm_version_fail', $class, $wanted, $version || '(undef)
+ mm_version_fail => q|(F) %s %s required--this is only version %s%s|,
+
+ ### STANDARD SUBCLASS DIAGNOSTICS
+
+ # _diagnostic('make_empty')
+ make_empty => q|(F) Can't parse meta-method declaration: argument is empty or undefined|,
+
+ # _diagnostic('make_noname')
+ make_noname => q|(F) Can't parse meta-method declaration: missing name attribute.| .
+ qq|\n (Perhaps a trailing attributes hash has become separated from its name?)|,
+
+ # _diagnostic('make_unsupported', $m_name)
+ make_unsupported => q|(F) Can't parse meta-method declaration: unsupported declaration type '%s'|,
+
+ ### TEMPLATE SUBCLASS DIAGNOSTICS
+ # ToDo: Should be moved to the Class::MakeMethods::Template package
+
+ debug_declaration => q|(Q) Meta-method declaration parsed: %s|,
+ debug_make_behave => q|(Q) Building meta-method behavior %s: %s(%s)|,
+ mmdef_not_interpretable => qq|(I) Not an interpretable meta-method: '%s'| .
+ qq|\n (Perhaps a meta-method attempted to import from a non-templated meta-method?)|,
+ make_bad_modifier => q|(F) Can't parse meta-method declaration: unknown option for %s: %s|,
+ make_bad_behavior => q|(F) Can't make method %s(): template specifies unknown behavior '%s'|,
+ behavior_mod_unknown => q|(F) Unknown modification to %s behavior: -%s|,
+ debug_template_builder => qq|(Q) Template interpretation for %s:\n%s|.
+ qq|\n---------\n%s\n---------\n|,
+ debug_template => q|(Q) Parsed template '%s': %s|,
+ debug_eval_builder => q|(Q) Compiling behavior builder '%s':| . qq|\n%s|,
+ make_behavior_mod => q|(F) Can't apply modifiers (%s) to code behavior %s|,
+ behavior_eval => q|(I) Class::MakeMethods behavior compilation error: %s| .
+ qq|\n (There's probably a syntax error in the below code.)\n%s|,
+ tmpl_unkown => q|(F) Can't interpret meta-method template: unknown template name '%s'|,
+ tmpl_empty => q|(F) Can't interpret meta-method template: argument is empty or undefined|,
+ tmpl_unsupported => q|(F) Can't interpret meta-method template: unsupported template type '%s'|,
+) }
+
+1;
+
+__END__
+
+
+=head1 NAME
+
+Class::MakeMethods - Generate common types of methods
+
+
+=head1 SYNOPSIS
+
+ # Generates methods for your object when you "use" it.
+ package MyObject;
+ use Class::MakeMethods::Standard::Hash (
+ 'new' => 'new',
+ 'scalar' => 'foo',
+ 'scalar' => 'bar',
+ );
+
+ # The generated methods can be called just like normal ones
+ my $obj = MyObject->new( foo => "Foozle", bar => "Bozzle" );
+ print $obj->foo();
+ $obj->bar("Barbados");
+
+
+=head1 DESCRIPTION
+
+The Class::MakeMethods framework allows Perl class developers to
+quickly define common types of methods. When a module C<use>s
+Class::MakeMethods or one of its subclasses, it can select from a
+variety of supported method types, and specify a name for each
+method desired. The methods are dynamically generated and installed
+in the calling package.
+
+Construction of the individual methods is handled by subclasses.
+This delegation approach allows for a wide variety of method-generation
+techniques to be supported, each by a different subclass. Subclasses
+can also be added to provide support for new types of methods.
+
+Over a dozen subclasses are available, including implementations of
+a variety of different method-generation techniques. Each subclass
+generates several types of methods, with some supporting their own
+open-eneded extension syntax, for hundreds of possible combinations
+of method types.
+
+
+=head1 GETTING STARTED
+
+=head2 Motivation
+
+ "Make easy things easier."
+
+This module addresses a problem encountered in object-oriented
+development wherein numerous methods are defined which differ only
+slightly from each other.
+
+A common example is accessor methods for hash-based object attributes,
+which allow you to get and set the value $self-E<gt>{'foo'} by
+calling a method $self-E<gt>foo().
+
+These methods are generally quite simple, requiring only a couple
+of lines of Perl, but in sufficient bulk, they can cut down on the
+maintainability of large classes.
+
+Class::MakeMethods allows you to simply declare those methods to
+be of a predefined type, and it generates and installs the necessary
+methods in your package at compile-time.
+
+=head2 A Contrived Example
+
+Object-oriented Perl code is widespread -- you've probably seen code like the below a million times:
+
+ my $obj = MyStruct->new( foo=>"Foozle", bar=>"Bozzle" );
+ if ( $obj->foo() =~ /foo/i ) {
+ $obj->bar("Barbados!");
+ }
+ print $obj->summary();
+
+(If this doesn't look familiar, take a moment to read L<perlboot>
+and you'll soon learn more than's good for you.)
+
+Typically, this involves creating numerous subroutines that follow
+a handful of common patterns, like constructor methods and accessor
+methods. The classic example is accessor methods for hash-based
+object attributes, which allow you to get and set the value
+I<self>-E<gt>{I<foo>} by calling a method I<self>-E<gt>I<foo>().
+These methods are generally quite simple, requiring only a couple
+of lines of Perl, but in sufficient bulk, they can cut down on the
+maintainability of large classes.
+
+Here's a possible implementation for the class whose interface is
+shown above:
+
+ package MyStruct;
+
+ sub new {
+ my $callee = shift;
+ my $self = bless { @_ }, (ref $callee || $callee);
+ return $self;
+ }
+
+ sub foo {
+ my $self = shift;
+ if ( scalar @_ ) {
+ $self->{'foo'} = shift();
+ } else {
+ $self->{'foo'}
+ }
+ }
+
+ sub bar {
+ my $self = shift;
+ if ( scalar @_ ) {
+ $self->{'bar'} = shift();
+ } else {
+ $self->{'bar'}
+ }
+ }
+
+ sub summary {
+ my $self = shift;
+ join(', ', map { "\u$_: " . $self->$_() } qw( foo bar ) )
+ }
+
+Note in particular that the foo and bar methods are almost identical,
+and that the new method could be used for almost any class; this
+is precisely the type of redundancy Class::MakeMethods addresses.
+
+Class::MakeMethods allows you to simply declare those methods to
+be of a predefined type, and it generates and installs the necessary
+methods in your package at compile-time.
+
+Here's the equivalent declaration for that same basic class:
+
+ package MyStruct;
+ use Class::MakeMethods::Standard::Hash (
+ 'new' => 'new',
+ 'scalar' => 'foo',
+ 'scalar' => 'bar',
+ );
+
+ sub summary {
+ my $self = shift;
+ join(', ', map { "\u$_: " . $self->$_() } qw( foo bar ) )
+ }
+
+This is the basic purpose of Class::MakeMethods: The "boring" pieces
+of code have been replaced by succinct declarations, placing the
+focus on the "unique" or "custom" pieces.
+
+=head2 Finding the Method Types You Need
+
+Once you've grasped the basic idea -- simplifying repetitive code
+by generating and installing methods on demand -- the remaining
+complexity basically boils down to figuring out which arguments to
+pass to generate the specific methods you want.
+
+Unfortunately, this is not a trivial task, as there are dozens of
+different types of methods that can be generated, each with a
+variety of options, and several alternative ways to write each
+method declaration. You may prefer to start by just finding a few
+examples that you can modify to accomplish your immediate needs,
+and defer investigating all of the extras until you're ready to
+take a closer look.
+
+=head2 Other Documentation
+
+The remainder of this document focuses on points of usage that are
+common across all subclasses, and describes how to create your own
+subclasses.
+
+If this is your first exposure to Class::MakeMethods, you may want
+to skim over the rest of this document, then take a look at the
+examples and one or two of the method-generating subclasses to get
+a more concrete sense of typical usage, before returning to the
+details presented below.
+
+=over 4
+
+=item *
+
+A collection of sample uses is available in
+L<Class::MakeMethods::Docs::Examples>.
+
+=item *
+
+Some of the most common object and class methods are available from
+L<Class::MakeMethods::Standard::Hash>,
+L<Class::MakeMethods::Standard::Global> and
+L<Class::MakeMethods::Standard::Universal>.
+
+=item *
+
+If you need a bit more flexibility, see L<Class::MakeMethods::Composite>
+for method generators which offer more customization options,
+including pre- and post-method callback hooks.
+
+=item *
+
+For the largest collection of methods and options, see
+L<Class::MakeMethods::Template>, which uses a system of dynamic
+code generation to allow endless variation.
+
+=item *
+
+A listing of available method types from each of the different
+subclasses is provided in L<Class::MakeMethods::Docs::Catalog>.
+
+=back
+
+=head1 CLASS ARCHITECTURE
+
+Because there are so many common types of methods one might wish
+to generate, the Class::MakeMethods framework provides an extensible
+system based on subclasses.
+
+When your code requests a method, the MakeMethods base class performs
+some standard argument parsing, delegates the construction of the
+actual method to the appropriate subclass, and then installs whatever
+method the subclass returns.
+
+=head2 The MakeMethods Base Class
+
+The Class::MakeMethods package defines a superclass for method-generating
+modules, and provides a calling convention, on-the-fly subclass
+loading, and subroutine installation that will be shared by all
+subclasses.
+
+The superclass also lets you generate several different types of
+methods in a single call, and will automatically load named subclasses
+the first time they're used.
+
+=head2 The Method Generator Subclasses
+
+The type of method that gets created is controlled by the specific
+subclass and generator function you request. For example,
+C<Class::MakeMethods::Standard::Hash> has a generator function
+C<scalar()>, which is responsible for generating simple scalar-accessor
+methods for blessed-hash objects.
+
+Each generator function specified is passed the arguments specifying
+the method the caller wants, and produces a closure or eval-able
+sequence of Perl statements representing the ready-to-install
+function.
+
+=head2 Included Subclasses
+
+Because each subclass defines its own set of method types and
+customization options, a key step is to find your way to the
+appropriate subclasses.
+
+=over 4
+
+=item Standard (See L<Class::MakeMethods::Standard>.)
+
+Generally you will want to begin with the Standard::Hash subclass,
+to create constructor and accessor methods for working with
+blessed-hash objects (or you might choose the Standard::Array
+subclass instead). The Standard::Global subclass provides methods
+for class data shared by all objects in a class.
+
+Each Standard method declaration can optionally include a hash of
+associated parameters, which allows you to tweak some of the
+characteristics of the methods. Subroutines are bound as closures
+to a hash of each method's name and parameters. Standard::Hash and
+Standard::Array provide object constructor and accessors. The
+Standard::Global provides for static data shared by all instances
+and subclasses, while the data for Standard::Inheritable methods
+trace the inheritance tree to find values, and can be overriden
+for any subclass or instance.
+
+=item Composite (See L<Class::MakeMethods::Composite>.)
+
+For additional customization options, check out the Composite
+subclasses, which allow you to select from a more varied set of
+implementations and which allow you to adjust any specific method
+by adding your own code-refs to be run before or after it.
+
+Subroutines are bound as closures to a hash of each method's name
+and optional additional data, and to one or more subroutine references
+which make up the composite behavior of the method. Composite::Hash
+and Composite::Array provide object constructor and accessors. The
+Composite::Global provides for static data shared by all instances
+and subclasses, while the data for Composite::Inheritable methods
+can be overriden for any subclass or instance.
+
+=item Template (See L<Class::MakeMethods::Template>.)
+
+The Template subclasses provide an open-ended structure for objects
+that assemble Perl code on the fly into cachable closure-generating
+subroutines; if the method you need isn't included, you can extend
+existing methods by re-defining just the snippet of code that's
+different.
+
+Class::MakeMethods::Template extends MakeMethods with a text
+templating system that can assemble Perl code fragments into a
+desired subroutine. The code for generated methods is eval'd once
+for each type, and then repeatedly bound as closures to method-specific
+data for better performance.
+
+Templates for dozens of types of constructor, accessor, and mutator
+methods are included, ranging from from the mundane (constructors
+and value accessors for hash and array slots) to the esoteric
+(inheritable class data and "inside-out" accessors with external
+indexes).
+
+=item Basic (See L<Class::MakeMethods::Basic>.)
+
+The Basic subclasses provide stripped down method generators with
+no configurable options, for minimal functionality (and minimum
+overhead).
+
+Subroutines are bound as closures to the name of each method.
+Basic::Hash and Basic::Array provide simple object constructors
+and accessors. Basic::Global provides basic global-data accessors.
+
+=item Emulators (See L<Class::MakeMethods::Emulator>.)
+
+In several cases, Class::MakeMethods provides functionality closely
+equivalent to that of an existing module, and it is simple to map
+the existing module's interface to that of Class::MakeMethods.
+
+Emulators are included for Class::MethodMaker, Class::Accessor::Fast,
+Class::Data::Inheritable, Class::Singleton, and Class::Struct, each
+of which passes the original module's test suite, usually requiring
+only that the name of the module be changed.
+
+=item Extending
+
+Class::MakeMethods can be extended by creating subclasses that
+define additional method-generation functions. Callers can then
+specify the name of your subclass and generator function in their
+C<use Call::MakeMethods ...> statements and your function will be
+invoked to produce the required closures. See L</EXTENDING> for
+more information.
+
+=back
+
+=head2 Naming Convention for Generated Method Types
+
+Method generation functions in this document are often referred to using the 'I<MakerClass>:I<MethodType>' or 'I<MakerGroup>::I<MakerSubclass>:I<MethodType>' naming conventions. As you will see, these are simply the names of Perl packages and the names of functions that are contained in those packages.
+
+The included subclasses are grouped into several major groups, so the names used by the included subclasses and method types reflect three axes of variation, "I<Group>::I<Subclass>:I<Type>":
+
+=over 4
+
+=item Maker Group
+
+Each group shares a similar style of technical implementation and level of complexity. For example, the C<Standard::*> packages are all simple, while the C<Composite::*> packages all support pre- and post-conditions.
+
+(For a listing of the four main groups of included subclasses, see L<"/Included Subclasses">.)
+
+=item Maker Subclass
+
+Each subclass generates methods for a similar level of scoping or underlying object type. For example, the C<*::Hash> packages all make methods for objects based on blessed hashes, while the C<*::Global> packages make methods that access class-wide data that will be shared between all objects in a class.
+
+=item Method Type
+
+Each method type produces a similar type of constructor or accessor. For examples, the C<*:new> methods are all constructors, while the C<::scalar> methods are all accessors that allow you to get and set a single scalar value.
+
+=back
+
+Bearing that in mind, you should be able to guess the intent of many of the method types based on their names alone; when you see "Standard::Hash:scalar" you can read it as "a type of method to access a I<scalar> value stored in a I<hash>-based object, with a I<standard> implementation style" and know that it's going to call the scalar() function in the Class::MakeMethods::Standard::Hash package to generate the requested method.
+
+
+=head1 USAGE
+
+The supported method types, and the kinds of arguments they expect, vary from subclass to subclass; see the documentation of each subclass for details.
+
+However, the features described below are applicable to all subclasses.
+
+=head2 Invocation
+
+Methods are dynamically generated and installed into the calling
+package when you C<use Class::MakeMethods (...)> or one of its
+subclasses, or if you later call C<Class::MakeMethods-E<gt>make(...)>.
+
+The arguments to C<use> or C<make> should be pairs of a generator
+type name and an associated array of method-name arguments to pass to
+the generator.
+
+=over 4
+
+=item *
+
+use Class::MakeMethods::I<MakerClass> (
+ 'I<MethodType>' => [ I<Arguments> ], I<...>
+ );
+
+=item *
+
+Class::MakeMethods::I<MakerClass>->make (
+ 'I<MethodType>' => [ I<Arguments> ], I<...>
+ );
+
+=back
+
+You may select a specific subclass of Class::MakeMethods for
+a single generator-type/argument pair by prefixing the type name
+with a subclass name and a colon.
+
+=over 4
+
+=item *
+
+use Class::MakeMethods (
+ 'I<MakerClass>:I<MethodType>' => [ I<Arguments> ], I<...>
+ );
+
+=item *
+
+Class::MakeMethods->make (
+ 'I<MakerClass>:I<MethodType>' => [ I<Arguments> ], I<...>
+ );
+
+=back
+
+The difference between C<use> and C<make> is primarily one of precedence; the C<use> keyword acts as a BEGIN block, and is thus evaluated before C<make> would be. (See L</"About Precedence"> for additional discussion of this issue.)
+
+=head2 Alternative Invocation
+
+If you want methods to be declared at run-time when a previously-unknown
+method is invoked, see L<Class::MakeMethods::Autoload>.
+
+=over 4
+
+=item *
+
+use Class::MakeMethods::Autoload 'I<MakerClass>:I<MethodType>';
+
+=back
+
+If you are using Perl version 5.6 or later, see
+L<Class::MakeMethods::Attribute> for an additional declaration
+syntax for generated methods.
+
+=over 4
+
+=item *
+
+use Class::MakeMethods::Attribute 'I<MakerClass>';
+
+sub I<name> :MakeMethod('I<MethodType>' => I<Arguments>);
+
+=back
+
+=head2 About Precedence
+
+Rather than passing the method declaration arguments when you C<use> one of these packages, you may instead pass them to a subsequent call to the class method C<make>.
+
+The difference between C<use> and C<make> is primarily one of precedence; the C<use> keyword acts as a BEGIN block, and is thus evaluated before C<make> would be. In particular, a C<use> at the top of a file will be executed before any subroutine declarations later in the file have been seen, whereas a C<make> at the same point in the file will not.
+
+By default, Class::MakeMethods will not install generated methods over any pre-existing methods in the target class. To override this you can pass C<-ForceInstall =E<gt> 1> as initial arguments to C<use> or C<make>.
+
+If the same method is declared multiple times, earlier calls to
+C<use> or C<make()> win over later ones, but within each call,
+later declarations superceed earlier ones.
+
+Here are some examples of the results of these precedence rules:
+
+ # 1 - use, before
+ use Class::MakeMethods::Standard::Hash (
+ 'scalar'=>['baz'] # baz() not seen yet, so we generate, install
+ );
+ sub baz { 1 } # Subsequent declaration overwrites it, with warning
+
+ # 2 - use, after
+ sub foo { 1 }
+ use Class::MakeMethods::Standard::Hash (
+ 'scalar'=>['foo'] # foo() is already declared, so has no effect
+ );
+
+ # 3 - use, after, Force
+ sub bar { 1 }
+ use Class::MakeMethods::Standard::Hash (
+ -ForceInstall => 1, # Set flag for following methods...
+ 'scalar' => ['bar'] # ... now overwrites pre-existing bar()
+ );
+
+ # 4 - make, before
+ Class::MakeMethods::Standard::Hash->make(
+ 'scalar'=>['blip'] # blip() is already declared, so has no effect
+ );
+ sub blip { 1 } # Although lower than make(), this "happens" first
+
+ # 5 - make, after, Force
+ sub ping { 1 }
+ Class::MakeMethods::Standard::Hash->make(
+ -ForceInstall => 1, # Set flag for following methods...
+ 'scalar' => ['ping'] # ... now overwrites pre-existing ping()
+ );
+
+=head2 Global Options
+
+Global options may be specified as an argument pair with a leading hyphen. (This distinguishes them from type names, which must be valid Perl subroutine names, and thus will never begin with a hyphen.)
+
+use Class::MakeMethods::I<MakerClass> (
+ '-I<Param>' => I<ParamValue>,
+ 'I<MethodType>' => [ I<Arguments> ], I<...>
+ );
+
+Option settings apply to all subsequent method declarations within a single C<use> or C<make> call.
+
+The below options allow you to control generation and installation of the requested methods. (Some subclasses may support additional options; see their documentation for details.)
+
+=over 4
+
+=item -TargetClass
+
+By default, the methods are installed in the first package in the caller() stack that is not a Class::MakeMethods subclass; this is generally the package in which your use or make statement was issued. To override this you can pass C<-TargetClass =E<gt> I<package>> as initial arguments to C<use> or C<make>.
+
+This allows you to construct or modify classes "from the outside":
+
+ package main;
+
+ use Class::MakeMethods::Basic::Hash(
+ -TargetClass => 'MyWidget',
+ 'new' => ['create'],
+ 'scalar' => ['foo', 'bar'],
+ );
+
+ $o = MyWidget->new( foo => 'Foozle' );
+ print $o->foo();
+
+=item -MakerClass
+
+By default, meta-methods are looked up in the package you called
+use or make on.
+
+You can override this by passing the C<-MakerClass> flag, which
+allows you to switch packages for the remainder of the meta-method
+types and arguments.
+
+use Class::MakeMethods (
+ '-MakerClass'=>'I<MakerClass>',
+ 'I<MethodType>' => [ I<Arguments> ]
+ );
+
+When specifying the MakerClass, you may provide either the trailing
+part name of a subclass inside of the C<Class::MakeMethods::>
+namespace, or a full package name prefixed by C<::>.
+
+For example, the following four statements are equivalent ways of
+declaring a Basic::Hash scalar method named 'foo':
+
+ use Class::MakeMethods::Basic::Hash (
+ 'scalar' => [ 'foo' ]
+ );
+
+ use Class::MakeMethods (
+ 'Basic::Hash:scalar' => [ 'foo' ]
+ );
+
+ use Class::MakeMethods (
+ '-MakerClass'=>'Basic::Hash',
+ 'scalar' => [ 'foo' ]
+ );
+
+ use Class::MakeMethods (
+ '-MakerClass'=>'::Class::MakeMethods::Basic::Hash',
+ 'scalar' => [ 'foo' ]
+ );
+
+=item -ForceInstall
+
+By default, Class::MakeMethods will not install generated methods over any pre-existing methods in the target class. To override this you can pass C<-ForceInstall =E<gt> 1> as initial arguments to C<use> or C<make>.
+
+Note that the C<use> keyword acts as a BEGIN block, so a C<use> at the top of a file will be executed before any subroutine declarations later in the file have been seen. (See L</"About Precedence"> for additional discussion of this issue.)
+
+=back
+
+=head2 Mixing Method Types
+
+A single calling class can combine generated methods from different MakeMethods subclasses. In general, the only mixing that's problematic is combinations of methods which depend on different underlying object types, like using *::Hash and *::Array methods together -- the methods will be generated, but some of them are guaranteed to fail when called, depending on whether your object happens to be a blessed hashref or arrayref.
+
+For example, it's common to mix and match various *::Hash methods, with a scattering of Global or Inheritable methods:
+
+ use Class::MakeMethods (
+ 'Basic::Hash:scalar' => 'foo',
+ 'Composite::Hash:scalar' => [ 'bar' => { post_rules => [] } ],
+ 'Standard::Global:scalar' => 'our_shared_baz'
+ );
+
+=head2 Declaration Syntax
+
+The following types of Simple declarations are supported:
+
+=over 4
+
+=item *
+
+I<generator_type> => 'I<method_name>'
+
+=item *
+
+I<generator_type> => 'I<method_1> I<method_2>...'
+
+=item *
+
+I<generator_type> => [ 'I<method_1>', 'I<method_2>', ...]
+
+=back
+
+For a list of the supported values of I<generator_type>, see
+L<Class::MakeMethods::Docs::Catalog/"STANDARD CLASSES">, or the documentation
+for each subclass.
+
+For each method name you provide, a subroutine of the indicated
+type will be generated and installed under that name in your module.
+
+Method names should start with a letter, followed by zero or more
+letters, numbers, or underscores.
+
+=head2 Argument Normalization
+
+The following expansion rules are applied to argument pairs to
+enable the use of simple strings instead of arrays of arguments.
+
+=over 4
+
+=item *
+
+Each type can be followed by a single meta-method definition, or by a
+reference to an array of them.
+
+=item *
+
+If the argument is provided as a string containing spaces, it is
+split and each word is treated as a separate argument.
+
+=item *
+
+It the meta-method type string contains spaces, it is split and
+only the first word is used as the type, while the remaining words
+are placed at the front of the argument list.
+
+=back
+
+For example, the following statements are equivalent ways of
+declaring a pair of Basic::Hash scalar methods named 'foo' and 'bar':
+
+ use Class::MakeMethods::Basic::Hash (
+ 'scalar' => [ 'foo', 'bar' ],
+ );
+
+ use Class::MakeMethods::Basic::Hash (
+ 'scalar' => 'foo',
+ 'scalar' => 'bar',
+ );
+
+ use Class::MakeMethods::Basic::Hash (
+ 'scalar' => 'foo bar',
+ );
+
+ use Class::MakeMethods::Basic::Hash (
+ 'scalar foo' => 'bar',
+ );
+
+(The last of these is clearly a bit peculiar and potentially misleading if used as shown, but it enables advanced subclasses to provide convenient formatting for declarations with defaults or modifiers, such as C<'Template::Hash:scalar --private' =E<gt> 'foo'>, discussed elsewhere.)
+
+=head2 Parameter Syntax
+
+The Standard syntax also provides several ways to optionally
+associate a hash of additional parameters with a given method
+name.
+
+=over 4
+
+=item *
+
+I<generator_type> => [
+ 'I<method_1>' => { I<param>=>I<value>... }, I<...>
+ ]
+
+A hash of parameters to use just for this method name.
+
+(Note: to prevent confusion with self-contained definition hashes,
+described below, parameter hashes following a method name must not
+contain the key C<'name'>.)
+
+=item *
+
+I<generator_type> => [
+ [ 'I<method_1>', 'I<method_2>', ... ] => { I<param>=>I<value>... }
+ ]
+
+Each of these method names gets a copy of the same set of parameters.
+
+=item *
+
+I<generator_type> => [
+ { 'name'=>'I<method_1>', I<param>=>I<value>... }, I<...>
+ ]
+
+By including the reserved parameter C<'name'>, you create a self-contained declaration with that name and any associated hash values.
+
+=back
+
+Simple declarations, as shown in the prior section, are treated as if they had an empty parameter hash.
+
+=head2 Default Parameters
+
+A set of default parameters to be used for several declarations
+may be specified using any of the following types of arguments to
+a method generator call:
+
+=over 4
+
+=item *
+
+I<generator_type> => [
+ '-I<param>' => 'I<value>', 'I<method_1>', 'I<method_2>', I<...>
+ ]
+
+Set a default value for the specified parameter to be passed to all subsequent declarations.
+
+=item *
+
+I<generator_type> => [
+ '--' => { 'I<param>' => 'I<value>', ... }, 'I<method_1>', 'I<method_2>', I<...>
+ ]
+
+Set default values for one or more parameters to be passed to all subsequent declarations. Equivalent to a series of '-I<param>' => 'I<value>' pairs for each pair in the referenced hash.
+
+=item *
+
+I<generator_type> => [
+ '--I<special_param>', 'I<method_1>', 'I<method_2>', I<...>
+ ]
+
+Appends to the default value for a special parameter named "--". This parameter is currently only used by some subclasses; for details see L<Class::MakeMethods::Template>
+
+=back
+
+Parameters set in these ways are passed to each declaration that
+follows it until the end of the method-generator argument array,
+or until overridden by another declaration. Parameters specified
+in a hash for a specific method name, as discussed above, will
+override the defaults of the same name for that particular method.
+
+
+=head1 DIAGNOSTICS
+
+The following warnings and errors may be produced when using
+Class::MakeMethods to generate methods. (Note that this list does not
+include run-time messages produced by calling the generated methods.)
+
+These messages are classified as follows (listed in increasing order of
+desperation):
+
+ (Q) A debugging message, only shown if $CONTEXT{Debug} is true
+ (W) A warning.
+ (D) A deprecation.
+ (F) A fatal error in caller's use of the module.
+ (I) An internal problem with the module or subclasses.
+
+Portions of the message which may vary are denoted with a %s.
+
+=over 4
+
+=item Can't interpret meta-method template: argument is empty or
+undefined
+
+(F)
+
+=item Can't interpret meta-method template: unknown template name
+'%s'
+
+(F)
+
+=item Can't interpret meta-method template: unsupported template
+type '%s'
+
+(F)
+
+=item Can't make method %s(): template specifies unknown behavior
+'%s'
+
+(F)
+
+=item Can't parse meta-method declaration: argument is empty or
+undefined
+
+(F) You passed an undefined value or an empty string in the list
+of meta-method declarations to use or make.
+
+=item Can't parse meta-method declaration: missing name attribute.
+
+(F) You included an hash-ref-style meta-method declaration that
+did not include the required name attribute. You may have meant
+this to be an attributes hash for a previously specified name, but
+if so we were unable to locate it.
+
+=item Can't parse meta-method declaration: unknown template name
+'%s'
+
+(F) You included a template specifier of the form C<'-I<template_name>'>
+in a the list of meta-method declaration, but that template is not
+available.
+
+=item Can't parse meta-method declaration: unsupported declaration
+type '%s'
+
+(F) You included an unsupported type of value in a list of meta-method
+declarations.
+
+=item Compilation error: %s
+
+(I)
+
+=item Not an interpretable meta-method: '%s'
+
+(I)
+
+=item Odd number of arguments passed to %s make
+
+(F) You specified an odd number of arguments in a call to use or
+make. The arguments should be key => value pairs.
+
+=item Unable to compile generated method %s(): %s
+
+(I) The install_methods subroutine attempted to compile a subroutine
+by calling eval on a provided string, which failed for the indicated
+reason, usually some type of Perl syntax error.
+
+=item Unable to dynamically load $package: $%s
+
+(F)
+
+=item Unable to install code for %s() method: '%s'
+
+(I) The install_methods subroutine was passed an unsupported value
+as the code to install for the named method.
+
+=item Unexpected return value from compilation of %s(): '%s'
+
+(I) The install_methods subroutine attempted to compile a subroutine
+by calling eval on a provided string, but the eval returned something
+other than than the code ref we expect.
+
+=item Unexpected return value from meta-method constructor %s: %s
+
+(I) The requested method-generator was invoked, but it returned an unacceptable value.
+
+=back
+
+
+=head1 EXTENDING
+
+Class::MakeMethods can be extended by creating subclasses that
+define additional meta-method types. Callers then select your
+subclass using any of the several techniques described above.
+
+=head2 Creating A Subclass
+
+The begining of a typical extension might look like the below:
+
+ package My::UpperCaseMethods;
+ use strict;
+ use Class::MakeMethods '-isasubclass';
+
+ sub my_method_type { ... }
+
+You can name your subclass anything you want; it does not need to
+begin with Class::MakeMethods.
+
+The '-isasubclass' flag is a shortcut that automatically puts
+Class::MakeMethods into your package's @ISA array so that it will
+inherit the import() and make() class methods. If you omit this
+flag, you will need to place the superclass in your @ISA explicitly.
+
+Typically, the subclass should B<not> inherit from Exporter; both
+Class::MakeMethods and Exporter are based on inheriting an import
+class method, and getting a subclass to support both would require
+additional effort.
+
+=head2 Naming Method Types
+
+Each type of method that can be generated is defined in a subroutine
+of the same name. You can give your meta-method type any name that
+is a legal subroutine identifier.
+
+(Names begining with an underscore, and the names C<import> and
+C<make>, are reserved for internal use by Class::MakeMethods.)
+
+If you plan on distributing your extension, you may wish to follow
+the "Naming Convention for Generated Method Types" described above
+to facilitate reuse by others.
+
+=head2 Implementation Options
+
+Each method generation subroutine can be implemented in any one of
+the following ways:
+
+=over 4
+
+=item *
+
+Subroutine Generation
+
+Returns a list of subroutine name/code pairs.
+
+The code returned may either be a coderef, or a string containing
+Perl code that can be evaled and will return a coderef. If the eval
+fails, or anything other than a coderef is returned, then
+Class::MakeMethods croaks.
+
+For example a simple sub-class with a method type upper_case_get_set
+that generates an accessor method for each argument provided might
+look like this:
+
+ package My::UpperCaseMethods;
+ use Class::MakeMethods '-isasubclass';
+
+ sub uc_scalar {
+ my $class = shift;
+ map {
+ my $name = $_;
+ $name => sub {
+ my $self = shift;
+ if ( scalar @_ ) {
+ $self->{ $name } = uc( shift )
+ } else {
+ $self->{ $name };
+ }
+ }
+ } @_;
+ }
+
+Callers could then generate these methods as follows:
+
+ use My::UpperCaseMethods ( 'uc_scalar' => 'foo' );
+
+=item *
+
+Aliasing
+
+Returns a string containing a different meta-method type to use
+for those same arguments.
+
+For example a simple sub-class that defines a method type stored_value
+might look like this:
+
+ package My::UpperCaseMethods;
+ use Class::MakeMethods '-isasubclass';
+
+ sub regular_scalar { return 'Basic::Hash:scalar' }
+
+And here's an example usage:
+
+ use My::UpperCaseMethods ( 'regular_scalar' => [ 'foo' ] );
+
+=item *
+
+Rewriting
+
+Returns one or more array references with different meta-method
+types and arguments to use.
+
+For example, the below meta-method definition reviews the name of
+each method it's passed and creates different types of meta-methods
+based on whether the declared name is in all upper case:
+
+ package My::UpperCaseMethods;
+ use Class::MakeMethods '-isasubclass';
+
+ sub auto_detect {
+ my $class = shift;
+ my @rewrite = ( [ 'Basic::Hash:scalar' ],
+ [ '::My::UpperCaseMethods:uc_scalar' ] );
+ foreach ( @_ ) {
+ my $name_is_uppercase = ( $_ eq uc($_) ) ? 1 : 0;
+ push @{ $rewrite[ $name_is_uppercase ] }, $_
+ }
+ return @rewrite;
+ }
+
+The following invocation would then generate a regular scalar accessor method foo, and a uc_scalar method BAR:
+
+ use My::UpperCaseMethods ( 'auto_detect' => [ 'foo', 'BAR' ] );
+
+=item *
+
+Generator Object
+
+Returns an object with a method named make_methods which will be responsible for returning subroutine name/code pairs.
+
+See L<Class::MakeMethods::Template> for an example.
+
+=item *
+
+Self-Contained
+
+Your code may do whatever it wishes, and return an empty list.
+
+=back
+
+=head2 Access to Options
+
+Global option values are available through the _context() class method at the time that method generation is being performed.
+
+ package My::Maker;
+ sub my_methodtype {
+ my $class = shift;
+ warn "Installing in " . $class->_context('TargetClass');
+ ...
+ }
+
+=over 4
+
+=item *
+
+TargetClass
+
+Class into which code should be installed.
+
+=item *
+
+MakerClass
+
+Which subclass of Class::MakeMethods will generate the methods?
+
+=item *
+
+ForceInstall
+
+Controls whether generated methods will be installed over pre-existing methods in the target package.
+
+=back
+
+
+=head1 SEE ALSO
+
+=head2 License and Support
+
+For distribution, installation, support, copyright and license
+information, see L<Class::MakeMethods::Docs::ReadMe>.
+
+=head2 Package Documentation
+
+A collection of sample uses is available in
+L<Class::MakeMethods::Docs::Examples>.
+
+See the documentation for each family of subclasses:
+
+=over 4
+
+=item *
+
+L<Class::MakeMethods::Basic>
+
+=item *
+
+L<Class::MakeMethods::Standard>
+
+=item *
+
+L<Class::MakeMethods::Composite>
+
+=item *
+
+L<Class::MakeMethods::Template>
+
+=back
+
+A listing of available method types from each of the different subclasses
+is provided in L<Class::MakeMethods::Docs::Catalog>.
+
+=head2 Related Modules
+
+For a brief survey of the numerous modules on CPAN which offer some type
+of method generation, see L<Class::MakeMethods::Docs::RelatedModules>.
+
+In several cases, Class::MakeMethods provides functionality closely
+equivalent to that of an existing module, and emulator modules are provided
+to map the existing module's interface to that of Class::MakeMethods.
+See L<Class::MakeMethods::Emulator> for more information.
+
+If you have used Class::MethodMaker, you will note numerous similarities
+between the two. Class::MakeMethods is based on Class::MethodMaker, but
+has been substantially revised in order to provide a range of new features.
+Backward compatibility and conversion documentation is provded in
+L<Class::MakeMethods::Emulator::MethodMaker>.
+
+=head2 Perl Docs
+
+See L<perlboot> for a quick introduction to objects for beginners. For
+an extensive discussion of various approaches to class construction, see
+L<perltoot> and L<perltootc> (called L<perltootc> in the most recent
+versions of Perl).
+
+See L<perlref/"Making References">, point 4 for more information on
+closures. (FWIW, I think there's a big opportunity for a "perlfunt" podfile
+bundled with Perl in the tradition of "perlboot" and "perltoot", exploring
+the utility of function references, callbacks, closures, and
+continuations... There are a bunch of useful references available, but
+not a good overview of how they all interact in a Perlish way.)
+
+=cut
diff --git a/lib/Class/MakeMethods/Attribute.pm b/lib/Class/MakeMethods/Attribute.pm
new file mode 100644
index 0000000..b8fe71d
--- /dev/null
+++ b/lib/Class/MakeMethods/Attribute.pm
@@ -0,0 +1,143 @@
+package Class::MakeMethods::Attribute;
+
+require 5.006;
+use strict;
+use Carp;
+use Attribute::Handlers;
+
+use Class::MakeMethods;
+use Class::MakeMethods::Utility::Inheritable 'get_vvalue';
+
+our $VERSION = 1.005;
+
+our %DefaultMaker;
+
+sub import {
+ my $class = shift;
+
+ if ( scalar @_ and $_[0] =~ m/^\d/ ) {
+ Class::MakeMethods::_import_version( $class, shift );
+ }
+
+ if ( scalar @_ == 1 ) {
+ my $target_class = ( caller(0) )[0];
+ $DefaultMaker{ $target_class } = shift;
+ }
+}
+
+sub UNIVERSAL::MakeMethod :ATTR(CODE) {
+ my ($package, $symbol, $referent, $attr, $data) = @_;
+ if ( $symbol eq 'ANON' or $symbol eq 'LEXICAL' ) {
+ croak "Can't apply MakeMethod attribute to $symbol declaration."
+ }
+ if ( ! $data ) {
+ croak "No method type provided for MakeMethod attribute."
+ }
+ my $symname = *{$symbol}{NAME};
+ if ( ref $data eq 'ARRAY' ) {
+ local $_ = shift @$data;
+ $symname = [ @$data, $symname ];
+ $data = $_;
+ }
+ unless ( $DefaultMaker{$package} ) {
+ local $_ = get_vvalue( \%DefaultMaker, $package );
+ $DefaultMaker{$package} = $_ if ( $_ );
+ }
+ Class::MakeMethods->make(
+ -TargetClass => $package,
+ -ForceInstall => 1,
+ ( $DefaultMaker{$package} ? ('-MakerClass'=>$DefaultMaker{$package}) : () ),
+ $data => $symname
+ );
+}
+
+1;
+
+__END__
+
+=head1 NAME
+
+Class::MakeMethods::Attribute - Declare generated subs with attribute syntax
+
+=head1 SYNOPSIS
+
+ package MyObject;
+ use Class::MakeMethods::Attribute 'Standard::Hash';
+
+ sub new :MakeMethod('new');
+ sub foo :MakeMethod('scalar');
+ sub bar :MakeMethod('scalar', { hashkey => 'bar_data' });
+ sub debug :MakeMethod('Standard::Global:scalar');
+
+=head1 DESCRIPTION
+
+This package allows common types of methods to be generated via a subroutine attribute declaration. (Available in Perl 5.6 and later.)
+
+Adding the :MakeMethod() attribute to a subroutine declaration causes Class::MakeMethods to create and install a subroutine based on the parameters given to the :MakeMethod attribute.
+
+You can declare a default method-generation class by passing the name of a MakeMethods subclass in the use Class::MakeMethods::Attribute statement. This default method-generation class will also apply as the default to any subclasses declared at compile time. If no default method-generation class is selected, you will need to fully-qualify all method type declarations.
+
+=head1 EXAMPLE
+
+Here's a typical use of Class::MakeMethods::Attribute:
+
+ package MyObject;
+ use Class::MakeMethods::Attribute 'Standard::Hash';
+
+ sub new :MakeMethod('new');
+ sub foo :MakeMethod('scalar');
+ sub bar :MakeMethod('scalar', { hashkey => 'bar_data' });
+ sub debug :MakeMethod('Standard::Global:scalar');
+
+ package MySubclass;
+ use base 'MyObject';
+
+ sub bazzle :MakeMethod('scalar');
+
+This is equivalent to the following explicit Class::MakeMethods invocations:
+
+ package MyObject;
+
+ use Class::MakeMethods (
+ -MakerClass => 'Standard::Hash',
+ new => 'new',
+ scalar => 'foo',
+ scalar => [ 'ba', { hashkey => 'bar_data' } ],
+ 'Standard::Global:scalar' => 'debug',
+ );
+
+ package MySubclass;
+ use base 'MyObject';
+
+ use Class::MakeMethods (
+ -MakerClass => 'Standard::Hash',
+ scalar => 'bazzle',
+ );
+
+=head1 DIAGNOSTICS
+
+The following warnings and errors may be produced when using
+Class::MakeMethods::Attribute to generate methods. (Note that this
+list does not include run-time messages produced by calling the
+generated methods, or the standard messages produced by
+Class::MakeMethods.)
+
+=over
+
+=item Can't apply MakeMethod attribute to %s declaration.
+
+You can not use the C<:MakeMethod> attribute with lexical or anonymous subroutine declarations.
+
+=item No method type provided for MakeMethod attribute.
+
+You called C<:MakeMethod()> without the required method-type argument.
+
+=back
+
+=head1 SEE ALSO
+
+See L<Attribute::Handlers> byÊDamian Conway.
+
+See L<Class::MakeMethods> for general information about this distribution.
+
+=cut
diff --git a/lib/Class/MakeMethods/Autoload.pm b/lib/Class/MakeMethods/Autoload.pm
new file mode 100644
index 0000000..ab1a6ca
--- /dev/null
+++ b/lib/Class/MakeMethods/Autoload.pm
@@ -0,0 +1,182 @@
+package Class::MakeMethods::Autoload;
+
+use strict;
+use Carp;
+require Exporter;
+
+use Class::MakeMethods;
+use Class::MakeMethods::Utility::Inheritable 'get_vvalue';
+
+use vars qw( $VERSION @ISA @EXPORT_OK );
+
+$VERSION = 1.000;
+@ISA = qw(Exporter);
+@EXPORT_OK = qw( AUTOLOAD );
+
+########################################################################
+
+use vars qw( $AUTOLOAD %DefaultType );
+
+sub import {
+ my $class = shift;
+ my $target_class = ( caller(0) )[0];
+
+ if ( scalar @_ and $_[0] =~ m/^\d/ ) {
+ Class::MakeMethods::_import_version( $class, shift );
+ }
+
+ if ( scalar @_ == 1 ) {
+ $DefaultType{ $target_class } = shift;
+ }
+
+ __PACKAGE__->Exporter::export_to_level(1, $class, 'AUTOLOAD');
+}
+
+sub AUTOLOAD {
+ my $sym = $AUTOLOAD;
+ my ($package, $func) = ($sym =~ /(.*)::([^:]+)$/);
+
+ unless ( $DefaultType{$package} ) {
+ local $_ = get_vvalue( \%DefaultType, $package );
+ $DefaultType{$package} = $_ if ( $_ );
+ }
+
+ my $type = $DefaultType{$package}
+ or croak(__PACKAGE__ . ": No default method type for $package; can't auto-generate $func");
+
+ if ( ref $type eq 'HASH' ) {
+ my $n_type = $type->{ $func } ||
+ ( map $type->{$_}, grep { $func =~ m/\A$_\Z/ } sort { length($b) <=> length($a) } keys %$type )[0] ||
+ $type->{ '' }
+ or croak(__PACKAGE__ . ": Can't find best match for '$func' in type map (" . join(', ', keys %$type ) . ")");
+ $type = $n_type;
+ } elsif ( ref $type eq 'CODE' ) {
+ $type = &$type( $func )
+ or croak(__PACKAGE__ . ": Can't find match for '$func' in type map ($type)");
+ }
+
+ # warn "Autoload $func ($type)";
+ Class::MakeMethods->make(
+ -TargetClass => $package,
+ -ForceInstall => 1,
+ $type => $func
+ );
+
+ if ( my $sub = $package->can( $func ) ) {
+ goto &$sub;
+ } else {
+ croak(__PACKAGE__ . ": Construction of $type method ${package}::$func failed to produce usable method")
+ }
+}
+
+1;
+
+__END__
+
+=head1 NAME
+
+Class::MakeMethods::Autoload - Declare generated subs with AUTOLOAD
+
+=head1 SYNOPSIS
+
+ package MyObject;
+ use Class::MakeMethods::Autoload 'Standard::Hash::scalar';
+
+ package main;
+ my $obj = bless {}, 'MyObject';
+
+ $obj->foo("Foozle");
+ print $obj->foo();
+
+=head1 DESCRIPTION
+
+This package provides a generate-on-demand interface to Class::MakeMethods.
+
+When your class uses this package, it imports an AUTOLOAD function that resolves missing methods by using Class::MakeMethods to generate and install a standard type of method.
+
+You must specify the type of method to be generated by passing a single argument to your use Class::MakeMethods::Autoload statement, which can take any of these forms:
+
+=over 4
+
+=item *
+
+A Class::MakeMethods generator name and method type.
+
+Here are three examples:
+
+ use Class::MakeMethods::Autoload 'Standard::Hash:scalar';
+
+ use Class::MakeMethods::Autoload 'Basic::Universal::no_op';
+
+ use Class::MakeMethods::Autoload
+ '::Class::MakeMethod::Composite::Global:array';
+
+=item *
+
+A reference to a subroutine which will be called for each requested function name and which is expected to return the name of the method generator to use.
+
+Here's a contrived example which generates scalar accessors for methods except those with a digit in their name, which are treated as globals.
+
+ use Class::MakeMethods::Autoload sub {
+ my $name = shift;
+ ( $name =~ /\d/ ) ? 'Standard::Global::scalar'
+ : 'Standard::Hash::scalar'
+ };
+
+=item *
+
+A reference to a hash which defines which method type to use based on the name of the requested method. If a key exists which is an exact match for the requested function name, the associated value is used; otherwise, each of the keys is used as a regular expression, and the value of the first one that matches the function name is used. (For regular expression matching, the keys are tested in reverse length order, longest to shortest.)
+
+Here's an example which provides a new() constructor, a DESTROY() method that does nothing, and a wildcard match that provides scalar accessors for all other Autoloaded methods:
+
+ use Class::MakeMethods::Autoload {
+ 'new' => 'Standard::Hash::new',
+ '.*' => 'Standard::Hash::scalar',
+ 'DESTROY' => 'Standard::Universal::no_op',
+ };
+
+Here's a more sophisticated example which causes all-upper-case method names to be generated as globals, those with a leading upper-case letter to be generated as inheritable data methods, and others to be normal accessors:
+
+ use Class::MakeMethods::Autoload {
+ 'new' => 'Standard::Hash::new',
+ '.*' => 'Standard::Hash::scalar',
+ '[A-Z].*' => 'Standard::Inheritable::scalar',
+ '[A-Z0-9]+' => 'Standard::Global::scalar',
+ 'DESTROY' => 'Standard::Universal::no_op',
+ };
+
+=back
+
+=head1 DIAGNOSTICS
+
+The following warnings and errors may be produced when using
+Class::MakeMethods::Attribute to generate methods. (Note that this
+list does not include run-time messages produced by calling the
+generated methods, or the standard messages produced by
+Class::MakeMethods.)
+
+=over
+
+=item No default method type; can't autoload
+
+You must declare a default method type, generally by passing its
+name to a C<use Class::MakeMethods::Autoload> statement, prior to
+autoloading any methods.
+
+=item Construction of %s method %s failed to produce usable method
+
+Indicates that Autoload succesfully called Class::MakeMethods->make
+to generate the requested method, but afterwards was not able to
+invoke the generated method. You may have selected an incompatible
+method type, or the method may not have been installed sucesfully.
+
+=back
+
+=head1 SEE ALSO
+
+See L<Class::MakeMethods> for general information about this distribution.
+
+For distribution, installation, support, copyright and license
+information, see L<Class::MakeMethods::Docs::ReadMe>.
+
+=cut
diff --git a/lib/Class/MakeMethods/Basic.pm b/lib/Class/MakeMethods/Basic.pm
new file mode 100644
index 0000000..f893f5b
--- /dev/null
+++ b/lib/Class/MakeMethods/Basic.pm
@@ -0,0 +1,98 @@
+package Class::MakeMethods::Basic;
+
+use Class::MakeMethods '-isasubclass';
+
+$VERSION = 1.000;
+
+1;
+
+__END__
+
+########################################################################
+
+=head1 NAME
+
+Class::MakeMethods::Basic - Make really simple methods
+
+
+=head1 SYNOPSIS
+
+ package MyObject;
+ use Class::MakeMethods::Basic::Hash (
+ 'new' => [ 'new' ],
+ 'scalar' => [ 'foo', 'bar' ]
+ );
+
+ package main;
+
+ my $obj = MyObject->new( foo => "Foozle", bar => "Bozzle" );
+ print $obj->foo();
+ $obj->bar("Barbados");
+
+
+=head1 DESCRIPTION
+
+This document describes the various subclasses of Class::MakeMethods
+included under the Basic::* namespace, and the method types each
+one provides.
+
+The Basic subclasses provide stripped-down method-generation implementations.
+
+Subroutines are generated as closures bound to each method name.
+
+=head2 Calling Conventions
+
+When you C<use> a subclass of this package, the method declarations you provide
+as arguments cause subroutines to be generated and installed in
+your module. You can also omit the arguments to C<use> and instead make methods
+at runtime by passing the declarations to a subsequent call to
+C<make()>.
+
+You may include any number of declarations in each call to C<use>
+or C<make()>. If methods with the same name already exist, earlier
+calls to C<use> or C<make()> win over later ones, but within each
+call, later declarations superceed earlier ones.
+
+You can install methods in a different package by passing C<-TargetClass =E<gt> I<package>> as your first arguments to C<use> or C<make>.
+
+See L<Class::MakeMethods/"USAGE"> for more details.
+
+=head2 Declaration Syntax
+
+The following types of declarations are supported:
+
+=over 4
+
+=item *
+
+I<generator_type> => 'I<method_name>'
+
+=item *
+
+I<generator_type> => 'I<name_1> I<name_2>...'
+
+=item *
+
+I<generator_type> => [ 'I<name_1>', 'I<name_2>', ...]
+
+=back
+
+For a list of the supported values of I<generator_type>, see
+L<Class::MakeMethods::Docs::Catalog/"BASIC CLASSES">, or the documentation
+for each subclass.
+
+For each method name you provide, a subroutine of the indicated
+type will be generated and installed under that name in your module.
+
+Method names should start with a letter, followed by zero or more
+letters, numbers, or underscores.
+
+
+=head1 SEE ALSO
+
+See L<Class::MakeMethods> for general information about this distribution.
+
+For distribution, installation, support, copyright and license
+information, see L<Class::MakeMethods::Docs::ReadMe>.
+
+=cut
diff --git a/lib/Class/MakeMethods/Basic/Array.pm b/lib/Class/MakeMethods/Basic/Array.pm
new file mode 100644
index 0000000..c537866
--- /dev/null
+++ b/lib/Class/MakeMethods/Basic/Array.pm
@@ -0,0 +1,422 @@
+=head1 NAME
+
+Class::MakeMethods::Basic::Array - Basic array methods
+
+=head1 SYNOPSIS
+
+ package MyObject;
+ use Class::MakeMethods::Basic::Array (
+ new => 'new',
+ scalar => [ 'foo', 'bar' ],
+ array => 'my_list',
+ hash => 'my_index',
+ );
+ ...
+
+ # Constructor
+ my $obj = MyObject->new( foo => 'Foozle' );
+
+ # Scalar Accessor
+ print $obj->foo();
+
+ $obj->bar('Barbados');
+ print $obj->bar();
+
+ # Array accessor
+ $obj->my_list(0 => 'Foozle', 1 => 'Bang!');
+ print $obj->my_list(1);
+
+ # Hash accessor
+ $obj->my_index('broccoli' => 'Blah!', 'foo' => 'Fiddle');
+ print $obj->my_index('foo');
+
+
+=head1 DESCRIPTION
+
+The Basic::Array subclass of MakeMethods provides a basic
+constructor and accessors for blessed-array object instances.
+
+=head2 Calling Conventions
+
+When you C<use> this package, the method names you provide
+as arguments cause subroutines to be generated and installed in
+your module.
+
+See L<Class::MakeMethods::Basic/"Calling Conventions"> for a summary, or L<Class::MakeMethods/"USAGE"> for full details.
+
+=head2 Declaration Syntax
+
+To declare methods, pass in pairs of a method-type name followed
+by one or more method names. Valid method-type names for this
+package are listed in L<"METHOD GENERATOR TYPES">.
+
+See L<Class::MakeMethods::Basic/"Declaration Syntax"> for more
+syntax information.
+
+=cut
+
+package Class::MakeMethods::Basic::Array;
+
+$VERSION = 1.000;
+use strict;
+use Class::MakeMethods '-isasubclass';
+
+########################################################################
+
+=head2 About Positional Accessors
+
+Each accessor method claims the next available spot in the array
+to store its value in.
+
+The mapping between method names and array positions is stored in
+a hash named %FIELDS in the target package. When the first positional
+accessor is defined for a package, its %FIELDS are initialized by
+searching its inheritance tree.
+
+B<Caution>: Subclassing packages that use positional accessors is
+somewhat fragile, since you may end up with two distinct methods
+assigned to the same position. Specific cases to avoid are:
+
+=over 4
+
+=item *
+
+If you inherit from more than one class with positional accessors,
+the positions used by the two sets of methods will overlap.
+
+=item *
+
+If your superclass adds additional positional accessors after you
+declare your first, they will overlap yours.
+
+=back
+
+=cut
+
+sub _array_index {
+ my $class = shift;
+ my $name = shift;
+ no strict;
+ local $^W = 0;
+ if ( ! scalar %{$class . "::FIELDS"} ) {
+ my @classes = @{$class . "::ISA"};
+ my @fields;
+ while ( @classes ) {
+ my $superclass = shift @classes;
+ if ( scalar %{$superclass . "::FIELDS"} ) {
+ push @fields, %{$superclass . "::FIELDS"};
+ } else {
+ unshift @classes, @{$superclass . "::ISA"}
+ }
+ }
+ %{$class . "::FIELDS"} = @fields
+ }
+ my $field_hash = \%{$class . "::FIELDS"};
+ $field_hash->{$name} or $field_hash->{$name} = scalar keys %$field_hash
+}
+
+########################################################################
+
+=head1 METHOD GENERATOR TYPES
+
+=head2 new - Constructor
+
+For each method name passed, returns a subroutine with the following characteristics:
+
+=over 4
+
+=item *
+
+If called as a class method, makes a new array and blesses it into that class.
+
+=item *
+
+If called on an array-based instance, makes a copy of it and blesses the copy into the same class as the original instance.
+
+=item *
+
+If passed a list of method-value pairs, calls each named method with the associated value as an argument.
+
+=item *
+
+Returns the new instance.
+
+=back
+
+Sample declaration and usage:
+
+ package MyObject;
+ use Class::MakeMethods::Basic::Array (
+ new => 'new',
+ );
+ ...
+
+ # Bare constructor
+ my $empty = MyObject->new();
+
+ # Constructor with initial sequence of method calls
+ my $obj = MyObject->new( foo => 'Foozle', bar => 'Barbados' );
+
+ # Copy with overriding sequence of method calls
+ my $copy = $obj->new( bar => 'Bob' );
+
+=cut
+
+sub new {
+ my $class = shift;
+ map {
+ my $name = $_;
+ $name => sub {
+ my $callee = shift;
+ my $self = ref($callee) ? bless( [@$callee], ref($callee) )
+ : bless( [], $callee );
+ while ( scalar @_ ) {
+ my $method = shift;
+ $self->$method( shift );
+ }
+ return $self;
+ }
+ } @_;
+}
+
+########################################################################
+
+=head2 scalar - Instance Accessor
+
+For each method name passed, uses a closure to generate a subroutine with the following characteristics:
+
+=over 4
+
+=item *
+
+Must be called on an array-based instance.
+
+=item *
+
+Determines the array position associated with the method name, and uses that as an index into each instance to access the related value.
+
+=item *
+
+If called without any arguments returns the current value (or undef).
+
+=item *
+
+If called with an argument, stores that as the value, and returns it,
+
+=back
+
+Sample declaration and usage:
+
+ package MyObject;
+ use Class::MakeMethods::Basic::Array (
+ scalar => 'foo',
+ );
+ ...
+
+ # Store value
+ $obj->foo('Foozle');
+
+ # Retrieve value
+ print $obj->foo;
+
+=cut
+
+sub scalar {
+ my $class = shift;
+ map {
+ my $name = $_;
+ my $index = _array_index( $class->_context('TargetClass'), $name );
+ $name => sub {
+ my $self = shift;
+ if ( scalar @_ ) {
+ $self->[$index] = shift;
+ } else {
+ $self->[$index];
+ }
+ }
+ } @_;
+}
+
+########################################################################
+
+=head2 array - Instance Ref Accessor
+
+For each method name passed, uses a closure to generate a subroutine with the following characteristics:
+
+=over 4
+
+=item *
+
+Must be called on an array-based instance.
+
+=item *
+
+Determines the array position associated with the method name, and uses that as an index into each instance to access the related value.
+
+=item *
+
+The value for each instance will be a reference to an array (or undef).
+
+=item *
+
+If called without any arguments, returns the current array-ref value (or undef).
+
+=item *
+
+If called with one argument, uses that argument as an index to retrieve from the referenced array, and returns that value (or undef). If the single argument is an array ref, then a slice of the referenced array is returned.
+
+=item *
+
+If called with a list of index-value pairs, stores the value at the given index in the referenced array. If the instance's value was previously undefined, a new array is autovivified. The current value in each position will be overwritten, and later arguments with the same index will override earlier ones. Returns the current array-ref value.
+
+=back
+
+Sample declaration and usage:
+
+ package MyObject;
+ use Class::MakeMethods::Basic::Array (
+ array => 'bar',
+ );
+ ...
+
+ # Set values by position
+ $obj->bar(0 => 'Foozle', 1 => 'Bang!');
+
+ # Positions may be overwritten, and in any order
+ $obj->bar(2 => 'And Mash', 1 => 'Blah!');
+
+ # Retrieve value by position
+ print $obj->bar(1);
+
+ # Retrieve slice of values by position
+ print join(', ', $obj->bar( [0, 2] ) );
+
+ # Direct access to referenced array
+ print scalar @{ $obj->bar() };
+
+ # Reset the array contents to empty
+ @{ $obj->bar() } = ();
+
+=cut
+
+sub array {
+ my $class = shift;
+ map {
+ my $name = $_;
+ my $index = _array_index( $class->_context('TargetClass'), $name );
+ $name => sub {
+ my $self = shift;
+ if ( scalar(@_) == 0 ) {
+ return $self->[$index];
+ } elsif ( scalar(@_) == 1 ) {
+ return $self->[$index]->[ shift() ];
+ } elsif ( scalar(@_) % 2 ) {
+ Carp::croak "Odd number of items in assigment to $name";
+ } else {
+ while ( scalar(@_) ) {
+ my $k = shift();
+ $self->[$index]->[ $k ] = shift();
+ }
+ return $self->[$index];
+ }
+ }
+ } @_;
+}
+
+########################################################################
+
+=head2 hash - Instance Ref Accessor
+
+For each method name passed, uses a closure to generate a subroutine with the following characteristics:
+
+=over 4
+
+=item *
+
+Must be called on an array-based instance.
+
+=item *
+
+Determines the array position associated with the method name, and uses that as an index into each instance to access the related value.
+
+=item *
+
+The value for each instance will be a reference to a hash (or undef).
+
+=item *
+
+If called without any arguments, returns the current hash-ref value (or undef).
+
+=item *
+
+If called with one argument, uses that argument as an index to retrieve from the referenced hash, and returns that value (or undef). If the single argument is an array ref, then a slice of the referenced hash is returned.
+
+=item *
+
+If called with a list of key-value pairs, stores the value under the given key in the referenced hash. If the instance's value was previously undefined, a new hash is autovivified. The current value under each key will be overwritten, and later arguments with the same key will override earlier ones. Returns the current hash-ref value.
+
+=back
+
+Sample declaration and usage:
+
+ package MyObject;
+ use Class::MakeMethods::Basic::Array (
+ hash => 'baz',
+ );
+ ...
+
+ # Set values by key
+ $obj->baz('foo' => 'Foozle', 'bar' => 'Bang!');
+
+ # Values may be overwritten, and in any order
+ $obj->baz('broccoli' => 'Blah!', 'foo' => 'Fiddle');
+
+ # Retrieve value by key
+ print $obj->baz('foo');
+
+ # Retrieve slice of values by position
+ print join(', ', $obj->baz( ['foo', 'bar'] ) );
+
+ # Direct access to referenced hash
+ print keys %{ $obj->baz() };
+
+ # Reset the hash contents to empty
+ @{ $obj->baz() } = ();
+
+=cut
+
+sub hash {
+ my $class = shift;
+ map {
+ my $name = $_;
+ my $index = _array_index( $class->_context('TargetClass'), $name );
+ $name => sub {
+ my $self = shift;
+ if ( scalar(@_) == 0 ) {
+ return $self->[$index];
+ } elsif ( scalar(@_) == 1 ) {
+ return $self->[$index]->{ shift() };
+ } elsif ( scalar(@_) % 2 ) {
+ Carp::croak "Odd number of items in assigment to $name";
+ } else {
+ while ( scalar(@_) ) {
+ my $k = shift();
+ $self->[$index]->{ $k } = shift();
+ }
+ return $self->[$index];
+ }
+ }
+ } @_;
+}
+
+########################################################################
+
+=head1 SEE ALSO
+
+See L<Class::MakeMethods> for general information about this distribution.
+
+See L<Class::MakeMethods::Basic> for more about this family of subclasses.
+
+=cut
+
+1;
diff --git a/lib/Class/MakeMethods/Basic/Global.pm b/lib/Class/MakeMethods/Basic/Global.pm
new file mode 100644
index 0000000..21116c4
--- /dev/null
+++ b/lib/Class/MakeMethods/Basic/Global.pm
@@ -0,0 +1,298 @@
+=head1 NAME
+
+Class::MakeMethods::Basic::Global - Basic shared methods
+
+=head1 SYNOPSIS
+
+ package MyObject;
+ use Class::MakeMethods::Basic::Global (
+ scalar => [ 'foo', 'bar' ],
+ array => 'my_list',
+ hash => 'my_index',
+ );
+ ....
+
+ # Store and retrieve global values
+ MyObject->foo('Foobar');
+ print MyObject->foo();
+
+ # All instances of your class access the same values
+ $my_object->bar('Barbados');
+ print $other_one->bar();
+
+ # Array accessor
+ MyObject->my_list(0 => 'Foozle', 1 => 'Bang!');
+ print MyObject->my_list(1);
+
+ # Hash accessor
+ MyObject->my_index('broccoli' => 'Blah!', 'foo' => 'Fiddle');
+ print MyObject->my_index('foo');
+
+
+=head1 DESCRIPTION
+
+The Basic::Global subclass of MakeMethods provides basic accessors for data shared by an entire class, sometimes called "static" or "class data."
+
+=head2 Calling Conventions
+
+When you C<use> this package, the method names you provide
+as arguments cause subroutines to be generated and installed in
+your module.
+
+See L<Class::MakeMethods::Basic/"Calling Conventions"> for a summary, or L<Class::MakeMethods/"USAGE"> for full details.
+
+=head2 Declaration Syntax
+
+To declare methods, pass in pairs of a method-type name followed
+by one or more method names. Valid method-type names for this
+package are listed in L<"METHOD GENERATOR TYPES">.
+
+See L<Class::MakeMethods::Basic/"Declaration Syntax"> for more
+syntax information.
+
+=cut
+
+package Class::MakeMethods::Basic::Global;
+
+$VERSION = 1.000;
+use Class::MakeMethods '-isasubclass';
+
+########################################################################
+
+=head1 METHOD GENERATOR TYPES
+
+=head2 scalar - Shared Accessor
+
+For each method name passed, uses a closure to generate a subroutine with the following characteristics:
+
+=over 4
+
+=item *
+
+May be called as a class method, or equivalently, on any object instance.
+
+=item *
+
+Stores a global value accessible only through this method.
+
+=item *
+
+If called without any arguments returns the current value.
+
+=item *
+
+If called with an argument, stores that as the value, and returns it,
+
+=back
+
+Sample declaration and usage:
+
+ package MyObject;
+ use Class::MakeMethods::Basic::Hash (
+ scalar => 'foo',
+ );
+ ...
+
+ # Store value
+ MyObject->foo('Foozle');
+
+ # Retrieve value
+ print MyObject->foo;
+
+=cut
+
+sub scalar {
+ my $class = shift;
+ map {
+ my $name = $_;
+ $name => sub {
+ my $self = shift;
+ if ( scalar @_ ) {
+ $value = shift;
+ } else {
+ $value;
+ }
+ }
+ } @_;
+}
+
+########################################################################
+
+=head2 array - Shared Ref Accessor
+
+For each method name passed, uses a closure to generate a subroutine with the following characteristics:
+
+=over 4
+
+=item *
+
+May be called as a class method, or equivalently, on any object instance.
+
+=item *
+
+Stores a global value accessible only through this method.
+
+=item *
+
+The value will be a reference to an array (or undef).
+
+=item *
+
+If called without any arguments, returns the current array-ref value (or undef).
+
+=item *
+
+If called with one argument, uses that argument as an index to retrieve from the referenced array, and returns that value (or undef). If the single argument is an array ref, then a slice of the referenced array is returned.
+
+=item *
+
+If called with a list of index-value pairs, stores the value at the given index in the referenced array. If the value was previously undefined, a new array is autovivified. The current value in each position will be overwritten, and later arguments with the same index will override earlier ones. Returns the current array-ref value.
+
+=back
+
+Sample declaration and usage:
+
+ package MyObject;
+ use Class::MakeMethods::Basic::Hash (
+ array => 'bar',
+ );
+ ...
+
+ # Set values by position
+ $obj->bar(0 => 'Foozle', 1 => 'Bang!');
+
+ # Positions may be overwritten, and in any order
+ $obj->bar(2 => 'And Mash', 1 => 'Blah!');
+
+ # Retrieve value by position
+ print $obj->bar(1);
+
+ # Retrieve slice of values by position
+ print join(', ', $obj->bar( [0, 2] ) );
+
+ # Direct access to referenced array
+ print scalar @{ $obj->bar() };
+
+ # Reset the array contents to empty
+ @{ $obj->bar() } = ();
+
+=cut
+
+sub array {
+ my $class = shift;
+ map {
+ my $name = $_;
+ my $value = [];
+ $name => sub {
+ my $self = shift;
+ if ( scalar(@_) == 1 ) {
+ my $index = shift;
+ ref($index) ? @{$value}[ @$index ] : $value->[ $index ];
+ } elsif ( scalar(@_) % 2 ) {
+ Carp::croak "Odd number of items in assigment to $name";
+ } else {
+ while ( scalar(@_) ) {
+ $value->[ shift() ] = shift();
+ }
+ return $value;
+ }
+ }
+ } @_;
+}
+
+########################################################################
+
+=head2 hash - Shared Ref Accessor
+
+For each method name passed, uses a closure to generate a subroutine with the following characteristics:
+
+=over 4
+
+=item *
+
+May be called as a class method, or equivalently, on any object instance.
+
+=item *
+
+Stores a global value accessible only through this method.
+
+=item *
+
+The value will be a reference to a hash (or undef).
+
+=item *
+
+If called without any arguments, returns the current hash-ref value (or undef).
+
+=item *
+
+If called with one argument, uses that argument as an index to retrieve from the referenced hash, and returns that value (or undef). If the single argument is an array ref, then a slice of the referenced hash is returned.
+
+=item *
+
+If called with a list of key-value pairs, stores the value under the given key in the referenced hash. If the value was previously undefined, a new hash is autovivified. The current value under each key will be overwritten, and later arguments with the same key will override earlier ones. Returns the current hash-ref value.
+
+=back
+
+Sample declaration and usage:
+
+ package MyObject;
+ use Class::MakeMethods::Basic::Hash (
+ hash => 'baz',
+ );
+ ...
+
+ # Set values by key
+ $obj->baz('foo' => 'Foozle', 'bar' => 'Bang!');
+
+ # Values may be overwritten, and in any order
+ $obj->baz('broccoli' => 'Blah!', 'foo' => 'Fiddle');
+
+ # Retrieve value by key
+ print $obj->baz('foo');
+
+ # Retrieve slice of values by position
+ print join(', ', $obj->baz( ['foo', 'bar'] ) );
+
+ # Direct access to referenced hash
+ print keys %{ $obj->baz() };
+
+ # Reset the hash contents to empty
+ @{ $obj->baz() } = ();
+
+=cut
+
+sub hash {
+ my $class = shift;
+ map {
+ my $name = $_;
+ my $value = {};
+ $name => sub {
+ my $self = shift;
+ if ( scalar(@_) == 1 ) {
+ my $index = shift;
+ ref($index) ? @{$value}{ @$index } : $value->{ $index };
+ } elsif ( scalar(@_) % 2 ) {
+ Carp::croak "Odd number of items in assigment to $name";
+ } else {
+ while ( scalar(@_) ) {
+ my $key = shift;
+ $value->{ $key } = shift();
+ }
+ $value;
+ }
+ }
+ } @_;
+}
+
+########################################################################
+
+=head1 SEE ALSO
+
+See L<Class::MakeMethods> for general information about this distribution.
+
+See L<Class::MakeMethods::Basic> for more about this family of subclasses.
+
+=cut
+
+1;
diff --git a/lib/Class/MakeMethods/Basic/Hash.pm b/lib/Class/MakeMethods/Basic/Hash.pm
new file mode 100644
index 0000000..7a55106
--- /dev/null
+++ b/lib/Class/MakeMethods/Basic/Hash.pm
@@ -0,0 +1,362 @@
+=head1 NAME
+
+Class::MakeMethods::Basic::Hash - Basic hash methods
+
+
+=head1 SYNOPSIS
+
+ package MyObject;
+ use Class::MakeMethods::Basic::Hash (
+ new => 'new',
+ scalar => [ 'foo', 'bar' ],
+ array => 'my_list',
+ hash => 'my_index',
+ );
+ ...
+
+ # Constructor
+ my $obj = MyObject->new( foo => 'Foozle' );
+
+ # Scalar Accessor
+ print $obj->foo();
+
+ $obj->bar('Barbados');
+ print $obj->bar();
+
+ # Array accessor
+ $obj->my_list(0 => 'Foozle', 1 => 'Bang!');
+ print $obj->my_list(1);
+
+ # Hash accessor
+ $obj->my_index('broccoli' => 'Blah!', 'foo' => 'Fiddle');
+ print $obj->my_index('foo');
+
+
+=head1 DESCRIPTION
+
+The Basic::Hash subclass of MakeMethods provides a basic constructor and accessors for blessed-hash object instances.
+
+=head2 Calling Conventions
+
+When you C<use> this package, the method names you provide
+as arguments cause subroutines to be generated and installed in
+your module.
+
+See L<Class::MakeMethods::Basic/"Calling Conventions"> for a summary, or L<Class::MakeMethods/"USAGE"> for full details.
+
+=head2 Declaration Syntax
+
+To declare methods, pass in pairs of a method-type name followed
+by one or more method names. Valid method-type names for this
+package are listed in L<"METHOD GENERATOR TYPES">.
+
+See L<Class::MakeMethods::Basic/"Declaration Syntax"> for more
+syntax information.
+
+
+=cut
+
+package Class::MakeMethods::Basic::Hash;
+
+$VERSION = 1.000;
+use strict;
+use Class::MakeMethods '-isasubclass';
+
+########################################################################
+
+=head1 METHOD GENERATOR TYPES
+
+=head2 new - Constructor
+
+For each method name passed, returns a subroutine with the following characteristics:
+
+=over 4
+
+=item *
+
+If called as a class method, makes a new hash and blesses it into that class.
+
+=item *
+
+If called on a hash-based instance, makes a copy of it and blesses the copy into the same class as the original instance.
+
+=item *
+
+If passed a list of key-value pairs, appends them to the new hash. These arguments override any copied values, and later arguments with the same name will override earlier ones.
+
+=item *
+
+Returns the new instance.
+
+=back
+
+Sample declaration and usage:
+
+ package MyObject;
+ use Class::MakeMethods::Basic::Hash (
+ new => 'new',
+ );
+ ...
+
+ # Bare constructor
+ my $empty = MyObject->new();
+
+ # Constructor with initial values
+ my $obj = MyObject->new( foo => 'Foozle', bar => 'Barbados' );
+
+ # Copy with overriding value
+ my $copy = $obj->new( bar => 'Bob' );
+
+=cut
+
+sub new {
+ my $class = shift;
+ map {
+ my $name = $_;
+ $name => sub {
+ my $callee = shift;
+ if ( ref $callee ) {
+ bless { %$callee, @_ }, ref $callee;
+ } else {
+ bless { @_ }, $callee;
+ }
+ }
+ } @_;
+}
+
+########################################################################
+
+=head2 scalar - Instance Accessor
+
+For each method name passed, uses a closure to generate a subroutine with the following characteristics:
+
+=over 4
+
+=item *
+
+Must be called on a hash-based instance.
+
+=item *
+
+Uses the method name as a hash key to access the related value for each instance.
+
+=item *
+
+If called without any arguments returns the current value.
+
+=item *
+
+If called with an argument, stores that as the value, and returns it,
+
+=back
+
+Sample declaration and usage:
+
+ package MyObject;
+ use Class::MakeMethods::Basic::Hash (
+ scalar => 'foo',
+ );
+ ...
+
+ # Store value
+ $obj->foo('Foozle');
+
+ # Retrieve value
+ print $obj->foo;
+
+=cut
+
+sub scalar {
+ my $class = shift;
+ map {
+ my $name = $_;
+ $name => sub {
+ if ( scalar @_ > 1 ) {
+ $_[0]->{$name} = $_[1];
+ } else {
+ $_[0]->{$name};
+ }
+ }
+ } @_;
+}
+
+########################################################################
+
+=head2 array - Instance Ref Accessor
+
+For each method name passed, uses a closure to generate a subroutine with the following characteristics:
+
+=over 4
+
+=item *
+
+Must be called on a hash-based instance.
+
+=item *
+
+Uses the method name as a hash key to access the related value for each instance.
+
+=item *
+
+The value for each instance will be a reference to an array (or undef).
+
+=item *
+
+If called without any arguments, returns the current array-ref value (or undef).
+
+=item *
+
+If called with one argument, uses that argument as an index to retrieve from the referenced array, and returns that value (or undef).
+
+=item *
+
+If called with a list of index-value pairs, stores the value at the given index in the referenced array. If the instance's value was previously undefined, a new array is autovivified. The current value in each position will be overwritten, and later arguments with the same index will override earlier ones. Returns the current array-ref value.
+
+=back
+
+Sample declaration and usage:
+
+ package MyObject;
+ use Class::MakeMethods::Basic::Hash (
+ array => 'bar',
+ );
+ ...
+
+ # Set values by position
+ $obj->bar(0 => 'Foozle', 1 => 'Bang!');
+
+ # Positions may be overwritten, and in any order
+ $obj->bar(2 => 'And Mash', 1 => 'Blah!');
+
+ # Retrieve value by position
+ print $obj->bar(1);
+
+ # Direct access to referenced array
+ print scalar @{ $obj->bar() };
+
+ # Reset the array contents to empty
+ @{ $obj->bar() } = ();
+
+=cut
+
+sub array {
+ my $class = shift;
+ map {
+ my $name = $_;
+ $name => sub {
+ my $self = shift;
+ if ( scalar(@_) == 0 ) {
+ return $self->{$name};
+ } elsif ( scalar(@_) == 1 ) {
+ $self->{$name}->[ shift() ];
+ } elsif ( scalar(@_) % 2 ) {
+ Carp::croak "Odd number of items in assigment to $name";
+ } else {
+ while ( scalar(@_) ) {
+ my $key = shift();
+ $self->{$name}->[ $key ] = shift();
+ }
+ return $self->{$name};
+ }
+ }
+ } @_;
+}
+
+########################################################################
+
+=head2 hash - Instance Ref Accessor
+
+For each method name passed, uses a closure to generate a subroutine with the following characteristics:
+
+=over 4
+
+=item *
+
+Must be called on a hash-based instance.
+
+=item *
+
+Uses the method name as a hash key to access the related value for each instance.
+
+=item *
+
+The value for each instance will be a reference to a hash (or undef).
+
+=item *
+
+If called without any arguments, returns the current hash-ref value (or undef).
+
+=item *
+
+If called with one argument, uses that argument as an index to retrieve from the referenced hash, and returns that value (or undef).
+
+=item *
+
+If called with a list of key-value pairs, stores the value under the given key in the referenced hash. If the instance's value was previously undefined, a new hash is autovivified. The current value under each key will be overwritten, and later arguments with the same key will override earlier ones. Returns the current hash-ref value.
+
+=back
+
+Sample declaration and usage:
+
+ package MyObject;
+ use Class::MakeMethods::Basic::Hash (
+ hash => 'baz',
+ );
+ ...
+
+ # Set values by key
+ $obj->baz('foo' => 'Foozle', 'bar' => 'Bang!');
+
+ # Values may be overwritten, and in any order
+ $obj->baz('broccoli' => 'Blah!', 'foo' => 'Fiddle');
+
+ # Retrieve value by key
+ print $obj->baz('foo');
+
+ # Direct access to referenced hash
+ print keys %{ $obj->baz() };
+
+ # Reset the hash contents to empty
+ @{ $obj->baz() } = ();
+
+=cut
+
+sub hash {
+ my $class = shift;
+ map {
+ my $name = $_;
+ $name => sub {
+ my $self = shift;
+ if ( scalar(@_) == 0 ) {
+ return $self->{$name};
+ } elsif ( scalar(@_) == 1 ) {
+ $self->{$name}->{ shift() };
+ } elsif ( scalar(@_) % 2 ) {
+ Carp::croak "Odd number of items in assigment to $name";
+ } else {
+ while ( scalar(@_) ) {
+ $self->{$name}->{ shift() } = shift();
+ }
+ return $self->{$name};
+ }
+ }
+ } @_;
+}
+
+########################################################################
+
+=head1 SEE ALSO
+
+See L<Class::MakeMethods> for general information about this distribution.
+
+See L<Class::MakeMethods::Basic> for more about this family of subclasses.
+
+See L<Class::MakeMethods::Basic::Array> for equivalent functionality
+based on blessed arrays. If all access to your object is through
+constructors and accessors declared using this package, and your
+class will not be extensively subclassed, consider switching to
+Basic::Array to minimize resource consumption.
+
+=cut
+
+1;
diff --git a/lib/Class/MakeMethods/Composite.pm b/lib/Class/MakeMethods/Composite.pm
new file mode 100644
index 0000000..902c235
--- /dev/null
+++ b/lib/Class/MakeMethods/Composite.pm
@@ -0,0 +1,218 @@
+=head1 NAME
+
+Class::MakeMethods::Composite - Make extensible compound methods
+
+
+=head1 SYNOPSIS
+
+ package MyObject;
+ use Class::MakeMethods::Composite::Hash (
+ new => 'new',
+ scalar => [ 'foo', 'bar' ],
+ array => 'my_list',
+ hash => 'my_index',
+ );
+
+
+=head1 DESCRIPTION
+
+This document describes the various subclasses of Class::MakeMethods
+included under the Composite::* namespace, and the method types each
+one provides.
+
+The Composite subclasses provide a parameterized set of method-generation
+implementations.
+
+Subroutines are generated as closures bound to a hash containing
+the method name and additional parameters, including the arrays of subroutine references that will provide the method's functionality.
+
+
+=head2 Calling Conventions
+
+When you C<use> this package, the method names you provide
+as arguments cause subroutines to be generated and installed in
+your module.
+
+See L<Class::MakeMethods::Standard/"Calling Conventions"> for more information.
+
+=head2 Declaration Syntax
+
+To declare methods, pass in pairs of a method-type name followed
+by one or more method names.
+
+Valid method-type names for this package are listed in L<"METHOD
+GENERATOR TYPES">.
+
+See L<Class::MakeMethods::Standard/"Declaration Syntax"> and L<Class::MakeMethods::Standard/"Parameter Syntax"> for more information.
+
+=cut
+
+package Class::MakeMethods::Composite;
+
+$VERSION = 1.000;
+use strict;
+use Class::MakeMethods '-isasubclass';
+use Carp;
+
+########################################################################
+
+=head2 About Composite Methods
+
+The methods generated by Class::MakeMethods::Composite are assembled
+from groups of "fragment" subroutines, each of which provides some
+aspect of the method's behavior.
+
+You can add pre- and post- operations to any composite method.
+
+ package MyObject;
+ use Class::MakeMethods::Composite::Hash (
+ new => 'new',
+ scalar => [
+ 'foo' => {
+ 'pre_rules' => [
+ sub {
+ # Don't automatically convert list to array-ref
+ croak "Too many arguments" if ( scalar @_ > 2 );
+ }
+ ],
+ 'post_rules' => [
+ sub {
+ # Don't let anyone see my credit card number!
+ ${(pop)->{result}} =~ s/\d{13,16}/****/g;
+ }
+ ],
+ }
+ ],
+ );
+
+=cut
+
+use vars qw( $Method );
+
+sub CurrentMethod {
+ $Method;
+}
+
+sub CurrentResults {
+ my $package = shift;
+ if ( ! scalar @_ ) {
+ ( ! $Method->{result} ) ? () :
+ ( ref($Method->{result}) eq 'ARRAY' ) ? @{$Method->{result}} :
+ ${$Method->{result}};
+ } elsif ( scalar @_ == 1) {
+ my $value = shift;
+ $Method->{result} = \$value;
+ $value
+ } else {
+ my @value = @_;
+ $Method->{result} = \@value;
+ @value;
+ }
+}
+
+sub _build_composite {
+ my $class = shift;
+ my $fragments = shift;
+ map {
+ my $method = $_;
+ my @fragments = @{ $fragments->{''} };
+ foreach my $flagname ( grep $method->{$_}, qw/ permit modifier / ) {
+ my $value = $method->{$flagname};
+ my $fragment = $fragments->{$value}
+ or croak "Unsupported $flagname flag '$value'";
+ push @fragments, @$fragment;
+ }
+ _bind_composite( $method, @fragments );
+ } $class->_get_declarations(@_)
+}
+
+sub _assemble_fragments {
+ my $method = shift;
+ my @fragments = @_;
+ while ( scalar @fragments ) {
+ my ($rule, $sub) = splice( @fragments, 0, 2 );
+ if ( $rule =~ s/\A\+// ) {
+ unshift @{$method->{"${rule}_rules"}}, $sub
+ } elsif ( $rule =~ s/\+\Z// ) {
+ push @{$method->{"${rule}_rules"}}, $sub
+ } elsif ( $rule =~ /\A\w+\Z/ ) {
+ @{$method->{"${rule}_rules"}} = $sub;
+ } else {
+ croak "Unsupported rule type '$rule'"
+ }
+ }
+}
+
+sub _bind_composite {
+ my $method = shift;
+ _assemble_fragments( $method, @_ );
+ if ( my $subs = $method->{"init_rules"} ) {
+ foreach my $sub ( @$subs ) {
+ &$sub( $method );
+ }
+ }
+ $method->{name} => sub {
+ local $Method = $method;
+ local $Method->{args} = [ @_ ];
+ local $Method->{result};
+ local $Method->{scratch};
+ # Strange but true: you can local a hash-value in hash that's not
+ # a package variable. Confirmed in in 5.004, 5.005, 5.6.0.
+
+ local $Method->{wantarray} = wantarray;
+
+ if ( my $subs = $Method->{"pre_rules"} ) {
+ foreach my $sub ( @$subs ) {
+ &$sub( @{$Method->{args}}, $Method );
+ }
+ }
+
+ my $subs = $Method->{"do_rules"}
+ or Carp::confess("No operations provided for $Method->{name}");
+ if ( ! defined $Method->{wantarray} ) {
+ foreach my $sub ( @$subs ) {
+ last if $Method->{result};
+ &$sub( @{$Method->{args}}, $Method );
+ }
+ } elsif ( ! $Method->{wantarray} ) {
+ foreach my $sub ( @$subs ) {
+ last if $Method->{result};
+ my $value = &$sub( @{$Method->{args}}, $Method );
+ if ( defined $value ) {
+ $Method->{result} = \$value;
+ }
+ }
+ } else {
+ foreach my $sub ( @$subs ) {
+ last if $Method->{result};
+ my @value = &$sub( @{$Method->{args}}, $Method );
+ if ( scalar @value ) {
+ $Method->{result} = \@value;
+ }
+ }
+ }
+
+ if ( my $subs = $Method->{"post_rules"} ) {
+ foreach my $sub ( @$subs ) {
+ &$sub( @{$Method->{args}}, $Method );
+ }
+ }
+
+ ( ! $Method->{result} ) ? () :
+ ( ref($Method->{result}) eq 'ARRAY' ) ? @{$Method->{result}} :
+ ${$Method->{result}};
+ }
+}
+
+########################################################################
+
+=head1 SEE ALSO
+
+See L<Class::MakeMethods> for general information about this distribution.
+
+For distribution, installation, support, copyright and license
+information, see L<Class::MakeMethods::Docs::ReadMe>.
+
+=cut
+
+1;
diff --git a/lib/Class/MakeMethods/Composite/Array.pm b/lib/Class/MakeMethods/Composite/Array.pm
new file mode 100644
index 0000000..fe04eba
--- /dev/null
+++ b/lib/Class/MakeMethods/Composite/Array.pm
@@ -0,0 +1,794 @@
+=head1 NAME
+
+Class::MakeMethods::Composite::Array - Basic array methods
+
+=head1 SYNOPSIS
+
+ package MyObject;
+ use Class::MakeMethods::Composite::Array (
+ new => 'new',
+ scalar => [ 'foo', 'bar' ],
+ array => 'my_list',
+ hash => 'my_index',
+ );
+ ...
+
+ my $obj = MyObject->new( foo => 'Foozle' );
+ print $obj->foo();
+
+ $obj->bar('Barbados');
+ print $obj->bar();
+
+ $obj->my_list(0 => 'Foozle', 1 => 'Bang!');
+ print $obj->my_list(1);
+
+ $obj->my_index('broccoli' => 'Blah!', 'foo' => 'Fiddle');
+ print $obj->my_index('foo');
+
+=head1 DESCRIPTION
+
+The Composite::Array suclass of MakeMethods provides a basic
+constructor and accessors for blessed-array object instances.
+
+=head2 Class::MakeMethods Calling Conventions
+
+When you C<use> this package, the method declarations you provide
+as arguments cause subroutines to be generated and installed in
+your module.
+
+You can also omit the arguments to C<use> and instead make methods
+at runtime by passing the declarations to a subsequent call to
+C<make()>.
+
+You may include any number of declarations in each call to C<use>
+or C<make()>. If methods with the same name already exist, earlier
+calls to C<use> or C<make()> win over later ones, but within each
+call, later declarations superceed earlier ones.
+
+You can install methods in a different package by passing C<-TargetClass =E<gt> I<package>> as your first arguments to C<use> or C<make>.
+
+See L<Class::MakeMethods> for more details.
+
+=head2 Class::MakeMethods::Basic Declaration Syntax
+
+The following types of Basic declarations are supported:
+
+=over 4
+
+=item *
+
+I<generator_type> => "I<method_name>"
+
+=item *
+
+I<generator_type> => "I<name_1> I<name_2>..."
+
+=item *
+
+I<generator_type> => [ "I<name_1>", "I<name_2>", ...]
+
+=back
+
+See the "METHOD GENERATOR TYPES" section below for a list of the supported values of I<generator_type>.
+
+For each method name you provide, a subroutine of the indicated
+type will be generated and installed under that name in your module.
+
+Method names should start with a letter, followed by zero or more
+letters, numbers, or underscores.
+
+=head2 Class::MakeMethods::Composite Declaration Syntax
+
+The Composite syntax also provides several ways to optionally
+associate a hash of additional parameters with a given method
+name.
+
+=over 4
+
+=item *
+
+I<generator_type> => [ "I<name_1>" => { I<param>=>I<value>... }, ... ]
+
+A hash of parameters to use just for this method name.
+
+(Note: to prevent confusion with self-contained definition hashes,
+described below, parameter hashes following a method name must not
+contain the key 'name'.)
+
+=item *
+
+I<generator_type> => [ [ "I<name_1>", "I<name_2>", ... ] => { I<param>=>I<value>... } ]
+
+Each of these method names gets a copy of the same set of parameters.
+
+=item *
+
+I<generator_type> => [ { "name"=>"I<name_1>", I<param>=>I<value>... }, ... ]
+
+By including the reserved parameter C<name>, you create a self
+contained declaration with that name and any associated hash values.
+
+=back
+
+Basic declarations, as described above, are treated as having an empty parameter hash.
+
+=cut
+
+package Class::MakeMethods::Composite::Array;
+
+$VERSION = 1.000;
+use strict;
+use Class::MakeMethods::Composite '-isasubclass';
+
+########################################################################
+
+=head2 Positional Accessors and %FIELDS
+
+Each accessor method is assigned the next available array index at
+which to store its value.
+
+The mapping between method names and array positions is stored in
+a hash named %FIELDS in the declaring package. When a package
+declares its first positional accessor, its %FIELDS are initialized
+by searching its inheritance tree.
+
+B<Warning>: Subclassing packages that use positional accessors is
+somewhat fragile, since you may end up with two distinct methods assigned to the same position. Specific cases to avoid are:
+
+=over 4
+
+=item *
+
+If you inherit from more than one class with positional accessors,
+the positions used by the two sets of methods will overlap.
+
+=item *
+
+If your superclass adds additional positional accessors after you
+declare your first, they will overlap yours.
+
+=back
+
+=cut
+
+sub _array_index {
+ my $class = shift;
+ my $name = shift;
+ no strict;
+ local $^W = 0;
+ if ( ! scalar %{$class . "::FIELDS"} ) {
+ my @classes = @{$class . "::ISA"};
+ my @fields;
+ while ( @classes ) {
+ my $superclass = shift @classes;
+ if ( scalar %{$superclass . "::FIELDS"} ) {
+ push @fields, %{$superclass . "::FIELDS"};
+ } else {
+ unshift @classes, @{$superclass . "::ISA"}
+ }
+ }
+ %{$class . "::FIELDS"} = @fields
+ }
+ my $field_hash = \%{$class . "::FIELDS"};
+ $field_hash->{$name} or $field_hash->{$name} = scalar keys %$field_hash
+}
+
+########################################################################
+
+=head1 METHOD GENERATOR TYPES
+
+=head2 new - Constructor
+
+For each method name passed, returns a subroutine with the following characteristics:
+
+=over 4
+
+=item *
+
+Has a reference to a sample item to copy. This defaults to a reference to an empty array, but you may override this with the C<'defaults' => I<array_ref>> method parameter.
+
+=item *
+
+If called as a class method, makes a new array containing values from the sample item, and blesses it into that class.
+
+=item *
+
+If called on an array-based instance, makes a copy of it and blesses the copy into the same class as the original instance.
+
+=item *
+
+If passed a list of method-value pairs, calls each named method with the associated value as an argument.
+
+=item *
+
+Returns the new instance.
+
+=back
+
+Sample declaration and usage:
+
+ package MyObject;
+ use Class::MakeMethods::Composite::Array (
+ new => 'new',
+ );
+ ...
+
+ # Bare constructor
+ my $empty = MyObject->new();
+
+ # Constructor with initial sequence of method calls
+ my $obj = MyObject->new( foo => 'Foozle', bar => 'Barbados' );
+
+ # Copy with overriding sequence of method calls
+ my $copy = $obj->new( bar => 'Bob' );
+
+=cut
+
+use vars qw( %ConstructorFragments );
+
+sub new {
+ (shift)->_build_composite( \%ConstructorFragments, @_ );
+}
+
+%ConstructorFragments = (
+ '' => [
+ '+init' => sub {
+ my $method = pop @_;
+ $method->{target_class} ||= $Class::MethodMaker::CONTEXT{TargetClass};
+ $method->{defaults} ||= [];
+ },
+ 'do' => sub {
+ my $method = pop @_;
+ my $self = shift @_;
+ my $obj = ref($self) ? bless( [ @$self ], ref $self )
+ : bless( { @[$method->{defaults}] }, $self );
+ @_ = %{$_[0]}
+ if ( scalar @_ == 1 and ref $_[0] eq 'HASH' );
+ while ( scalar @_ ) {
+ my $method = shift @_;
+ $obj->$method( shift @_ );
+ }
+ $obj;
+ },
+ ],
+ 'with_values' => [
+ 'do' => sub {
+ my $method = pop @_;
+ my $self = shift @_;
+ @_ = @[$_[0]]
+ if ( scalar @_ == 1 and ref $_[0] eq 'ARRAY' );
+ bless( [ @_ ], ref($self) || $self );
+ }
+ ],
+);
+
+########################################################################
+
+=head2 new_with_values - Constructor
+
+For each method name passed, returns a subroutine with the following characteristics:
+
+=over 4
+
+=item *
+
+May be called as a class method, or (equivalently) on any existing object of that class.
+
+=item *
+
+Creates an array, blesses it into the class, and returns the new instance.
+
+=item *
+
+If no arguments are provided, the returned array will be empty. If passed a single array-ref argument, copies its contents into the new array. If called with multiple arguments, copies them into the new array. (Note that this is a "shallow" copy, not a "deep" clone.)
+
+=back
+
+Sample declaration and usage:
+
+ package MyObject;
+ use Class::MakeMethods::Composite::Array (
+ new => 'new',
+ );
+ ...
+
+ # Bare constructor
+ my $empty = MyObject->new();
+
+ # Constructor with initial sequence of method calls
+ my $obj = MyObject->new( foo => 'Foozle', bar => 'Barbados' );
+
+ # Copy with overriding sequence of method calls
+ my $copy = $obj->new( bar => 'Bob' );
+
+=cut
+
+########################################################################
+
+=head2 scalar - Instance Accessor
+
+For each method name passed, uses a closure to generate a subroutine with the following characteristics:
+
+=over 4
+
+=item *
+
+Must be called on an array-based instance.
+
+=item *
+
+Determines the array position associated with the method name, and uses that as an index into each instance to access the related value. This defaults to the next available slot in %FIELDS, but you may override this with the C<'array_index' => I<number>> method parameter, or by pre-filling the contents of %FIELDS.
+
+=item *
+
+If called without any arguments returns the current value (or undef).
+
+=item *
+
+If called with an argument, stores that as the value, and returns it,
+
+=item *
+
+If called with multiple arguments, stores a reference to a new array with those arguments as contents, and returns that array reference.
+
+=back
+
+Sample declaration and usage:
+
+ package MyObject;
+ use Class::MakeMethods::Composite::Array (
+ scalar => 'foo',
+ );
+ ...
+
+ # Store value
+ $obj->foo('Foozle');
+
+ # Retrieve value
+ print $obj->foo;
+
+=cut
+
+use vars qw( %ScalarFragments );
+
+sub scalar {
+ (shift)->_build_composite( \%ScalarFragments, @_ );
+}
+
+%ScalarFragments = (
+ '' => [
+ '+init' => sub {
+ my ($method) = @_;
+ $method->{target_class} ||= $Class::MethodMaker::CONTEXT{TargetClass};
+ $method->{array_index} ||=
+ _array_index( $method->{target_class}, $name );
+ },
+ 'do' => sub {
+ my $method = pop @_;
+ my $self = shift @_;
+ if ( scalar(@_) == 0 ) {
+ $self->[$method->{array_index}];
+ } elsif ( scalar(@_) == 1 ) {
+ $self->[$method->{array_index}] = shift;
+ } else {
+ $self->[$method->{array_index}] = [@_];
+ }
+ },
+ ],
+ 'rw' => [],
+ 'p' => [
+ '+pre' => sub {
+ my $method = pop @_;
+ my $self = shift @_;
+ my $args = \@_;
+ unless ( UNIVERSAL::isa((caller(1))[0], $method->{target_class}) ) {
+ croak "Method $method->{name} is protected";
+ }
+ },
+ ],
+ 'pp' => [
+ '+pre' => sub {
+ my $method = pop @_;
+ my $self = shift @_;
+ my $args = \@_;
+ unless ( (caller(1))[0] eq $method->{target_class} ) {
+ croak "Method $method->{name} is private";
+ }
+ },
+ ],
+ 'pw' => [
+ '+pre' => sub {
+ my $method = pop @_;
+ my $self = shift @_;
+ my $args = \@_;
+ unless ( @$args == 0 or UNIVERSAL::isa((caller(1))[0], $method->{target_class}) ) {
+ croak "Method $method->{name} is write-protected";
+ }
+ },
+ ],
+ 'ppw' => [
+ '+pre' => sub {
+ my $method = pop @_;
+ my $self = shift @_;
+ my $args = \@_;
+ unless ( @$args == 0 or (caller(1))[0] eq $method->{target_class} ) {
+ croak "Method $method->{name} is write-private";
+ }
+ },
+ ],
+ 'r' => [
+ '+pre' => sub {
+ my $method = pop @_;
+ my $self = shift @_;
+ my $args = \@_;
+ @$args = ();
+ },
+ ],
+ 'ro' => [
+ '+pre' => sub {
+ my $method = pop @_;
+ my $self = shift @_;
+ my $args = \@_;
+ unless ( @$args == 0 ) {
+ croak("Method $method->{name} is read-only");
+ }
+ },
+ ],
+ 'wo' => [
+ '+pre' => sub {
+ my $method = pop @_;
+ my $self = shift @_;
+ my $args = \@_;
+ if ( @$args == 0 ) {
+ croak("Method $method->{name} is write-only");
+ }
+ },
+ ],
+ 'return_original' => [
+ '+pre' => sub {
+ my $method = pop @_;
+ my $self = shift @_;
+ my $args = \@_;
+ $method->{scratch}{return_original} = $self->[$method->{array_index}];
+ },
+ '+post' => sub {
+ my $method = pop @_;
+ my $self = shift @_;
+ my $args = \@_;
+ $method->{result} = \{ $method->{scratch}{return_original} };
+ },
+ ],
+);
+
+########################################################################
+
+=head2 array - Instance Ref Accessor
+
+For each method name passed, uses a closure to generate a subroutine with the following characteristics:
+
+=over 4
+
+=item *
+
+Must be called on an array-based instance.
+
+=item *
+
+Determines the array position associated with the method name, and uses that as an index into each instance to access the related value. This defaults to the next available slot in %FIELDS, but you may override this with the C<'array_index' => I<number>> method parameter, or by pre-filling the contents of %FIELDS.
+
+=item *
+
+The value for each instance will be a reference to an array (or undef).
+
+=item *
+
+If called without any arguments, returns the current array-ref value (or undef).
+
+=item *
+
+If called with a single non-ref argument, uses that argument as an index to retrieve from the referenced array, and returns that value (or undef).
+
+=item *
+
+If called with a single array ref argument, uses that list to return a slice of the referenced array.
+
+=item *
+
+If called with a list of argument pairs, each with a non-ref index and an associated value, stores the value at the given index in the referenced array. If the instance's value was previously undefined, a new array is autovivified. The current value in each position will be overwritten, and later arguments with the same index will override earlier ones. Returns the current array-ref value.
+
+=item *
+
+If called with a list of argument pairs, each with the first item being a reference to an array of up to two numbers, loops over each pair and uses those numbers to splice the value array.
+
+The first controlling number is the position at which the splice will begin. Zero will start before the first item in the list. Negative numbers count backwards from the end of the array.
+
+The second number is the number of items to be removed from the list. If it is omitted, or undefined, or zero, no items are removed. If it is a positive integer, that many items will be returned.
+
+If both numbers are omitted, or are both undefined, they default to containing the entire value array.
+
+If the second argument is undef, no values will be inserted; if it is a non-reference value, that one value will be inserted; if it is an array-ref, its values will be copied.
+
+The method returns the items that removed from the array, if any.
+
+=back
+
+Sample declaration and usage:
+
+ package MyObject;
+ use Class::MakeMethods::Composite::Array (
+ array => 'bar',
+ );
+ ...
+
+ # Clear and set contents of list
+ print $obj->bar([ 'Spume', 'Frost' ] );
+
+ # Set values by position
+ $obj->bar(0 => 'Foozle', 1 => 'Bang!');
+
+ # Positions may be overwritten, and in any order
+ $obj->bar(2 => 'And Mash', 1 => 'Blah!');
+
+ # Retrieve value by position
+ print $obj->bar(1);
+
+ # Direct access to referenced array
+ print scalar @{ $obj->bar() };
+
+There are also calling conventions for slice and splice operations:
+
+ # Retrieve slice of values by position
+ print join(', ', $obj->bar( undef, [0, 2] ) );
+
+ # Insert an item at position in the array
+ $obj->bar([3], 'Potatoes' );
+
+ # Remove 1 item from position 3 in the array
+ $obj->bar([3, 1], undef );
+
+ # Set a new value at position 2, and return the old value
+ print $obj->bar([2, 1], 'Froth' );
+
+=cut
+
+
+use vars qw( %ArrayFragments );
+
+sub array {
+ (shift)->_build_composite( \%ArrayFragments, @_ );
+}
+
+%ArrayFragments = (
+ '' => [
+ '+init' => sub {
+ my ($method) = @_;
+ $method->{target_class} ||= $Class::MethodMaker::CONTEXT{TargetClass};
+ $method->{array_index} ||=
+ _array_index( $method->{target_class}, $name );
+ },
+ 'do' => sub {
+ my $method = pop @_;
+ my $self = shift @_;
+ my $args = \@_;
+ if ( scalar(@$args) == 0 ) {
+ if ( $method->{auto_init} and
+ ! defined $self->[$method->{array_index}] ) {
+ $self->[$method->{array_index}] = [];
+ }
+ wantarray ? @{ $self->[$method->{array_index}] } : $self->[$method->{array_index}];
+ } elsif ( scalar(@_) == 1 and ref $_[0] eq 'ARRAY' ) {
+ $self->[$method->{array_index}] = [ @{ $_[0] } ];
+ wantarray ? @{ $self->[$method->{array_index}] } : $self->[$method->{array_index}];
+ } else {
+ $self->[$method->{array_index}] ||= [];
+ Class::MakeMethods::Composite::__array_ops(
+ $self->[$method->{array_index}], @$args );
+ }
+ },
+ ],
+);
+
+########################################################################
+
+=head2 hash - Instance Ref Accessor
+
+For each method name passed, uses a closure to generate a subroutine with the following characteristics:
+
+=over 4
+
+=item *
+
+Must be called on an array-based instance.
+
+=item *
+
+Determines the array position associated with the method name, and uses that as an index into each instance to access the related value. This defaults to the next available slot in %FIELDS, but you may override this with the C<'array_index' => I<number>> method parameter, or by pre-filling the contents of %FIELDS.
+
+=item *
+
+The value for each instance will be a reference to a hash (or undef).
+
+=item *
+
+If called without any arguments, returns the contents of the hash in list context, or a hash reference in scalar context (or undef).
+
+=item *
+
+If called with one non-ref argument, uses that argument as an index to retrieve from the referenced hash, and returns that value (or undef).
+
+=item *
+
+If called with one array-ref argument, uses the contents of that array to retrieve a slice of the referenced hash.
+
+=item *
+
+If called with one hash-ref argument, sets the contents of the referenced hash to match that provided.
+
+=item *
+
+If called with a list of key-value pairs, stores the value under the given key in the referenced hash. If the instance's value was previously undefined, a new hash is autovivified. The current value under each key will be overwritten, and later arguments with the same key will override earlier ones. Returns the contents of the hash in list context, or a hash reference in scalar context.
+
+=back
+
+Sample declaration and usage:
+
+ package MyObject;
+ use Class::MakeMethods::Composite::Array (
+ hash => 'baz',
+ );
+ ...
+
+ # Set values by key
+ $obj->baz('foo' => 'Foozle', 'bar' => 'Bang!');
+
+ # Values may be overwritten, and in any order
+ $obj->baz('broccoli' => 'Blah!', 'foo' => 'Fiddle');
+
+ # Retrieve value by key
+ print $obj->baz('foo');
+
+ # Retrive slice of values by position
+ print join(', ', $obj->baz( ['foo', 'bar'] ) );
+
+ # Direct access to referenced hash
+ print keys %{ $obj->baz() };
+
+ # Reset the hash contents to empty
+ @{ $obj->baz() } = ();
+
+=cut
+
+
+use vars qw( %HashFragments );
+
+sub hash {
+ (shift)->_build_composite( \%HashFragments, @_ );
+}
+
+%HashFragments = (
+ '' => [
+ '+init' => sub {
+ my ($method) = @_;
+ $method->{hash_key} ||= $_->{name};
+ },
+ 'do' => sub {
+ my $method = pop @_;
+ my $self = shift @_;
+ my $args = \@_;
+ if ( scalar(@$args) == 0 ) {
+ if ( $method->{auto_init} and ! defined $self->[$method->{array_index}] ) {
+ $self->[$method->{array_index}] = {};
+ }
+ wantarray ? %{ $self->[$method->{array_index}] } : $self->[$method->{array_index}];
+ } elsif ( scalar(@$args) == 1 ) {
+ if ( ref($_[0]) eq 'HASH' ) {
+ %{$self->[$method->{array_index}]} = %{$_[0]};
+ } elsif ( ref($_[0]) eq 'ARRAY' ) {
+ return @{$self->[$method->{array_index}]}{ @{$_[0]} }
+ } else {
+ return $self->[$method->{array_index}]->{ $_[0] }
+ }
+ } elsif ( scalar(@$args) % 2 ) {
+ croak "Odd number of items in assigment to $method->{name}";
+ } else {
+ while ( scalar(@$args) ) {
+ my $key = shift @$args;
+ $self->[$method->{array_index}]->{ $key} = shift @$args;
+ }
+ wantarray ? %{ $self->[$method->{array_index}] } : $self->[$method->{array_index}];
+ }
+ },
+ ],
+);
+
+########################################################################
+
+=head2 object - Instance Ref Accessor
+
+For each method name passed, uses a closure to generate a subroutine with the following characteristics:
+
+=over 4
+
+=item *
+
+Must be called on an array-based instance.
+
+=item *
+
+Determines the array position associated with the method name, and uses that as an index into each instance to access the related value. This defaults to the next available slot in %FIELDS, but you may override this with the C<'array_index' => I<number>> method parameter, or by pre-filling the contents of %FIELDS.
+
+=item *
+
+The value for each instance will be a reference to an object (or undef).
+
+=item *
+
+If called without any arguments returns the current value.
+
+=item *
+
+If called with an argument, stores that as the value, and returns it,
+
+=back
+
+Sample declaration and usage:
+
+ package MyObject;
+ use Class::MakeMethods::Composite::Hash (
+ object => 'foo',
+ );
+ ...
+
+ # Store value
+ $obj->foo( Foozle->new() );
+
+ # Retrieve value
+ print $obj->foo;
+
+=cut
+
+use vars qw( %ObjectFragments );
+
+sub object {
+ (shift)->_build_composite( \%ObjectFragments, @_ );
+}
+
+%ObjectFragments = (
+ '' => [
+ '+init' => sub {
+ my ($method) = @_;
+ $method->{hash_key} ||= $_->{name};
+ },
+ 'do' => sub {
+ my $method = pop @_;
+ my $self = shift;
+ if ( scalar @_ ) {
+ my $value = shift;
+ if ( $method->{class} and ! UNIVERSAL::isa( $value, $method->{class} ) ) {
+ croak "Wrong argument type ('$value') in assigment to $method->{name}";
+ }
+ $self->[$method->{array_index}] = $value;
+ } else {
+ if ( $method->{auto_init} and ! defined $self->[$method->{array_index}] ) {
+ my $class = $method->{class}
+ or die "Can't auto_init without a class";
+ my $new_method = $method->{new_method} || 'new';
+ $self->[$method->{array_index}] = $class->$new_method();
+ }
+ $self->[$method->{array_index}];
+ }
+ },
+ ],
+);
+
+########################################################################
+
+=head1 SEE ALSO
+
+See L<Class::MakeMethods> for general information about this distribution.
+
+See L<Class::MakeMethods::Composite> for more about this family of subclasses.
+
+=cut
+
+1;
diff --git a/lib/Class/MakeMethods/Composite/Global.pm b/lib/Class/MakeMethods/Composite/Global.pm
new file mode 100644
index 0000000..cf9af0b
--- /dev/null
+++ b/lib/Class/MakeMethods/Composite/Global.pm
@@ -0,0 +1,588 @@
+=head1 NAME
+
+Class::MakeMethods::Composite::Global - Global data
+
+=head1 SYNOPSIS
+
+ package MyClass;
+ use Class::MakeMethods::Composite::Global (
+ scalar => [ 'foo' ],
+ array => [ 'my_list' ],
+ hash => [ 'my_index' ],
+ );
+ ...
+
+ MyClass->foo( 'Foozle' );
+ print MyClass->foo();
+
+ print MyClass->new(...)->foo(); # same value for any instance
+ print MySubclass->foo(); # ... and for any subclass
+
+ MyClass->my_list(0 => 'Foozle', 1 => 'Bang!');
+ print MyClass->my_list(1);
+
+ MyClass->my_index('broccoli' => 'Blah!', 'foo' => 'Fiddle');
+ print MyClass->my_index('foo');
+
+
+=head1 DESCRIPTION
+
+The Composite::Global suclass of MakeMethods provides basic accessors for shared data.
+
+=head2 Class::MakeMethods Calling Interface
+
+When you C<use> this package, the method declarations you provide
+as arguments cause subroutines to be generated and installed in
+your module.
+
+You can also omit the arguments to C<use> and instead make methods
+at runtime by passing the declarations to a subsequent call to
+C<make()>.
+
+You may include any number of declarations in each call to C<use>
+or C<make()>. If methods with the same name already exist, earlier
+calls to C<use> or C<make()> win over later ones, but within each
+call, later declarations superceed earlier ones.
+
+You can install methods in a different package by passing C<-TargetClass =E<gt> I<package>> as your first arguments to C<use> or C<make>.
+
+See L<Class::MakeMethods> for more details.
+
+=head2 Class::MakeMethods::Basic Declaration Syntax
+
+The following types of Basic declarations are supported:
+
+=over 4
+
+=item *
+
+I<generator_type> => "I<method_name>"
+
+=item *
+
+I<generator_type> => "I<name_1> I<name_2>..."
+
+=item *
+
+I<generator_type> => [ "I<name_1>", "I<name_2>", ...]
+
+=back
+
+See the "METHOD GENERATOR TYPES" section below for a list of the supported values of I<generator_type>.
+
+For each method name you provide, a subroutine of the indicated
+type will be generated and installed under that name in your module.
+
+Method names should start with a letter, followed by zero or more
+letters, numbers, or underscores.
+
+=head2 Class::MakeMethods::Composite Declaration Syntax
+
+The Composite syntax also provides several ways to optionally
+associate a hash of additional parameters with a given method
+name.
+
+=over 4
+
+=item *
+
+I<generator_type> => [ "I<name_1>" => { I<param>=>I<value>... }, ... ]
+
+A hash of parameters to use just for this method name.
+
+(Note: to prevent confusion with self-contained definition hashes,
+described below, parameter hashes following a method name must not
+contain the key 'name'.)
+
+=item *
+
+I<generator_type> => [ [ "I<name_1>", "I<name_2>", ... ] => { I<param>=>I<value>... } ]
+
+Each of these method names gets a copy of the same set of parameters.
+
+=item *
+
+I<generator_type> => [ { "name"=>"I<name_1>", I<param>=>I<value>... }, ... ]
+
+By including the reserved parameter C<name>, you create a self-contained declaration with that name and any associated hash values.
+
+=back
+
+Basic declarations, as described above, are given an empty parameter hash.
+
+=cut
+
+package Class::MakeMethods::Composite::Global;
+
+$VERSION = 1.000;
+use strict;
+use Class::MakeMethods::Composite '-isasubclass';
+
+########################################################################
+
+=head1 METHOD GENERATOR TYPES
+
+=head2 scalar - Global Accessor
+
+For each method name passed, uses a closure to generate a subroutine with the following characteristics:
+
+=over 4
+
+=item *
+
+May be called as a class method, or on any instance or subclass, and behaves identically regardless of what it was called on.
+
+=item *
+
+If called without any arguments returns the current value.
+
+=item *
+
+If called with an argument, stores that as the value, and returns it,
+
+=item *
+
+If called with multiple arguments, stores a reference to a new array with those arguments as contents, and returns that array reference.
+
+=back
+
+Sample declaration and usage:
+
+ package MyClass;
+ use Class::MakeMethods::Composite::Global (
+ scalar => 'foo',
+ );
+ ...
+
+ # Store value
+ MyClass->foo('Foozle');
+
+ # Retrieve value
+ print MyClass->foo;
+
+=cut
+
+use vars qw( %ScalarFragments );
+
+sub scalar {
+ (shift)->_build_composite( \%ScalarFragments, @_ );
+}
+
+%ScalarFragments = (
+ '' => [
+ '+init' => sub {
+ my ($method) = @_;
+ $method->{target_class} ||= $Class::MethodMaker::CONTEXT{TargetClass};
+ $method->{array_index} ||=
+ _array_index( $method->{target_class}, $name );
+ },
+ 'do' => sub {
+ my $method = pop @_;
+ my $self = shift @_;
+ if ( scalar(@_) == 0 ) {
+ $method->{global_data};
+ } elsif ( scalar(@_) == 1 ) {
+ $method->{global_data} = shift;
+ } else {
+ $method->{global_data} = [@_];
+ }
+ },
+ ],
+ 'rw' => [],
+ 'p' => [
+ '+pre' => sub {
+ my $method = pop @_;
+ unless ( UNIVERSAL::isa((caller(1))[0], $method->{target_class}) ) {
+ croak "Method $method->{name} is protected";
+ }
+ },
+ ],
+ 'pp' => [
+ '+pre' => sub {
+ my $method = pop @_;
+ unless ( (caller(1))[0] eq $method->{target_class} ) {
+ croak "Method $method->{name} is private";
+ }
+ },
+ ],
+ 'pw' => [
+ '+pre' => sub {
+ my $method = pop @_;
+ my $self = shift @_;
+ my $args = \@_;
+ unless ( @$args == 0 or UNIVERSAL::isa((caller(1))[0], $method->{target_class}) ) {
+ croak "Method $method->{name} is write-protected";
+ }
+ },
+ ],
+ 'ppw' => [
+ '+pre' => sub {
+ my $method = pop @_;
+ my $self = shift @_;
+ my $args = \@_;
+ unless ( @$args == 0 or (caller(1))[0] eq $method->{target_class} ) {
+ croak "Method $method->{name} is write-private";
+ }
+ },
+ ],
+ 'r' => [
+ '+pre' => sub {
+ my $method = pop @_;
+ my $self = shift @_;
+ @{$method->{args}} = ($self) if ( scalar @_ );
+ },
+ ],
+ 'ro' => [
+ '+pre' => sub {
+ my $method = pop @_;
+ my $self = shift @_;
+ my $args = \@_;
+ unless ( @$args == 0 ) {
+ croak("Method $method->{name} is read-only");
+ }
+ },
+ ],
+ 'wo' => [
+ '+pre' => sub {
+ my $method = pop @_;
+ my $self = shift @_;
+ my $args = \@_;
+ if ( @$args == 0 ) {
+ croak("Method $method->{name} is write-only");
+ }
+ },
+ ],
+ 'return_original' => [
+ '+pre' => sub {
+ my $method = pop @_;
+ my $self = shift @_;
+ my $args = \@_;
+ $method->{scratch}{return_original} = $method->{global_data};
+ },
+ '+post' => sub {
+ my $method = pop @_;
+ my $self = shift @_;
+ my $args = \@_;
+ $method->{result} = \{ $method->{scratch}{return_original} };
+ },
+ ],
+);
+
+########################################################################
+
+=head2 array - Global Ref Accessor
+
+For each method name passed, uses a closure to generate a subroutine with the following characteristics:
+
+=over 4
+
+=item *
+
+May be called as a class method, or on any instance or subclass, and behaves identically regardless of what it was called on.
+
+=item *
+
+The global value will be a reference to an array (or undef).
+
+=item *
+
+If called without any arguments, returns the current array-ref value (or undef).
+
+
+=item *
+
+If called with a single non-ref argument, uses that argument as an index to retrieve from the referenced array, and returns that value (or undef).
+
+=item *
+
+If called with a single array ref argument, uses that list to return a slice of the referenced array.
+
+=item *
+
+If called with a list of argument pairs, each with a non-ref index and an associated value, stores the value at the given index in the referenced array. If the global value was previously undefined, a new array is autovivified. The current value in each position will be overwritten, and later arguments with the same index will override earlier ones. Returns the current array-ref value.
+
+=item *
+
+If called with a list of argument pairs, each with the first item being a reference to an array of up to two numbers, loops over each pair and uses those numbers to splice the value array.
+
+The first controlling number is the position at which the splice will begin. Zero will start before the first item in the list. Negative numbers count backwards from the end of the array.
+
+The second number is the number of items to be removed from the list. If it is omitted, or undefined, or zero, no items are removed. If it is a positive integer, that many items will be returned.
+
+If both numbers are omitted, or are both undefined, they default to containing the entire value array.
+
+If the second argument is undef, no values will be inserted; if it is a non-reference value, that one value will be inserted; if it is an array-ref, its values will be copied.
+
+The method returns the items that removed from the array, if any.
+
+=back
+
+Sample declaration and usage:
+
+ package MyClass;
+ use Class::MakeMethods::Composite::Global (
+ array => 'bar',
+ );
+ ...
+
+ # Clear and set contents of list
+ print MyClass->bar([ 'Spume', 'Frost' ] );
+
+ # Set values by position
+ MyClass->bar(0 => 'Foozle', 1 => 'Bang!');
+
+ # Positions may be overwritten, and in any order
+ MyClass->bar(2 => 'And Mash', 1 => 'Blah!');
+
+ # Retrieve value by position
+ print MyClass->bar(1);
+
+ # Direct access to referenced array
+ print scalar @{ MyClass->bar() };
+
+There are also calling conventions for slice and splice operations:
+
+ # Retrieve slice of values by position
+ print join(', ', MyClass->bar( undef, [0, 2] ) );
+
+ # Insert an item at position in the array
+ MyClass->bar([3], 'Potatoes' );
+
+ # Remove 1 item from position 3 in the array
+ MyClass->bar([3, 1], undef );
+
+ # Set a new value at position 2, and return the old value
+ print MyClass->bar([2, 1], 'Froth' );
+
+=cut
+
+
+use vars qw( %ArrayFragments );
+
+sub array {
+ (shift)->_build_composite( \%ArrayFragments, @_ );
+}
+
+%ArrayFragments = (
+ '' => [
+ '+init' => sub {
+ my ($method) = @_;
+ $method->{hash_key} ||= $_->{name};
+ },
+ 'do' => sub {
+ my $method = pop @_;
+ my $self = shift @_;
+ my $args = \@_;
+ if ( scalar(@$args) == 0 ) {
+ if ( $method->{auto_init} and
+ ! defined $method->{global_data} ) {
+ $method->{global_data} = [];
+ }
+ wantarray ? @{ $method->{global_data} } : $method->{global_data}
+ } elsif ( scalar(@_) == 1 and ref $_[0] eq 'ARRAY' ) {
+ $method->{global_data} = [ @{ $_[0] } ];
+ wantarray ? @{ $method->{global_data} } : $method->{global_data}
+ } else {
+ $method->{global_data} ||= [];
+ Class::MakeMethods::Composite::__array_ops(
+ $method->{global_data}, @$args );
+ }
+ },
+ ],
+);
+
+########################################################################
+
+=head2 hash - Global Ref Accessor
+
+For each method name passed, uses a closure to generate a subroutine with the following characteristics:
+
+=over 4
+
+=item *
+
+May be called as a class method, or on any instance or subclass, and behaves identically regardless of what it was called on.
+
+=item *
+
+The global value will be a reference to a hash (or undef).
+
+=item *
+
+If called without any arguments, returns the contents of the hash in list context, or a hash reference in scalar context (or undef).
+
+=item *
+
+If called with one non-ref argument, uses that argument as an index to retrieve from the referenced hash, and returns that value (or undef).
+
+=item *
+
+If called with one array-ref argument, uses the contents of that array to retrieve a slice of the referenced hash.
+
+=item *
+
+If called with one hash-ref argument, sets the contents of the referenced hash to match that provided.
+
+=item *
+
+If called with a list of key-value pairs, stores the value under the given key in the referenced hash. If the global value was previously undefined, a new hash is autovivified. The current value under each key will be overwritten, and later arguments with the same key will override earlier ones. Returns the contents of the hash in list context, or a hash reference in scalar context.
+
+=back
+
+Sample declaration and usage:
+
+ package MyClass;
+ use Class::MakeMethods::Composite::Global (
+ hash => 'baz',
+ );
+ ...
+
+ # Set values by key
+ MyClass->baz('foo' => 'Foozle', 'bar' => 'Bang!');
+
+ # Values may be overwritten, and in any order
+ MyClass->baz('broccoli' => 'Blah!', 'foo' => 'Fiddle');
+
+ # Retrieve value by key
+ print MyClass->baz('foo');
+
+ # Retrive slice of values by position
+ print join(', ', MyClass->baz( ['foo', 'bar'] ) );
+
+ # Direct access to referenced hash
+ print keys %{ MyClass->baz() };
+
+ # Reset the hash contents to empty
+ @{ MyClass->baz() } = ();
+
+=cut
+
+use vars qw( %HashFragments );
+
+sub hash {
+ (shift)->_build_composite( \%HashFragments, @_ );
+}
+
+%HashFragments = (
+ '' => [
+ '+init' => sub {
+ my ($method) = @_;
+ $method->{hash_key} ||= $_->{name};
+ },
+ 'do' => sub {
+ my $method = pop @_;
+ my $self = shift @_;
+ my $args = \@_;
+ if ( scalar(@$args) == 0 ) {
+ if ( $method->{auto_init} and ! defined $method->{global_data} ) {
+ $method->{global_data} = {};
+ }
+ wantarray ? %{ $method->{global_data} } : $method->{global_data};
+ } elsif ( scalar(@$args) == 1 ) {
+ if ( ref($_[0]) eq 'HASH' ) {
+ %{$method->{global_data}} = %{$_[0]};
+ } elsif ( ref($_[0]) eq 'ARRAY' ) {
+ return @{$method->{global_data}}{ @{$_[0]} }
+ } else {
+ return $method->{global_data}->{ $_[0] }
+ }
+ } elsif ( scalar(@$args) % 2 ) {
+ croak "Odd number of items in assigment to $method->{name}";
+ } else {
+ while ( scalar(@$args) ) {
+ my $key = shift @$args;
+ $method->{global_data}->{ $key} = shift @$args;
+ }
+ wantarray ? %{ $method->{global_data} } : $method->{global_data};
+ }
+ },
+ ],
+);
+
+########################################################################
+
+=head2 object - Global Ref Accessor
+
+For each method name passed, uses a closure to generate a subroutine with the following characteristics:
+
+=over 4
+
+=item *
+
+May be called as a class method, or on any instance or subclass, and behaves identically regardless of what it was called on.
+
+=item *
+
+The global value will be a reference to an object (or undef).
+
+=item *
+
+If called without any arguments returns the current value.
+
+=item *
+
+If called with an argument, stores that as the value, and returns it,
+
+=back
+
+Sample declaration and usage:
+
+ package MyClass;
+ use Class::MakeMethods::Composite::Global (
+ object => 'foo',
+ );
+ ...
+
+ # Store value
+ MyClass->foo( Foozle->new() );
+
+ # Retrieve value
+ print MyClass->foo;
+
+=cut
+
+use vars qw( %ObjectFragments );
+
+sub object {
+ (shift)->_build_composite( \%ObjectFragments, @_ );
+}
+
+%ObjectFragments = (
+ '' => [
+ '+init' => sub {
+ my ($method) = @_;
+ $method->{hash_key} ||= $_->{name};
+ },
+ 'do' => sub {
+ my $method = pop @_;
+ my $self = shift;
+ if ( scalar @_ ) {
+ my $value = shift;
+ if ( $method->{class} and ! UNIVERSAL::isa( $value, $method->{class} ) ) {
+ croak "Wrong argument type ('$value') in assigment to $method->{name}";
+ }
+ $method->{global_data} = $value;
+ } else {
+ if ( $method->{auto_init} and ! defined $method->{global_data} ) {
+ my $class = $method->{class}
+ or die "Can't auto_init without a class";
+ my $new_method = $method->{new_method} || 'new';
+ $method->{global_data} = $class->$new_method();
+ }
+ $method->{global_data};
+ }
+ },
+ ],
+);
+
+########################################################################
+
+=head1 SEE ALSO
+
+See L<Class::MakeMethods> for general information about this distribution.
+
+See L<Class::MakeMethods::Composite> for more about this family of subclasses.
+
+=cut
+
+1;
diff --git a/lib/Class/MakeMethods/Composite/Hash.pm b/lib/Class/MakeMethods/Composite/Hash.pm
new file mode 100644
index 0000000..969bdd0
--- /dev/null
+++ b/lib/Class/MakeMethods/Composite/Hash.pm
@@ -0,0 +1,719 @@
+=head1 NAME
+
+Class::MakeMethods::Composite::Hash - Composite hash methods
+
+=head1 SYNOPSIS
+
+ package MyObject;
+ use Class::MakeMethods::Composite::Hash (
+ new => 'new',
+ scalar => [ 'foo', 'bar' ],
+ array => 'my_list',
+ hash => 'my_index',
+ );
+ ...
+
+ my $obj = MyObject->new( foo => 'Foozle' );
+ print $obj->foo();
+
+ $obj->bar('Barbados');
+ print $obj->bar();
+
+ $obj->my_list(0 => 'Foozle', 1 => 'Bang!');
+ print $obj->my_list(1);
+
+ $obj->my_index('broccoli' => 'Blah!', 'foo' => 'Fiddle');
+ print $obj->my_index('foo');
+
+=head1 DESCRIPTION
+
+The Composite::Hash suclass of MakeMethods provides a basic constructor and accessors for blessed-hash object instances.
+
+=head2 Class::MakeMethods Calling Interface
+
+When you C<use> this package, the method declarations you provide
+as arguments cause subroutines to be generated and installed in
+your module.
+
+You can also omit the arguments to C<use> and instead make methods
+at runtime by passing the declarations to a subsequent call to
+C<make()>.
+
+You may include any number of declarations in each call to C<use>
+or C<make()>. If methods with the same name already exist, earlier
+calls to C<use> or C<make()> win over later ones, but within each
+call, later declarations superceed earlier ones.
+
+You can install methods in a different package by passing C<-TargetClass =E<gt> I<package>> as your first arguments to C<use> or C<make>.
+
+See L<Class::MakeMethods> for more details.
+
+=head2 Class::MakeMethods::Basic Declaration Syntax
+
+The following types of Basic declarations are supported:
+
+=over 4
+
+=item *
+
+I<generator_type> => "I<method_name>"
+
+=item *
+
+I<generator_type> => "I<name_1> I<name_2>..."
+
+=item *
+
+I<generator_type> => [ "I<name_1>", "I<name_2>", ...]
+
+=back
+
+See the "METHOD GENERATOR TYPES" section below for a list of the supported values of I<generator_type>.
+
+For each method name you provide, a subroutine of the indicated
+type will be generated and installed under that name in your module.
+
+Method names should start with a letter, followed by zero or more
+letters, numbers, or underscores.
+
+=head2 Class::MakeMethods::Composite Declaration Syntax
+
+The Composite syntax also provides several ways to optionally
+associate a hash of additional parameters with a given method
+name.
+
+=over 4
+
+=item *
+
+I<generator_type> => [ "I<name_1>" => { I<param>=>I<value>... }, ... ]
+
+A hash of parameters to use just for this method name.
+
+(Note: to prevent confusion with self-contained definition hashes,
+described below, parameter hashes following a method name must not
+contain the key 'name'.)
+
+=item *
+
+I<generator_type> => [ [ "I<name_1>", "I<name_2>", ... ] => { I<param>=>I<value>... } ]
+
+Each of these method names gets a copy of the same set of parameters.
+
+=item *
+
+I<generator_type> => [ { "name"=>"I<name_1>", I<param>=>I<value>... }, ... ]
+
+By including the reserved parameter C<name>, you create a self-contained declaration with that name and any associated hash values.
+
+=back
+
+Basic declarations, as described above, are given an empty parameter hash.
+
+=cut
+
+package Class::MakeMethods::Composite::Hash;
+
+$VERSION = 1.000;
+use strict;
+use Class::MakeMethods::Composite '-isasubclass';
+use Carp;
+
+########################################################################
+
+=head1 METHOD GENERATOR TYPES
+
+=head2 new - Constructor
+
+For each method name passed, returns a subroutine with the following characteristics:
+
+=over 4
+
+=item *
+
+Has a reference to a sample item to copy. This defaults to a reference to an empty hash, but you may override this with the C<'defaults' =E<gt> I<hash_ref>> method parameter.
+
+=item *
+
+If called as a class method, makes a new hash and blesses it into that class.
+
+=item *
+
+If called on a hash-based instance, makes a copy of it and blesses the copy into the same class as the original instance.
+
+=item *
+
+If passed a list of key-value pairs, appends them to the new hash. These arguments override any copied values, and later arguments with the same name will override earlier ones.
+
+=item *
+
+Returns the new instance.
+
+=back
+
+Sample declaration and usage:
+
+ package MyObject;
+ use Class::MakeMethods::Composite::Hash (
+ new => 'new',
+ );
+ ...
+
+ # Bare constructor
+ my $empty = MyObject->new();
+
+ # Constructor with initial values
+ my $obj = MyObject->new( foo => 'Foozle', bar => 'Barbados' );
+
+ # Copy with overriding value
+ my $copy = $obj->new( bar => 'Bob' );
+
+=cut
+
+=head2 new --with_values - Constructor
+
+For each method name passed, returns a subroutine with the following characteristics:
+
+=over 4
+
+=item *
+
+May be called as a class method, or (equivalently) on any existing object of that class.
+
+=item *
+
+Creates a hash, blesses it into the class, and returns the new instance.
+
+=item *
+
+If no arguments are provided, the returned hash will be empty. If passed a single hash-ref argument, copies its contents into the new hash. If called with multiple arguments, treats them as key-value pairs, and copies them into the new hash. (Note that this is a "shallow" copy, not a "deep" clone.)
+
+=back
+
+=cut
+
+use vars qw( %ConstructorFragments );
+
+sub new {
+ (shift)->_build_composite( \%ConstructorFragments, @_ );
+}
+
+%ConstructorFragments = (
+ '' => [
+ '+init' => sub {
+ my $method = pop @_;
+ $method->{target_class} ||= $Class::MethodMaker::CONTEXT{TargetClass};
+ $method->{defaults} ||= {};
+ },
+ 'do' => sub {
+ my $method = pop @_;
+ my $self = shift @_;
+ my $obj = ref($self) ? bless( { %$self }, ref $self )
+ : bless( { %{$method->{defaults}} }, $self );
+ @_ = %{$_[0]}
+ if ( scalar @_ == 1 and ref $_[0] eq 'HASH' );
+ while ( scalar @_ ) {
+ my $method = shift @_;
+ my $value = shift @_;
+ $obj->$method( $value );
+ }
+ $obj;
+ },
+ ],
+ 'with_values' => [
+ 'do' => sub {
+ my $method = pop @_;
+ my $self = shift @_;
+ @_ = %{$_[0]}
+ if ( scalar @_ == 1 and ref $_[0] eq 'HASH' );
+ bless( { @_ }, ref($self) || $self );
+ }
+ ],
+);
+
+########################################################################
+
+=head2 scalar - Instance Accessor
+
+For each method name passed, uses a closure to generate a subroutine with the following characteristics:
+
+=over 4
+
+=item *
+
+Must be called on a hash-based instance.
+
+=item *
+
+Has a specific hash key to use to access the related value for each instance.
+This defaults to the method name, but you may override this with the C<'hash_key' => I<string>> method parameter.
+
+=item *
+
+If called without any arguments returns the current value.
+
+=item *
+
+If called with an argument, stores that as the value, and returns it.
+
+=item *
+
+If called with multiple arguments, stores a reference to a new array with those arguments as contents, and returns that array reference.
+
+=back
+
+Sample declaration and usage:
+
+ package MyObject;
+ use Class::MakeMethods::Composite::Hash (
+ scalar => 'foo',
+ );
+ ...
+
+ # Store value
+ $obj->foo('Foozle');
+
+ # Retrieve value
+ print $obj->foo;
+
+=cut
+
+use vars qw( %ScalarFragments );
+
+sub scalar {
+ (shift)->_build_composite( \%ScalarFragments, @_ );
+}
+
+%ScalarFragments = (
+ '' => [
+ '+init' => sub {
+ my ($method) = @_;
+ $method->{hash_key} ||= $method->{name};
+ $method->{target_class} ||= $Class::MethodMaker::CONTEXT{TargetClass};
+ },
+ 'do' => sub {
+ my $method = pop @_;
+ my $self = shift @_;
+ if ( scalar(@_) == 0 ) {
+ $self->{$method->{hash_key}};
+ } elsif ( scalar(@_) == 1 ) {
+ $self->{$method->{hash_key}} = shift;
+ } else {
+ $self->{$method->{hash_key}} = [@_];
+ }
+ },
+ ],
+ 'rw' => [],
+ 'p' => [
+ '+pre' => sub {
+ my $method = pop @_;
+ my $self = shift @_;
+ unless ( UNIVERSAL::isa((caller(1))[0], $method->{target_class}) ) {
+ croak "Method $method->{name} is protected";
+ }
+ },
+ ],
+ 'pp' => [
+ '+pre' => sub {
+ my $method = pop @_;
+ my $self = shift @_;
+ unless ( (caller(1))[0] eq $method->{target_class} ) {
+ croak "Method $method->{name} is private";
+ }
+ },
+ ],
+ 'pw' => [
+ '+pre' => sub {
+ my $method = pop @_;
+ my $self = shift @_;
+ my $args = \@_;
+ unless ( @$args == 0 or UNIVERSAL::isa((caller(1))[0], $method->{target_class}) ) {
+ croak "Method $method->{name} is write-protected";
+ }
+ },
+ ],
+ 'ppw' => [
+ '+pre' => sub {
+ my $method = pop @_;
+ my $self = shift @_;
+ my $args = \@_;
+ unless ( @$args == 0 or (caller(1))[0] eq $method->{target_class} ) {
+ croak "Method $method->{name} is write-private";
+ }
+ },
+ ],
+ 'r' => [
+ '+pre' => sub {
+ my $method = pop @_;
+ my $self = shift @_;
+ my $args = \@_;
+ @$args = ();
+ },
+ ],
+ 'ro' => [
+ '+pre' => sub {
+ my $method = pop @_;
+ my $self = shift @_;
+ my $args = \@_;
+ unless ( @$args == 0 ) {
+ croak("Method $method->{name} is read-only");
+ }
+ },
+ ],
+ 'wo' => [
+ '+pre' => sub {
+ my $method = pop @_;
+ my $self = shift @_;
+ my $args = \@_;
+ if ( @$args == 0 ) {
+ croak("Method $method->{name} is write-only");
+ }
+ },
+ ],
+ 'return_original' => [
+ '+pre' => sub {
+ my $method = pop @_;
+ my $self = shift @_;
+ my $args = \@_;
+ $method->{scratch}{return_original} = $self->{$method->{hash_key}};
+ },
+ '+post' => sub {
+ my $method = pop @_;
+ my $self = shift @_;
+ my $args = \@_;
+ ${ $method->{result} } = $method->{scratch}{return_original};
+ },
+ ],
+);
+
+########################################################################
+
+=head2 array - Instance Ref Accessor
+
+For each method name passed, uses a closure to generate a subroutine with the following characteristics:
+
+=over 4
+
+=item *
+
+Must be called on a hash-based instance.
+
+=item *
+
+Has a specific hash key to use to access the related value for each instance.
+This defaults to the method name, but you may override this with the C<'hash_key' => I<string>> method parameter.
+
+=item *
+
+The value for each instance will be a reference to an array (or undef).
+
+=item *
+
+If called without any arguments, returns the current array-ref value (or undef).
+
+
+=item *
+
+If called with a single non-ref argument, uses that argument as an index to retrieve from the referenced array, and returns that value (or undef).
+
+=item *
+
+If called with a single array ref argument, uses that list to return a slice of the referenced array.
+
+=item *
+
+If called with a list of argument pairs, each with a non-ref index and an associated value, stores the value at the given index in the referenced array. If the instance's value was previously undefined, a new array is autovivified. The current value in each position will be overwritten, and later arguments with the same index will override earlier ones. Returns the current array-ref value.
+
+=item *
+
+If called with a list of argument pairs, each with the first item being a reference to an array of up to two numbers, loops over each pair and uses those numbers to splice the value array.
+
+The first controlling number is the position at which the splice will begin. Zero will start before the first item in the list. Negative numbers count backwards from the end of the array.
+
+The second number is the number of items to be removed from the list. If it is omitted, or undefined, or zero, no items are removed. If it is a positive integer, that many items will be returned.
+
+If both numbers are omitted, or are both undefined, they default to containing the entire value array.
+
+If the second argument is undef, no values will be inserted; if it is a non-reference value, that one value will be inserted; if it is an array-ref, its values will be copied.
+
+The method returns the items that removed from the array, if any.
+
+=back
+
+Sample declaration and usage:
+
+ package MyObject;
+ use Class::MakeMethods::Composite::Hash (
+ array => 'bar',
+ );
+ ...
+
+ # Clear and set contents of list
+ print $obj->bar([ 'Spume', 'Frost' ] );
+
+ # Set values by position
+ $obj->bar(0 => 'Foozle', 1 => 'Bang!');
+
+ # Positions may be overwritten, and in any order
+ $obj->bar(2 => 'And Mash', 1 => 'Blah!');
+
+ # Retrieve value by position
+ print $obj->bar(1);
+
+ # Direct access to referenced array
+ print scalar @{ $obj->bar() };
+
+There are also calling conventions for slice and splice operations:
+
+ # Retrieve slice of values by position
+ print join(', ', $obj->bar( undef, [0, 2] ) );
+
+ # Insert an item at position in the array
+ $obj->bar([3], 'Potatoes' );
+
+ # Remove 1 item from position 3 in the array
+ $obj->bar([3, 1], undef );
+
+ # Set a new value at position 2, and return the old value
+ print $obj->bar([2, 1], 'Froth' );
+
+=cut
+
+use vars qw( %ArrayFragments );
+
+sub array {
+ (shift)->_build_composite( \%ArrayFragments, @_ );
+}
+
+%ArrayFragments = (
+ '' => [
+ '+init' => sub {
+ my ($method) = @_;
+ $method->{hash_key} ||= $_->{name};
+ },
+ 'do' => sub {
+ my $method = pop @_;
+ my $self = shift @_;
+ my $args = \@_;
+ if ( scalar(@$args) == 0 ) {
+ if ( $method->{auto_init} and
+ ! defined $self->{$method->{hash_key}} ) {
+ $self->{$method->{hash_key}} = [];
+ }
+ wantarray ? @{ $self->{$method->{hash_key}} } : $self->{$method->{hash_key}};
+ } elsif ( scalar(@_) == 1 and ref $_[0] eq 'ARRAY' ) {
+ $self->{$method->{hash_key}} = [ @{ $_[0] } ];
+ wantarray ? @{ $self->{$method->{hash_key}} } : $self->{$method->{hash_key}};
+ } else {
+ $self->{$method->{hash_key}} ||= [];
+ array_splicer( $self->{$method->{hash_key}}, @$args );
+ }
+ },
+ ],
+);
+
+########################################################################
+
+=head2 hash - Instance Ref Accessor
+
+For each method name passed, uses a closure to generate a subroutine with the following characteristics:
+
+=over 4
+
+=item *
+
+Must be called on a hash-based instance.
+
+=item *
+
+Has a specific hash key to use to access the related value for each instance.
+This defaults to the method name, but you may override this with the C<'hash_key' => I<string>> method parameter.
+
+=item *
+
+The value for each instance will be a reference to a hash (or undef).
+
+=item *
+
+If called without any arguments, returns the contents of the hash in list context, or a hash reference in scalar context (or undef).
+
+=item *
+
+If called with one non-ref argument, uses that argument as an index to retrieve from the referenced hash, and returns that value (or undef).
+
+=item *
+
+If called with one array-ref argument, uses the contents of that array to retrieve a slice of the referenced hash.
+
+=item *
+
+If called with one hash-ref argument, sets the contents of the referenced hash to match that provided.
+
+=item *
+
+If called with a list of key-value pairs, stores the value under the given key in the referenced hash. If the instance's value was previously undefined, a new hash is autovivified. The current value under each key will be overwritten, and later arguments with the same key will override earlier ones. Returns the contents of the hash in list context, or a hash reference in scalar context.
+
+=back
+
+Sample declaration and usage:
+
+ package MyObject;
+ use Class::MakeMethods::Composite::Hash (
+ hash => 'baz',
+ );
+ ...
+
+ # Set values by key
+ $obj->baz('foo' => 'Foozle', 'bar' => 'Bang!');
+
+ # Values may be overwritten, and in any order
+ $obj->baz('broccoli' => 'Blah!', 'foo' => 'Fiddle');
+
+ # Retrieve value by key
+ print $obj->baz('foo');
+
+ # Retrive slice of values by position
+ print join(', ', $obj->baz( ['foo', 'bar'] ) );
+
+ # Direct access to referenced hash
+ print keys %{ $obj->baz() };
+
+ # Reset the hash contents to empty
+ @{ $obj->baz() } = ();
+
+=cut
+
+use vars qw( %HashFragments );
+
+sub hash {
+ (shift)->_build_composite( \%HashFragments, @_ );
+}
+
+%HashFragments = (
+ '' => [
+ '+init' => sub {
+ my ($method) = @_;
+ $method->{hash_key} ||= $_->{name};
+ },
+ 'do' => sub {
+ my $method = pop @_;
+ my $self = shift @_;
+ my $args = \@_;
+ if ( scalar(@$args) == 0 ) {
+ if ( $method->{auto_init} and ! defined $self->{$method->{hash_key}} ) {
+ $self->{$method->{hash_key}} = {};
+ }
+ wantarray ? %{ $self->{$method->{hash_key}} } : $self->{$method->{hash_key}};
+ } elsif ( scalar(@$args) == 1 ) {
+ if ( ref($_[0]) eq 'HASH' ) {
+ %{$self->{$method->{hash_key}}} = %{$_[0]};
+ } elsif ( ref($_[0]) eq 'ARRAY' ) {
+ return @{$self->{$method->{hash_key}}}{ @{$_[0]} }
+ } else {
+ return $self->{$method->{hash_key}}->{ $_[0] }
+ }
+ } elsif ( scalar(@$args) % 2 ) {
+ croak "Odd number of items in assigment to $method->{name}";
+ } else {
+ while ( scalar(@$args) ) {
+ my $key = shift @$args;
+ $self->{$method->{hash_key}}->{ $key} = shift @$args;
+ }
+ wantarray ? %{ $self->{$method->{hash_key}} } : $self->{$method->{hash_key}};
+ }
+ },
+ ],
+);
+
+########################################################################
+
+=head2 object - Instance Ref Accessor
+
+For each method name passed, uses a closure to generate a subroutine with the following characteristics:
+
+=over 4
+
+=item *
+
+Must be called on a hash-based instance.
+
+=item *
+
+Has a specific hash key to use to access the related value for each instance.
+This defaults to the method name, but you may override this with the C<'hash_key' => I<string>> method parameter.
+
+=item *
+
+The value for each instance will be a reference to an object (or undef).
+
+=item *
+
+If called without any arguments returns the current value.
+
+=item *
+
+If called with an argument, stores that as the value, and returns it,
+
+=back
+
+Sample declaration and usage:
+
+ package MyObject;
+ use Class::MakeMethods::Composite::Hash (
+ object => 'foo',
+ );
+ ...
+
+ # Store value
+ $obj->foo( Foozle->new() );
+
+ # Retrieve value
+ print $obj->foo;
+
+=cut
+
+use vars qw( %ObjectFragments );
+
+sub object {
+ (shift)->_build_composite( \%ObjectFragments, @_ );
+}
+
+%ObjectFragments = (
+ '' => [
+ '+init' => sub {
+ my ($method) = @_;
+ $method->{hash_key} ||= $_->{name};
+ },
+ 'do' => sub {
+ my $method = pop @_;
+ my $self = shift;
+ if ( scalar @_ ) {
+ my $value = shift;
+ if ( $method->{class} and ! UNIVERSAL::isa( $value, $method->{class} ) ) {
+ croak "Wrong argument type ('$value') in assigment to $method->{name}";
+ }
+ $self->{$method->{hash_key}} = $value;
+ } else {
+ if ( $method->{auto_init} and ! defined $self->{$method->{hash_key}} ) {
+ my $class = $method->{class}
+ or die "Can't auto_init without a class";
+ my $new_method = $method->{new_method} || 'new';
+ $self->{$method->{hash_key}} = $class->$new_method();
+ }
+ $self->{$method->{hash_key}};
+ }
+ },
+ ],
+);
+
+########################################################################
+
+=head1 SEE ALSO
+
+See L<Class::MakeMethods> for general information about this distribution.
+
+See L<Class::MakeMethods::Composite> for more about this family of subclasses.
+
+=cut
+
+1;
diff --git a/lib/Class/MakeMethods/Composite/Inheritable.pm b/lib/Class/MakeMethods/Composite/Inheritable.pm
new file mode 100644
index 0000000..ca4be3e
--- /dev/null
+++ b/lib/Class/MakeMethods/Composite/Inheritable.pm
@@ -0,0 +1,613 @@
+=head1 NAME
+
+Class::MakeMethods::Composite::Inheritable - Overridable data
+
+=head1 SYNOPSIS
+
+ package MyClass;
+
+ use Class::MakeMethods( 'Composite::Inheritable:scalar' => 'foo' );
+ # We now have an accessor method for an "inheritable" scalar value
+
+ MyClass->foo( 'Foozle' ); # Set a class-wide value
+ print MyClass->foo(); # Retrieve class-wide value
+
+ my $obj = MyClass->new(...);
+ print $obj->foo(); # All instances "inherit" that value...
+
+ $obj->foo( 'Foible' ); # until you set a value for an instance.
+ print $obj->foo(); # This now finds object-specific value.
+ ...
+
+ package MySubClass;
+ @ISA = 'MyClass';
+
+ print MySubClass->foo(); # Intially same as superclass,
+ MySubClass->foo('Foobar'); # but overridable per subclass,
+ print $subclass_obj->foo(); # and shared by its instances
+ $subclass_obj->foo('Fosil');# until you override them...
+ ...
+
+ # Similar behaviour for hashes and arrays is currently incomplete
+ package MyClass;
+ use Class::MakeMethods::Composite::Inheritable (
+ array => 'my_list',
+ hash => 'my_index',
+ );
+
+ MyClass->my_list(0 => 'Foozle', 1 => 'Bang!');
+ print MyClass->my_list(1);
+
+ MyClass->my_index('broccoli' => 'Blah!', 'foo' => 'Fiddle');
+ print MyClass->my_index('foo');
+
+
+=head1 DESCRIPTION
+
+The MakeMethods subclass provides accessor methods that search an inheritance tree to find a value. This allows you to set a shared or default value for a given class, optionally override it in a subclass, and then optionally override it on a per-instance basis.
+
+Note that all MakeMethods methods are inheritable, in the sense that they work as expected for subclasses. These methods are different in that the I<data> accessed by each method can be inherited or overridden in each subclass or instance. See L< Class::MakeMethods::Utility::Inheritable> for more about this type of "inheritable" or overridable" data.
+
+
+=head2 Class::MakeMethods Calling Interface
+
+When you C<use> this package, the method declarations you provide
+as arguments cause subroutines to be generated and installed in
+your module.
+
+See L<Class::MakeMethods::Standard/"Calling Conventions"> for more information.
+
+=head2 Class::MakeMethods::Standard Declaration Syntax
+
+To declare methods, pass in pairs of a method-type name followed
+by one or more method names.
+
+See the "METHOD GENERATOR TYPES" section below for a list of the supported values of I<generator_type>.
+
+See L<Class::MakeMethods::Standard/"Declaration Syntax"> and L<Class::MakeMethods::Standard/"Parameter Syntax"> for more information.
+
+=cut
+
+package Class::MakeMethods::Composite::Inheritable;
+
+$VERSION = 1.000;
+use strict;
+use Carp;
+
+use Class::MakeMethods::Composite '-isasubclass';
+use Class::MakeMethods::Utility::Inheritable qw(get_vvalue set_vvalue find_vself );
+
+########################################################################
+
+=head1 METHOD GENERATOR TYPES
+
+=head2 scalar - Overrideable Accessor
+
+For each method name passed, uses a closure to generate a subroutine with the following characteristics:
+
+=over 4
+
+=item *
+
+May be called as a class or instance method, on the declaring class or any subclass.
+
+=item *
+
+If called without any arguments returns the current value for the callee. If the callee has not had a value defined for this method, searches up from instance to class, and from class to superclass, until a callee with a value is located.
+
+=item *
+
+If called with an argument, stores that as the value associated with the callee, whether instance or class, and returns it,
+
+=item *
+
+If called with multiple arguments, stores a reference to a new array with those arguments as contents, and returns that array reference.
+
+=back
+
+Sample declaration and usage:
+
+ package MyClass;
+ use Class::MakeMethods::Composite::Inheritable (
+ scalar => 'foo',
+ );
+ ...
+
+ # Store value
+ MyClass->foo('Foozle');
+
+ # Retrieve value
+ print MyClass->foo;
+
+=cut
+
+use vars qw( %ScalarFragments );
+
+sub scalar {
+ (shift)->_build_composite( \%ScalarFragments, @_ );
+}
+
+%ScalarFragments = (
+ '' => [
+ '+init' => sub {
+ my ($method) = @_;
+ $method->{target_class} ||= $Class::MethodMaker::CONTEXT{TargetClass};
+ $method->{data} ||= {};
+ },
+ 'do' => sub {
+ my $method = pop @_;
+ my $self = shift @_;
+ if ( scalar(@_) == 0 ) {
+ return get_vvalue($method->{data}, $self);
+ } else {
+ my $value = (@_ == 1 ? $_[0] : [@_]);
+ set_vvalue($method->{data}, $self, $value);
+ }
+ },
+ ],
+ 'rw' => [],
+ 'p' => [
+ '+pre' => sub {
+ my $method = pop @_;
+ my $self = shift @_;
+ unless ( UNIVERSAL::isa((caller(1))[0], $method->{target_class}) ) {
+ croak "Method $method->{name} is protected";
+ }
+ },
+ ],
+ 'pp' => [
+ '+pre' => sub {
+ my $method = pop @_;
+ my $self = shift @_;
+ unless ( (caller(1))[0] eq $method->{target_class} ) {
+ croak "Method $method->{name} is private";
+ }
+ },
+ ],
+ 'pw' => [
+ '+pre' => sub {
+ my $method = pop @_;
+ my $self = shift @_;
+ unless ( @_ == 0 or UNIVERSAL::isa((caller(1))[0], $method->{target_class}) ) {
+ croak "Method $method->{name} is write-protected";
+ }
+ },
+ ],
+ 'ppw' => [
+ '+pre' => sub {
+ my $method = pop @_;
+ my $self = shift @_;
+ unless ( @_ == 0 or (caller(1))[0] eq $method->{target_class} ) {
+ croak "Method $method->{name} is write-private";
+ }
+ },
+ ],
+ 'r' => [
+ '+pre' => sub {
+ my $method = pop @_;
+ my $self = shift @_;
+ @{ $method->{args} } = ();
+ },
+ ],
+ 'ro' => [
+ '+pre' => sub {
+ my $method = pop @_;
+ my $self = shift @_;
+ unless ( @_ == 0 ) {
+ croak("Method $method->{name} is read-only");
+ }
+ },
+ ],
+ 'wo' => [
+ '+pre' => sub {
+ my $method = pop @_;
+ my $self = shift @_;
+ if ( @_ == 0 ) {
+ croak("Method $method->{name} is write-only");
+ }
+ },
+ ],
+ 'return_original' => [
+ '+pre' => sub {
+ my $method = pop @_;
+ my $self = shift @_;
+ my $v_self = find_vself($method->{data}, $self);
+ $method->{scratch}{return_original} =
+ $v_self ? $method->{data}{$v_self} : ();
+ },
+ '+post' => sub {
+ my $method = pop @_;
+ $method->{result} = \{ $method->{scratch}{return_original} };
+ },
+ ],
+);
+
+########################################################################
+
+=head2 array - Overrideable Ref Accessor
+
+For each method name passed, uses a closure to generate a subroutine with the following characteristics:
+
+=over 4
+
+=item *
+
+May be called as a class method, or on any instance or subclass, Must be called on a hash-based instance.
+
+=item *
+
+The class value will be a reference to an array (or undef).
+
+=item *
+
+If called without any arguments, returns the current array-ref value (or undef).
+
+
+=item *
+
+If called with a single non-ref argument, uses that argument as an index to retrieve from the referenced array, and returns that value (or undef).
+
+=item *
+
+If called with a single array ref argument, uses that list to return a slice of the referenced array.
+
+=item *
+
+If called with a list of argument pairs, each with a non-ref index and an associated value, stores the value at the given index in the referenced array. If the class value was previously undefined, a new array is autovivified. The current value in each position will be overwritten, and later arguments with the same index will override earlier ones. Returns the current array-ref value.
+
+=item *
+
+If called with a list of argument pairs, each with the first item being a reference to an array of up to two numbers, loops over each pair and uses those numbers to splice the value array.
+
+The first controlling number is the position at which the splice will begin. Zero will start before the first item in the list. Negative numbers count backwards from the end of the array.
+
+The second number is the number of items to be removed from the list. If it is omitted, or undefined, or zero, no items are removed. If it is a positive integer, that many items will be returned.
+
+If both numbers are omitted, or are both undefined, they default to containing the entire value array.
+
+If the second argument is undef, no values will be inserted; if it is a non-reference value, that one value will be inserted; if it is an array-ref, its values will be copied.
+
+The method returns the items that removed from the array, if any.
+
+=back
+
+Sample declaration and usage:
+
+ package MyClass;
+ use Class::MakeMethods::Composite::Inheritable (
+ array => 'bar',
+ );
+ ...
+
+ # Clear and set contents of list
+ print MyClass->bar([ 'Spume', 'Frost' ] );
+
+ # Set values by position
+ MyClass->bar(0 => 'Foozle', 1 => 'Bang!');
+
+ # Positions may be overwritten, and in any order
+ MyClass->bar(2 => 'And Mash', 1 => 'Blah!');
+
+ # Retrieve value by position
+ print MyClass->bar(1);
+
+ # Direct access to referenced array
+ print scalar @{ MyClass->bar() };
+
+There are also calling conventions for slice and splice operations:
+
+ # Retrieve slice of values by position
+ print join(', ', MyClass->bar( undef, [0, 2] ) );
+
+ # Insert an item at position in the array
+ MyClass->bar([3], 'Potatoes' );
+
+ # Remove 1 item from position 3 in the array
+ MyClass->bar([3, 1], undef );
+
+ # Set a new value at position 2, and return the old value
+ print MyClass->bar([2, 1], 'Froth' );
+
+B<NOTE: THIS METHOD GENERATOR HAS NOT BEEN WRITTEN YET.>
+
+=cut
+
+use vars qw( %ArrayFragments );
+
+sub array {
+ (shift)->_build_composite( \%ArrayFragments, @_ );
+}
+
+%ArrayFragments = (
+ '' => [
+ '+init' => sub {
+ my ($method) = @_;
+ $method->{hash_key} ||= $_->{name};
+ $method->{data} ||= {};
+ },
+ 'do' => sub {
+ my $method = pop @_;
+ my $self = shift @_;
+
+ if ( scalar(@_) == 0 ) {
+ my $v_self = find_vself($method->{data}, $self);
+ my $value = $v_self ? $method->{data}{$v_self} : ();
+ if ( $method->{auto_init} and ! $value ) {
+ $value = $method->{data}{$self} = [];
+ }
+ ( ! $value ) ? () : wantarray ? @$value : $value;
+
+ } elsif ( scalar(@_) == 1 and ref $_[0] eq 'ARRAY' ) {
+ $method->{data}{$self} = [ @{ $_[0] } ];
+ wantarray ? @{ $method->{data}{$self} } : $method->{data}{$self}
+
+ } else {
+ if ( ! exists $method->{data}{$self} ) {
+ my $v_self = find_vself($method->{data}, $self);
+ $method->{data}{$self} = [ $v_self ? @{$method->{data}{$v_self}} : () ];
+ }
+ return array_splicer( $method->{data}{$self}, @_ );
+ }
+ },
+ ],
+);
+
+########################################################################
+
+=head2 hash - Overrideable Ref Accessor
+
+For each method name passed, uses a closure to generate a subroutine with the following characteristics:
+
+=over 4
+
+=item *
+
+May be called as a class method, or on any instance or subclass, Must be called on a hash-based instance.
+
+=item *
+
+The class value will be a reference to a hash (or undef).
+
+=item *
+
+If called without any arguments returns the contents of the hash in list context, or a hash reference in scalar context for the callee. If the callee has not had a value defined for this method, searches up from instance to class, and from class to superclass, until a callee with a value is located.
+
+=item *
+
+If called with one non-ref argument, uses that argument as an index to retrieve from the referenced hash, and returns that value (or undef). If the callee has not had a value defined for this method, searches up from instance to class, and from class to superclass, until a callee with a value is located.
+
+=item *
+
+If called with one array-ref argument, uses the contents of that array to retrieve a slice of the referenced hash. If the callee has not had a value defined for this method, searches up from instance to class, and from class to superclass, until a callee with a value is located.
+
+=item *
+
+If called with one hash-ref argument, sets the contents of the referenced hash to match that provided.
+
+=item *
+
+If called with a list of key-value pairs, stores the value under the given key in the hash associated with the callee, whether instance or class. If the callee did not previously have a hash-ref value associated with it, searches up instance to class, and from class to superclass, until a callee with a value is located, and copies that hash before making the assignments. The current value under each key will be overwritten, and later arguments with the same key will override earlier ones. Returns the contents of the hash in list context, or a hash reference in scalar context.
+
+=back
+
+Sample declaration and usage:
+
+ package MyClass;
+ use Class::MakeMethods::Composite::Inheritable (
+ hash => 'baz',
+ );
+ ...
+
+ # Set values by key
+ MyClass->baz('foo' => 'Foozle', 'bar' => 'Bang!');
+
+ # Values may be overwritten, and in any order
+ MyClass->baz('broccoli' => 'Blah!', 'foo' => 'Fiddle');
+
+ # Retrieve value by key
+ print MyClass->baz('foo');
+
+ # Retrive slice of values by position
+ print join(', ', MyClass->baz( ['foo', 'bar'] ) );
+
+ # Direct access to referenced hash
+ print keys %{ MyClass->baz() };
+
+ # Reset the hash contents to empty
+ @{ MyClass->baz() } = ();
+
+B<NOTE: THIS METHOD GENERATOR IS INCOMPLETE.>
+
+=cut
+
+use vars qw( %HashFragments );
+
+sub hash {
+ (shift)->_build_composite( \%HashFragments, @_ );
+}
+
+%HashFragments = (
+ '' => [
+ '+init' => sub {
+ my ($method) = @_;
+ $method->{hash_key} ||= $_->{name};
+ $method->{data} ||= {};
+ },
+ 'do' => sub {
+ my $method = pop @_;
+ my $self = shift @_;
+
+ if ( scalar(@_) == 0 ) {
+ my $value = get_vvalue($method->{data}, $self);
+ if ( $method->{auto_init} and ! $value ) {
+ $value = set_vvalue( $method->{data}, $self, {} );
+ }
+ wantarray ? %$value : $value;
+ } elsif ( scalar(@_) == 1 ) {
+ if ( ref($_[0]) eq 'HASH' ) {
+ %{$method->{data}{$self}} = %{$_[0]};
+ } elsif ( ref($_[0]) eq 'ARRAY' ) {
+ my $v_self = find_vself($method->{data}, $self) or return;
+ return @{ $method->{data}{$v_self} }{ @{$_[0]} }
+ } else {
+ my $v_self = find_vself($method->{data}, $self) or return;
+ return $method->{data}{$v_self}{ $_[0] }
+ }
+
+ } elsif ( scalar(@_) % 2 ) {
+ Carp::croak "Odd number of items in assigment to $method->{name}";
+ } else {
+ if ( ! exists $method->{data}{$self} ) {
+ my $v_self = find_vself($method->{data}, $self);
+ $method->{data}{$self} = { $v_self ? %{ $method->{data}{$v_self} } : () };
+ }
+ while ( scalar(@_) ) {
+ my $key = shift();
+ $method->{data}{$self}->{ $key } = shift();
+ }
+ wantarray ? %{$method->{data}{$self}} : $method->{data}{$self};
+ }
+ },
+ ],
+);
+
+########################################################################
+
+=head2 hook - Overrideable array of subroutines
+
+A hook method is called from the outside as a normal method. However, internally, it contains an array of subroutine references, each of which are called in turn to produce the method's results.
+
+Subroutines may be added to the hook's array by calling it with a blessed subroutine reference, as shown below. Subroutines may be added on a class-wide basis or on an individual object.
+
+You might want to use this type of method to provide an easy way for callbacks to be registered.
+
+ package MyClass;
+ use Class::MakeMethods::Composite::Inheritable ( 'hook' => 'init' );
+
+ MyClass->init( Class::MakeMethods::Composite::Inheritable->Hook( sub {
+ my $callee = shift;
+ warn "Init...";
+ } );
+
+ my $obj = MyClass->new;
+ $obj->init();
+
+=cut
+
+use vars qw( %HookFragments );
+
+sub hook {
+ (shift)->_build_composite( \%HookFragments, @_ );
+}
+
+%HookFragments = (
+ '' => [
+ '+init' => sub {
+ my ($method) = @_;
+ $method->{data} ||= {};
+ },
+ 'do' => sub {
+ my $method = pop @_;
+ my $self = shift @_;
+
+ if ( scalar(@_) and
+ ref($_[0]) eq 'Class::MakeMethods::Composite::Inheritable::Hook' ) {
+ if ( ! exists $method->{data}{$self} ) {
+ my $v_self = find_vself($method->{data}, $self);
+ $method->{data}{$self} = [ $v_self ? @{ $method->{data}{$v_self} } : () ];
+ }
+ push @{ $method->{data}{$self} }, map $$_, @_;
+ } else {
+ my $v_self = find_vself($method->{data}, $self);
+ my $subs = $v_self ? $method->{data}{$v_self} : ();
+ my @subs = ( ( ! $subs ) ? () : @$subs );
+
+ if ( ! defined $method->{wantarray} ) {
+ foreach my $sub ( @subs ) {
+ &$sub( @{$method->{args}} );
+ }
+ } elsif ( ! $method->{wantarray} ) {
+ foreach my $sub ( @subs ) {
+ my $value = &$sub( @{$method->{args}} );
+ if ( defined $value ) {
+ $method->{result} = \$value;
+ }
+ }
+ } else {
+ foreach my $sub ( @subs ) {
+ my @value = &$sub( @{$method->{args}} );
+ if ( scalar @value ) {
+ push @{ $method->{result} }, @value;
+ }
+ }
+ }
+
+ }
+ return Class::MakeMethods::Composite->CurrentResults();
+ },
+ ],
+);
+
+sub Hook (&) {
+ my $package = shift;
+ my $sub = shift;
+ bless \$sub, 'Class::MakeMethods::Composite::Inheritable::Hook';
+}
+
+########################################################################
+
+=head2 object - Overrideable Ref Accessor
+
+For each method name passed, uses a closure to generate a subroutine with the following characteristics:
+
+=over 4
+
+=item *
+
+May be called as a class method, or on any instance or subclass, Must be called on a hash-based instance.
+
+=item *
+
+The class value will be a reference to an object (or undef).
+
+=item *
+
+If called without any arguments returns the current value for the callee. If the callee has not had a value defined for this method, searches up from instance to class, and from class to superclass, until a callee with a value is located.
+
+=item *
+
+If called with an argument, stores that as the value associated with the callee, whether instance or class, and returns it,
+
+=back
+
+Sample declaration and usage:
+
+ package MyClass;
+ use Class::MakeMethods::Composite::Inheritable (
+ object => 'foo',
+ );
+ ...
+
+ # Store value
+ MyClass->foo( Foozle->new() );
+
+ # Retrieve value
+ print MyClass->foo;
+
+B<NOTE: THIS METHOD GENERATOR HAS NOT BEEN WRITTEN YET.>
+
+=cut
+
+sub object { }
+
+########################################################################
+
+=head1 SEE ALSO
+
+See L<Class::MakeMethods> for general information about this distribution.
+
+See L<Class::MakeMethods::Composite> for more about this family of subclasses.
+
+=cut
+
+1;
diff --git a/lib/Class/MakeMethods/Composite/Universal.pm b/lib/Class/MakeMethods/Composite/Universal.pm
new file mode 100644
index 0000000..e53e76d
--- /dev/null
+++ b/lib/Class/MakeMethods/Composite/Universal.pm
@@ -0,0 +1,150 @@
+=head1 NAME
+
+Class::MakeMethods::Composite::Universal - Composite Method Tricks
+
+=head1 SYNOPSIS
+
+ Class::MakeMethods::Composite::Universal->make_patch(
+ -TargetClass => 'SomeClass::OverYonder',
+ name => 'foo',
+ pre_rules => [
+ sub {
+ my $method = pop;
+ warn "Arguments for foo:", @_
+ }
+ ]
+ post_rules => [
+ sub {
+ warn "Result of foo:", Class::MakeMethods::Composite->CurrentResults
+ }
+ ]
+ );
+
+=head1 DESCRIPTION
+
+The Composite::Universal suclass of MakeMethods provides some generally-applicable types of methods based on Class::MakeMethods::Composite.
+
+=cut
+
+package Class::MakeMethods::Composite::Universal;
+
+$VERSION = 1.000;
+use strict;
+use Class::MakeMethods::Composite '-isasubclass';
+use Carp;
+
+########################################################################
+
+=head1 METHOD GENERATOR TYPES
+
+=head2 patch
+
+The patch ruleset generates composites whose core behavior is based on an existing subroutine.
+
+Here's a sample usage:
+
+ sub foo {
+ my $count = shift;
+ return 'foo' x $count;
+ }
+
+ Class::MakeMethods::Composite::Universal->make(
+ -ForceInstall => 1,
+ patch => {
+ name => 'foo',
+ pre_rules => [
+ sub {
+ my $method = pop @_;
+ if ( ! scalar @_ ) {
+ @{ $method->{args} } = ( 2 );
+ }
+ },
+ sub {
+ my $method = pop @_;
+ my $count = shift;
+ if ( $count > 99 ) {
+ Carp::confess "Won't foo '$count' -- that's too many!"
+ }
+ },
+ ],
+ post_rules => [
+ sub {
+ my $method = pop @_;
+ if ( ref $method->{result} eq 'SCALAR' ) {
+ ${ $method->{result} } =~ s/oof/oozle-f/g;
+ } elsif ( ref $method->{result} eq 'ARRAY' ) {
+ map { s/oof/oozle-f/g } @{ $method->{result} };
+ }
+ }
+ ],
+ },
+ );
+
+=cut
+
+use vars qw( %PatchFragments );
+
+sub patch {
+ (shift)->_build_composite( \%PatchFragments, @_ );
+}
+
+%PatchFragments = (
+ '' => [
+ '+init' => sub {
+ my $method = pop @_;
+ my $origin = ( $Class::MethodMaker::CONTEXT{TargetClass} || '' ) .
+ '::' . $method->{name};
+ no strict 'refs';
+ $method->{patch_original} = *{ $origin }{CODE}
+ or croak "No subroutine $origin() to patch";
+ },
+ 'do' => sub {
+ my $method = pop @_;
+ my $sub = $method->{patch_original};
+ &$sub( @_ );
+ },
+ ],
+);
+
+=head2 make_patch
+
+A convenient wrapper for C<make()> and the C<patch> method generator.
+
+Provides the '-ForceInstall' flag, which is required to ensure that the patched subroutine replaces the original.
+
+For example, one could add logging to an existing method as follows:
+
+ Class::MakeMethods::Composite::Universal->make_patch(
+ -TargetClass => 'SomeClass::OverYonder',
+ name => 'foo',
+ pre_rules => [
+ sub {
+ my $method = pop;
+ warn "Arguments for foo:", @_
+ }
+ ]
+ post_rules => [
+ sub {
+ warn "Result of foo:", Class::MakeMethods::Composite->CurrentResults
+ }
+ ]
+ );
+
+=cut
+
+sub make_patch {
+ (shift)->make( -ForceInstall => 1, patch => { @_ } );
+}
+
+
+########################################################################
+
+=head1 SEE ALSO
+
+See L<Class::MakeMethods> for general information about this distribution.
+
+See L<Class::MakeMethods::Composite> for more about this family of subclasses.
+
+=cut
+
+1;
diff --git a/lib/Class/MakeMethods/Docs/Catalog.pod b/lib/Class/MakeMethods/Docs/Catalog.pod
new file mode 100644
index 0000000..ba17349
--- /dev/null
+++ b/lib/Class/MakeMethods/Docs/Catalog.pod
@@ -0,0 +1,888 @@
+=head1 NAME
+
+Class::MakeMethods::Docs::Catalog - List of Makable Method Types
+
+
+=head1 DESCRIPTION
+
+This document lists the various subclasses of Class::MakeMethods included
+in this distribution, and the method types each one provides.
+
+See the documentation for each implementation for more details
+about the features it provides.
+
+For each class, a parenthetical comment indicates whether the methods it generates are applicable to individual blessed objects (Instances), to class data (Global), or both (Any)
+=head2 Scoping
+
+The final part of the name of a method-generating subclass typically indicates the scope or applicability of the methods it generates
+
+=over 4
+
+=item Hash
+
+For object instances based on blessed hashes with named values.
+
+=item Array
+
+For object instances based on blessed arrays with positional values.
+
+=item Scalar
+
+For object instances based on blessed scalars with a single value.
+
+=item InsideOut
+
+For any object instance regardless of underlying data type.
+
+=item Ref
+
+For any object instance regardless of underlying data type.
+
+=item Inheritable
+
+For data which can be set at the class, subclass, or instance level.
+
+=item Class
+
+For class data shared by all instances but different for each subclass
+
+=item ClassVar
+
+For class data shared by all instances but different for each subclass
+
+=item ClassInherit
+
+For class data shared by all instances but different for each subclass
+
+=item Global
+
+For global data shared by a class and all its instances and subclasses
+
+=item PackageVar
+
+For global data shared by a class and all its instances and subclasses
+
+=item Universal
+
+# General method types that are widely applicable
+
+=back
+
+=head2 Summary Charts
+
+This table shows which scopes are available in each generator family:
+
+ SCOPING Basic Standard Evaled Composite Template
+ Hash + + + + +
+ Array + + + +
+ Scalar +
+ InsideOut +
+ Ref +
+ Inheritable + + +
+ Class +
+ ClassVar +
+ ClassInherit +
+ Global + + + +
+ PackageVar +
+ Universal + +
+
+This table shows which types of methods are typically available in each generator family:
+
+ METHOD Basic Standard Evaled Composite Template
+ new + + + +
+
+ scalar + + + +
+ string +
+ string_index +
+ number +
+ boolean +
+ boolean_index +
+ bits +
+
+ array + + + +
+ struct +
+
+ hash + + + +
+ hash_of_arrays +
+ tiedhash +
+
+ object + + +
+ instance +
+ array_of_objects +
+
+ code +
+ code_or_scalar +
+
+
+=head1 BASIC CLASSES
+
+=head2 Basic::Hash (Instances)
+
+Methods for objects based on blessed hashes. See L<Class::MakeMethods::Basic::Hash> for details.
+
+=over 4
+
+=item *
+
+new: create and copy instances
+
+=item *
+
+scalar: get and set scalar values in each instance
+
+=item *
+
+array: get and set values stored in an array refered to in each
+instance
+
+=item *
+
+hash: get and set values in a hash refered to in each instance
+
+=back
+
+=head2 Basic::Array (Instances)
+
+Methods for manipulating positional values in arrays. See L<Class::MakeMethods::Basic::Array> for details.
+
+=over 4
+
+=item *
+
+new: create and copy instances
+
+=item *
+
+scalar: get and set scalar values in each instance
+
+=item *
+
+array: get and set values stored in an array refered to in each
+instance
+
+=item *
+
+hash: get and set values in a hash refered to in each instance
+
+=back
+
+=head2 Basic::Global (Global)
+
+Global methods are not instance-dependent; calling them by class
+name or from any instance or subclass will consistently access the
+same value. See L<Class::MakeMethods::Basic::Global> for details.
+
+=over 4
+
+=item *
+
+scalar: get and set a global scalar value
+
+=item *
+
+array: get and set values in a global array
+
+=item *
+
+hash: get and set values in a global hash
+
+=back
+
+
+=head1 STANDARD CLASSES
+
+=head2 Standard::Hash (Instances)
+
+Methods for objects based on blessed hashes. See L<Class::MakeMethods::Standard::Hash> for details.
+
+=over 4
+
+=item *
+
+new: create and copy instances
+
+=item *
+
+scalar: get and set scalar values in each instance
+
+=item *
+
+array: get and set values stored in an array refered to in each
+instance
+
+=item *
+
+hash: get and set values in a hash refered to in each instance
+
+=item *
+
+object: access an object refered to by each instance
+
+=back
+
+=head2 Standard::Array (Instances)
+
+Methods for manipulating positional values in arrays. See L<Class::MakeMethods::Standard::Array> for details.
+
+=over 4
+
+=item *
+
+new: create and copy instances
+
+=item *
+
+scalar: get and set scalar values in each instance
+
+=item *
+
+array: get and set values stored in an array refered to in each
+instance
+
+=item *
+
+hash: get and set values in a hash refered to in each instance
+
+=item *
+
+object: access an object refered to by each instance
+
+=back
+
+=head2 Standard::Global (Global)
+
+Methods for manipulating global data. See L<Class::MakeMethods::Standard::Global> for details.
+
+=over 4
+
+=item *
+
+scalar: get and set global scalar
+
+=item *
+
+array: get and set values stored in a global array
+
+=item *
+
+hash: get and set values in a global hash
+
+=item *
+
+object: global access to an object ref
+
+=back
+
+
+=head2 Standard::Inheritable (Any)
+
+Methods for manipulating data which may be overridden per class or instance. Uses external data storage, so it works with objects of any underlying data type. See L<Class::MakeMethods::Standard::Inheritable> for details.
+
+=over 4
+
+=item *
+
+scalar: get and set scalar values for each instance or class
+
+=back
+
+
+=head1 COMPOSITE CLASSES
+
+=head2 Composite::Hash (Instances)
+
+Methods for objects based on blessed hashes. See L<Class::MakeMethods::Composite::Hash> for details.
+
+=over 4
+
+=item *
+
+new: create and copy instances
+
+=item *
+
+scalar: get and set scalar values in each instance
+
+=item *
+
+array: get and set values stored in an array refered to in each
+instance
+
+=item *
+
+hash: get and set values in a hash refered to in each instance
+
+=item *
+
+object: access an object refered to by each instance
+
+=back
+
+=head2 Composite::Array (Instances)
+
+Methods for manipulating positional values in arrays. See L<Class::MakeMethods::Composite::Array> for details.
+
+=over 4
+
+=item *
+
+new: create and copy instances
+
+=item *
+
+scalar: get and set scalar values in each instance
+
+=item *
+
+array: get and set values stored in an array refered to in each
+instance
+
+=item *
+
+hash: get and set values in a hash refered to in each instance
+
+=item *
+
+object: access an object refered to by each instance
+
+=back
+
+=head2 Composite::Global (Global)
+
+Methods for manipulating global data. See L<Class::MakeMethods::Composite::Global> for details.
+
+=over 4
+
+=item *
+
+scalar: get and set global scalar
+
+=item *
+
+array: get and set values stored in a global array
+
+=item *
+
+hash: get and set values in a global hash
+
+=item *
+
+object: global access to an object ref
+
+=back
+
+
+=head2 Composite::Inheritable (Any)
+
+Methods for manipulating data which may be overridden per class or instance. Uses external data storage, so it works with objects of any underlying data type. See L<Class::MakeMethods::Composite::Inheritable> for details.
+
+=over 4
+
+=item *
+
+scalar: get and set scalar values for each instance or class
+
+=item *
+
+hook: create a subroutine intended to have operations added to it
+
+=back
+
+
+=head2 Composite::Universal (Any)
+
+Methods for padding pre- and post-conditions to any class. See L<Class::MakeMethods::Composite::Universal> for details.
+
+=over 4
+
+=item *
+
+patch: add pre and post operations to an existing subroutine
+
+=back
+
+
+=head1 TEMPLATE CLASSES
+
+=head2 Template::Universal (Any)
+
+Meta-methods for any type of object. See L<Class::MakeMethods::Template::Universal>.
+
+=over 4
+
+=item *
+
+no_op - a method with an empty body
+
+=item *
+
+croak - a method which will croak if called
+
+=item *
+
+method_init - calls other methods from a list of method name => argument pairs
+
+=item *
+
+forward_methods - delegates to an object provided by another method
+
+=back
+
+=head2 Template::Ref (Any Instance)
+
+Methods for deep copies and comparisons. See L<Class::MakeMethods::Template::Ref>.
+
+=over 4
+
+=item *
+
+clone: make a deep copy of an object instance
+
+=item *
+
+prototype: make new objects by cloning a typical instance
+
+=item *
+
+compare: compare one object to another
+
+=back
+
+
+=head2 Template::Generic (Abstract)
+
+The remaining subclasses inherit a similar collection of templates from Template::Generic, and provide a different type of scoping or binding for the functionality defined by the Generic template. See L<Class::MakeMethods::Template::Generic> for details.
+
+
+=head2 Template::Hash (Instances)
+
+The most commonly used implementation, for objects based on blessed hashes. See L<Class::MakeMethods::Template::Hash>.
+
+=over 4
+
+=item *
+
+new: create and copy instances
+
+=item *
+
+scalar: get and set scalar values in each instance
+
+=item *
+
+string: get and set string values in each instance
+
+=item *
+
+number: get and set numeric values in each instance
+
+=item *
+
+boolean: get and set boolean values in each instance
+
+=item *
+
+bits: get and set boolean values stored in a single value in each
+instance
+
+=item *
+
+array: get and set values stored in an array refered to in each
+instance
+
+=item *
+
+struct - methods for acccessing values which are stored by
+position in an array
+
+=item *
+
+hash: get and set values in a hash refered to in each instance
+
+=item *
+
+tiedhash: get and set values in a tied hash refered to in each
+instance
+
+=item *
+
+hash_of_arrays: for references to hashes of arrays contained in each
+instance
+
+=item *
+
+object: set or access a reference to an object contained in each
+instance
+
+=item *
+
+array_of_objects: manipulate an array of object references within in
+each instance
+
+=item *
+
+code: set or call a function reference contained in each instance
+
+=back
+
+
+=head2 Template::Array (Instances)
+
+Methods for manipulating positional values in arrays. See L<Class::MakeMethods::Template::Array>.
+
+=over 4
+
+=item *
+
+new: create and copy array instances
+
+=item *
+
+scalar: get and set scalar values in a given array position
+
+=item *
+
+string: get and set string values in a given array position
+
+=item *
+
+number: get and set numeric values in a given array position
+
+=item *
+
+boolean: get and set boolean values in a given array position
+
+=item *
+
+builtin_isa: generates a wrapper around some builtin function,
+cacheing the results in the object and providing a by-name interface
+
+=back
+
+
+
+=head2 Template::Scalar (Instances)
+
+For objects based on blessed scalars. See L<Class::MakeMethods::Template::Scalar>.
+
+Note that these objects can generally only have one value accessor method, as all such accessors will refer to the same value.
+
+=over 4
+
+=item *
+
+new: create and copy instances
+
+=item *
+
+scalar: get and set scalar values in each instance
+
+=item *
+
+string: get and set a string value in each instance
+
+=item *
+
+number: get and set a numeric value in each instance
+
+=item *
+
+boolean: get and set a boolean value in each instance
+
+=item *
+
+bits: get and set boolean values stored in a single value in each
+instance
+
+=item *
+
+code: set or call a function reference contained in each instance
+
+=back
+
+
+=head2 Template::InsideOut (Instances)
+
+Stores values for objects in an external location hashed by identity. See L<Class::MakeMethods::Template::InsideOut>.
+
+Note that while the below constructor creates and returns scalar
+references, accessor methods can be created with this implementation
+for use with any type of object.
+
+=over 4
+
+=item *
+
+new: create and copy instances
+
+=item *
+
+scalar: get and set scalar values associated with each instance
+
+=item *
+
+string: get and set string values associated with each instance
+
+=item *
+
+string_index: get and set string values associated with each
+instance, and maintain an index of instances by value
+
+=item *
+
+number: get and set numeric values associated with each instance
+
+=item *
+
+boolean: get and set boolean values associated with each instance
+
+=item *
+
+boolean_index: get and set boolean values associated with each instance, and maintain a list of items which have the flag set
+
+=item *
+
+bits: get and set boolean values stored in a single value associated with each
+instance
+
+=item *
+
+array: get and set values stored in an array associated with each
+instance
+
+=item *
+
+hash: get and set values in a hash associated with each instance
+
+=item *
+
+code: set or call a function reference associated with each instance
+
+=back
+
+
+=head2 Template::Global (Global)
+
+Global methods are not instance-dependent; calling them by class
+name or from any instance will consistently access the same value. See L<Class::MakeMethods::Template::Static>.
+
+=over 4
+
+=item *
+
+scalar: get and set a global scalar value
+
+=item *
+
+string: get and set a global string value
+
+=item *
+
+number: get and set a global number value
+
+=item *
+
+boolean: get and set a global boolean value
+
+=item *
+
+array: get and set values in a global array
+
+=item *
+
+hash: get and set values in a global hash
+
+=item *
+
+tiedhash: get and set values in a global tied hash
+
+=item *
+
+hash_of_arrays: get and set values in a global hash of arrays
+
+=item *
+
+object: set and access a global reference to an object
+
+=item *
+
+instance: set and access a global reference to an object of the declaring class
+
+=item *
+
+code: set and access a global reference to a subroutine.
+
+=back
+
+
+=head2 Template::PackageVar (Global)
+
+PackageVar methods access a variable in the declaring package. Thus,
+they have the same effect as Static methods, while keeping their
+value accessible via the symbol table. See L<Class::MakeMethods::Template::PackageVar>.
+
+=over 4
+
+=item *
+
+scalar: get and set a global scalar value
+
+=item *
+
+string: get and set a global string value
+
+=item *
+
+number: get and set a global number value
+
+=item *
+
+boolean: get and set a global boolean value
+
+=item *
+
+array: get and set values in a global array
+
+=item *
+
+hash: get and set values in a global hash
+
+=back
+
+
+=head2 Template::Class (Global)
+
+Class methods are similar to Static methods, except that each subclass and its instances will access a distinct value. See L<Class::MakeMethods::Template::Class>.
+
+=over 4
+
+=item *
+
+scalar: get and set a class-specific scalar value
+
+=item *
+
+string: get and set a class-specific string value
+
+=item *
+
+number: get and set a class-specific number value
+
+=item *
+
+boolean: get and set a class-specific boolean value
+
+=item *
+
+array: get and set values in a class-specific array
+
+=item *
+
+hash: get and set values in a class-specific hash
+
+=back
+
+
+=head2 Template::ClassVar (Global)
+
+ClassVar methods access a variable in the package on which they
+are called. Thus, they have the same effect as Class methods,
+while keeping their value accessible via the symbol table, like
+PackageVar. See L<Class::MakeMethods::Template::ClassVar>.
+
+=over 4
+
+=item *
+
+scalar: get and set a class-specific scalar value
+
+=item *
+
+string: get and set a class-specific string value
+
+=item *
+
+number: get and set a class-specific number value
+
+=item *
+
+boolean: get and set a class-specific boolean value
+
+=item *
+
+array: get and set values in a class-specific array
+
+=item *
+
+hash: get and set values in a class-specific hash
+
+=back
+
+
+=head2 Template::ClassInherit (Global)
+
+ClassInherit methods are an intermediate point between Static and Class methods; subclasses inherit their superclass's value until they set their own value, after which they become distinct. See L<Class::MakeMethods::Template::ClassInherit>.
+
+=over 4
+
+=item *
+
+scalar: get and set an inheritable class-specific scalar value
+
+=item *
+
+string: get and set an inheritable class-specific string value
+
+=item *
+
+number: get and set an inheritable class-specific number value
+
+=item *
+
+boolean: get and set an inheritable class-specific boolean value
+
+=item *
+
+array: get and set values in an inheritable class-specific array
+
+=item *
+
+hash: get and set values in an inheritable class-specific hash
+
+=back
+
+
+=head2 Template::Inheritable (Any)
+
+Methods for manipulating data which may be overridden per class or instance. Uses external data storage, so it works with objects of any underlying data type. See L<Class::MakeMethods::Template::Inheritable> for details.
+
+=over 4
+
+=item *
+
+scalar: get and set scalar values for each instance or class
+
+=item *
+
+string: get and set string values for each instance or class
+
+=item *
+
+number: get and set numeric values for each instance or class
+
+=item *
+
+boolean: get and set boolean values for each instance or class
+
+=item *
+
+hash: get and set values in a hash refered to in each instance
+
+=back
+
+
+=head1 SEE ALSO
+
+See L<Class::MakeMethods> for general information about this distribution.
+
+=cut
diff --git a/lib/Class/MakeMethods/Docs/Changes.pod b/lib/Class/MakeMethods/Docs/Changes.pod
new file mode 100644
index 0000000..8b01f0a
--- /dev/null
+++ b/lib/Class/MakeMethods/Docs/Changes.pod
@@ -0,0 +1,661 @@
+=head1 NAME
+
+Class::MakeMethods::Docs::Changes - History of Class::MakeMethods
+
+=head1 SYNOPSIS
+
+Revision history for Class::MakeMethods.
+
+=head1 CHANGES
+
+=head2 Version 1.010
+
+=over 4
+
+=item 2004/09/06
+
+Moved get_declarations() and associated documentation from Standard module to superclass.
+
+=item 2004/09/03
+
+Developed test.pl test harness with recursive file search to fix Windows "command line too long" errors.
+
+=item 2004/09/01
+
+Moved Template::TextBuilder and Template::DiskCache into Utility:: namespace.
+
+Added support for defaults with -- and -param to Standard get_declarations().
+
+=item 2004/08/12
+
+Began testing and integrating tied-value patches from Dominique Dumont.
+
+=item 2004/04/27
+
+Added method types to Evaled::Hash.
+
+=item 2004/04/23
+
+Added skeleton of a new Evaled::Hash class.
+
+=back
+
+=head2 Version 1.009
+
+=over 4
+
+=item 2003/09/25
+
+Added Emulator::mcoder and compatibility tests.
+
+Released to CPAN as Class-MakeMethods-1.009.tar.gz.
+
+=item 2003/09/22
+
+Added support for lvalue methods to Template and Template::Generic. Added a few tests to demonstrate they're working. Added an example to Docs::Examples.
+
+Added Emulator::accessors and compatibility tests.
+
+Minor documentation improvements.
+
+=back
+
+=head2 Version 1.008
+
+=over 4
+
+=item 2003/09/05
+
+Adjusted layout of test directories in another attempt to solve a MakeMaker/shell-glob issue on Windows that was preventing make test from running correctly.
+
+Removed Template::PseudoHash, since this package never really worked, as pointed out by a question from Mike Castle. Management of array-based objects can be handled by any of the existing ::Array subclasses, and support for pseudo-hashes would not provide any useful new capabilities.
+
+Added support for "Template::Universal:forward_methods -delegate" and "Template::Generic:object --soft_delegate" based on a suggestion from Peter Chen. Extended behavior of Template -subs handling to make it easy to add such functionality in the future.
+
+Released to CPAN as Class-MakeMethods-1.008.tar.gz.
+
+=item 2003/09/02
+
+Adjusted DESTROY behavior of Template::InsideOut and cleaned up documentation.
+
+=back
+
+=head2 Version 1.007
+
+=over 4
+
+=item 2003/09/01
+
+Made Template definitions automatically import their class's generic
+definitions, if present. This eliminates the need for Generic
+subclasses to explicitly redeclare every method it inherits, and
+should obviate the "missing declaration" problems referenced below.
+
+Updated the names of several Template subclasses, with stubs at
+the old names for backwards compatibility: Flyweight becomes
+InsideOut, Static becomes Global, and Struct becomes Array.
+
+Added Template::Inheritable and basic tests for it.
+
+Eliminated use of legacy Test.pm from remaining tests, except for
+MethodMaker emulation.
+
+Rearranged test directories in an effort to avoid a reported bug
+with the test path of t/*/*.t under Windows.
+
+Released to CPAN as Class-MakeMethods-1.007.tar.gz.
+
+=item 2003/08/27
+
+Added section to Class::MakeMethods/EXTENDING documentation based
+on question from Terrence Brannon.
+
+=item 2003/02/07
+
+Fixed missing declaration of Template::Hash:instance, reported via RT.
+
+=back
+
+=head2 Version 1.006
+
+=over 4
+
+=item 2003/01/26
+
+Additional documentation touch-ups. Moved miscellaneous POD files into the Docs directory.
+
+Added new test scripts from Class-MethodMaker-1.08, although we
+don't yet pass them. In particular, I need to add support for the
+new method types added in 1.04: tie_scalar, tie_list, object_tie_list,
+object_tie_hash
+
+Also need to compare against the changes included in Class-MethodMaker-1.09 and 1.10, which don't seem to include any new test code, but do include functionality changes.
+
+=item 2002/12/12
+
+Re-integrated Template and Emulator packages; the separate distribution
+turned out to be a hastle rather than a convenience. However, in
+order to keep test scripts for each subsystem separate, I'm now
+using a Makefile.PL attribute to specify a two-level deep directory
+tree of test scripts; I hope this doesn't break on Windows...
+
+Fixed possible "use of undefined as a reference" problem in
+Standard::*::array method generators, reported by Jared Rhine.
+
+Tried to improve documentation, based on feedback from Jared Rhine.
+Expunged ReadMe.pod. Extracted method catalogs into Catalog.pod.
+Moved examples to new Example.pod, although that underlines how
+few examples there are.
+
+=back
+
+
+=head2 Version 1.005
+
+=over 4
+
+=item 2002/06/06
+
+Added Autoload interface.
+
+Modifed Attribute interface to add "inheritable" default logic for
+Maker class parameter. (Suggested by Malcolm Cook.)
+
+Fixed typo in documentation for Standard::Universal. (Spotted by
+Malcolm Cook.)
+
+=back
+
+
+=head2 Version 1.004
+
+=over 4
+
+=item 2002/03/23
+
+Released to CPAN as Class-MakeMethods-1.004.tar.gz.
+
+=item 2002/03/16
+
+Allow double-colons between package name and method generator name.
+
+=item 2002/02/19
+
+Fixed related use of undef in Standard::*:hash methods.
+
+=item 2002/02/14
+
+Adjusted Standard::*:hash methods to avoid assuming that the hashref
+already exists.
+
+=item 2002/02/07
+
+Added missing *_reset => clear to Template number --counter interface.
+
+=item 2002/02/02
+
+Adjusted error message in Utility::ArraySplicer
+
+=item 2002/01/26
+
+Applied small documentation corrections suggested by Adam Spiers.
+
+Added Standard::Universal:alias.
+
+=back
+
+=head2 Version 1.003
+
+=over 4
+
+=item 2002/01/24
+
+Folded "Getting Started Guide" POD into main module documentation.
+
+Renamed Utility::TakeName to Emulator.
+
+Split Template and Emulator packages into their own distributions.
+
+B<Please Note:> This means that to fully upgrade you must retrieve
+all three of these files:
+
+ Class-MakeMethods-1.003.tar.gz
+ Class-MakeMethods-Template-1.003.tar.gz
+ Class-MakeMethods-Emulator-1.003.tar.gz
+
+Of course, if you're not using the Template or Emulator classes,
+there's no need to download them...
+
+
+=item 2002/01/21
+
+Started bumping sub-version numbers and not using sub-sub-versions,
+to shorten distribution names and more closely match standard
+practice.
+
+Added Composite::Inheritable:hook and matching test. Added
+Composite->CurrentResults method to easily access, update composite
+method results.
+
+=back
+
+=head2 Version 1.000.*
+
+=over 4
+
+=item v1.000.16 - 2002/01/21
+
+Released to CPAN as v1.000.016.
+
+=item v1.000.16 - 2002/01/20
+
+Adjusted the hash and array methods in the Standard::* and Composite::*
+packages to properly accept a set-contents call with a single
+reference argument, and to return contents rather than ref in list
+context.
+
+=item v1.000.16 - 2002/01/14
+
+Fixed a subtle bug in a test script inherited from Class::MethodMaker:
+4_Template_hash_hash_array.t and 7_MethodMaker_hash_of_lists.t both
+relied on "keys %hash" returning the keys in a particular order,
+which *almost* always worked, but caused failures on one or more
+Perl version/platform combinations.
+
+
+=item v1.000.15 - 2002/01/14
+
+Released to CPAN as v1.000.015.
+
+=item v1.000.15 - 2002/01/12
+
+Renamed Basic::Static to Basic::Global for consistency with Standard
+and Composite. Hopefully, there aren't many users of this module
+yet; please accept my apologies if this breaks your code.
+
+Eliminated "local @_ = ...", which appears to cause a scoping
+problem on Perl 5.6. Thanks to Adam Spiers for a thorough bug
+report. (See http://www.perlmonks.org/index.pl?node_id=138370 for
+details.)
+
+Extended Template::Generic to support "array --get_set_ref" method
+style requested by Adam Spiers.
+
+Various documentation tweaks, including feedback from Adam Spiers:
+Adjusted documentation to downplay Basic::* modules as a starting
+point, in favor of Standard::* ones. Trimmed out some duplicated
+documentation in favor of more "See LE<lt>...E<gt>" links. Adjusted
+documentation of *::Inheritable packages in an attempt to clarify
+the way in which the inheritance tree is searched for a value.
+
+Factored out common code from Standard::Inheritable and
+Composite::Inheritable to new module, Utility::Inheritable. Factored
+out common code from Standard::Hash and Standard::Array to new
+module, Utility::ArraySplicer. Factored out common code from
+Template::Universal to new module, Utility::Ref. Renamed
+Emulator::TakeName to Utility::TakeName (this is internal use only,
+so there should be no public impact).
+
+
+=item v1.000.15 - 2001/12/01
+
+Adjusted Template::Universal's code for _CALL_METHODS_FROM_HASH_,
+to ensure that method/arg pairs are called in order they were passed
+in.
+
+=item v1.000.15 - 2001/07/04, 2001/07/19
+
+Minor additions to documentation of various method types.
+
+
+=item v1.000.14 - 2001/07/01
+
+Released as v1.000.014.
+
+
+=item v1.000.14 - 2001/06/25, 2001/06/29, 2001/07/01
+
+Removed Makefile rule from Makefile.PL to avoid warnings when used
+with recent versions of ExtUtils::MakeMaker, which also define a
+similar rule. (Based on bug report from Ron Savage.)
+
+Fixed test failure for machines with P5.6 but no Attribute::Handlers.
+(Reported by Ron Savage, Jay Lawrence.)
+
+Added Template::Flyweight:string_index. (But still needs test
+script.)
+
+Added Standard::Universal. (But still needs test scripts.)
+
+Minor touch-ups to ReadMe and Guide documentation.
+
+
+=item v1.000.13 - 2001/05/16, 2001/05/18, 2001/05/20, 2001/06/02, 2001/06/22, 2001/06/24
+
+To date, this module has been circulated under several provisional
+names: it was originally floated as a possible version-2 rewrite
+of Class::MethodMaker, then renamed to Class::Methods when it forked
+from that project, and then briefly to Class::MethodGenerator.
+(Note that it can be surprisingly difficult to comply with both of
+these L<perlmodlib> guidelines: "To be portable each component of
+a module name should be limited to 11 characters. [...] Always
+try to use two or more whole words.") In the end, I selected
+Class::MakeMethods, as it is two whole words, and is reminiscent
+of Class::MethodMaker without being confusing (I hope!), and I
+believe this issue is now settled.
+
+Standardized syntax for global options; renamed -implementation to
+-MakerClass and -target_class to -TargetClass. Moved $TargetClass
+and other context information into %CONTEXT with _context accessor.
+Added ForceInstall.
+
+Completed re-simplification of build directories; we're back to a
+single Makefile, which avoids a warning in P5.6.0.
+
+Added Attribute interface for use with P5.6 and later, based on
+Attribute::Handlers.
+
+Renamed "Simple" subclasses to "Basic". Added documentation and
+initial tests.
+
+Added Standard subclasses with parameter parsing and more powerful
+accessors.
+
+Modified Emulator::Struct to use Standard::* methods. Found struct
+test from P5.7, and added auto_init functionality to match.
+
+Added Composite::* subclasses.
+
+Added Emulator::AccessorFast.
+
+Added Class::MakeMethods::Guide with introduction and examples.
+
+Continued clean-up effort on Template documentation. Renamed Template
+"attributes" to "method parameters" to avoid confusion with Perl
+attributes. Retitled Template naming rules from "templates" to
+"interfaces".
+
+Changed initialization code expressions of Template::Class in hopes
+of P5.6.1 compatibility. (Problem reported by M Schwern.)
+
+Added 'Template::Generic:new --and_then_init' based on feedback
+from Jay Lawrence.
+
+=back
+
+=head2 Early 1.000 versions
+
+=over 4
+
+=item v1.000.12 - 2001/05/14
+
+Renamed module to Class::MethodGenerator, although naming questions
+remain.
+
+Moved Template subclasses into Template::* namespace. Simplified
+build directory and makefile structure.
+
+Changed initialization code expressions of Template::PackageVar,
+ClassVar for P5.6.0 compatibility. (Reported by M Schwern.)
+
+
+=item v1.000.11 - 2001/05/07, 2001/05/12
+
+Eliminated Bundle file. Moved general documentation to cm_base.
+
+Renamed Class::Methods::Base to Class::Methods::Generator.
+
+Extracted code for Template declarations to new Class::Methods::Template
+module. Extracted disk-caching to new Template::DiskCache module.
+Moved TextBuilder into the Template:: tree.
+
+Moved _namespace_capture code to new package
+Class::Methods::Emulator::TakeName.
+
+Added Simple::Hash subclass.
+
+
+=item v1.000.10 - 2001/04/26, 2001/05/02, 2001/05/04
+
+Moved _namespace_capture and _namespace_release to Class::Methods::Base.
+
+Additional doc tweakage. Moved ReadMe documentation to
+Bundle::ClassMethods. Merged Extending documentation into Base.
+
+Removed spurious uses of -default => 'default' in templates.
+
+Added new ClassInherit subclass and Emulator::Inheritable.
+
+Expunged Index subclass in favor of boolean_index and string_index
+types on Generic.
+
+Moved Struct:builtin_isa type to new package, StructBuiltin.
+
+Refactored code templating function as Class::Methods::Base::TextBuilder.
+
+
+=item v1.000.9 - 2001/03/24
+
+Reversed sense of - and --, as it was in 1.000.1.
+
+Separated source files into separate directories with distinct
+Makefiles and test hierarchies. This should clarify the boundaries
+between the core method-generation code, the common constructor/accessor
+methods, and the various emulator and experimental packages.
+
+
+=item v1.000.8 - 2001/01/19
+
+Following receipt of a suggestion to fork from the maintainer of
+Class::MethodMaker, renamed packge from Class::MethodMaker v2.0 to
+Class::Methods v1.000.
+
+Adjusted documentation to reflect fork, although additional cleanup
+is still needed.
+
+Moved backward compatibility to Emulator::MethodMaker subclass.
+
+Added Generic -compatibility array index_* and hash_of_arrays *_last
+and *_set methods to match changes in Class::MethodMaker v1.02.
+Added Emulator::MethodMaker support for the '-static' flag. The
+emulator now completely satisfies the enclosed test suites, from
+Class::MethodMaker v0.92 and v1.02.
+
+
+=item v1.000.7 - 2001/01/05, 2001/01/06, 2001/01/07
+
+Moved core code and internal code to Internals.pm. MethodMaker.pm
+now contains only some require statements and the general user
+guide documentation.
+
+Moved ReadMe.pod, Changes.pod, and ToDo.pod into MethodMaker
+directory. Separated Catalog.pod, Extending.pod, RelatedModules.pod.
+
+Included version 1 docs as Class::Methods::OriginalDocs; minor
+revisions for clarity.
+
+Renamed Package subclass to PackageVar, Class to ClassVar.
+
+Added Emulation::Struct subclass.
+
+Added support for shifting targets with make( -target_class =>
+Package, ... ).
+
+Extended ClassName subclass to handle requiring, rather than creating
+subclases.
+
+
+=item v1.000.6 - 2000/12/29, 2001/01/02, 2001/01/04
+
+Restored -sugar import option for compatibility with earlier
+versions.
+
+Added plural names to "Generic:hash -compatibility" to support
+v0.92 usage.
+
+Replaced use of substr(..., 0, 1) with ... =~ s/^-// for P5.004
+compatibility; problem found by Scott Godin.
+
+Copy @_ before splicing and pushing on to it for P5.004 compatibility.
+
+Expunged duplicate lines from Generic.pm's array_of_objects; found
+by Ron Savage.
+
+Renamed Hash.pm's delete and exists behaviors to avoid possible
+run-time import conflict with Generic.pm's behaviors; failure
+reported by Ron Savage.
+
+Added _STATIC_ATTR_{return_value_undefined} attributes to Generic
+string and number to allow overrides of this functionality.
+
+Minor doc touchups and expanded examples section.
+
+
+=item v1.000.5 - 2000/11/28, 2000/12/16, 2000/12/28
+
+Added Universal -warn_calls modifier.
+
+Folded various pod files together into main module's inline
+documentation. Updated catalog of existing implementations in
+documentation. Added pointers to some tutorials and books which
+discuss Class::Methods.
+
+Standardized naming of test scripts.
+
+Can now specify default template name, via -default=>"foo".
+
+
+=item v1.000.4 - 2000/11/22
+
+Separated string, number, and boolean from the Generic scalar
+methods.
+
+Provide _disk_cache to shortcut the lengthy _interpret_text_builder
+process.
+
+Fixes to ClassName implementation.
+
+Change to forward methods to provide better error messages when
+object is empty.
+
+
+=item v1.000.3 - 2000/11/03
+
+Rearranged documentation into separate files in the pod/ directory.
+
+Collapsed find_target_class and make functionality into import;
+moved support for the old functions to the Compatibility module.
+
+Adjusted tests to generally use standard syntax, and not Compatibility
+hooks.
+
+
+=item v1.000.2.1 - 2000/10/23
+
+Moved commonly-accessible information to Universal.
+
+Added block{...} replacement for enhanced behavior templating.
+
+Added modifier mechanism to support -private and -protected.
+
+May need to be able to specify import ordering so that modifiers
+are applied in the right order. This hasn't bit me yet, but it's
+there. Darn.
+
+
+=item v1.000.2 - 2000/10/22
+
+Completed generalization of Generic methods from Static and Hash.
+Rewrote ClassVar and PackageVar to use Generic framework.
+
+Attribute expansion can now substitute values besides name, using
+*{attr}.
+
+Added _diagnostics function and documentation of all failure
+messages.
+
+Added SEE ALSO section to documentation, brief review of Class::*
+on CPAN. Stumbled across Damian Conway's very nice Class::Contract
+module.
+
+Added Scalar and Flyweight implementations.
+
+
+=item v1.000.1.1 - 2000/10/21
+
+Rolled back change from yesterday; can still pick templates like
+'-java'. Allow attributes to be specified as '--foo'=>'bar' or
+'--'=>{foo=>'bar'}
+
+Automated caching for meta-method definition hashes.
+
+Generalized several Static and Hash interfaces into Generic templates.
+Added Static:array and Static:code support.
+
+Allow global -import to set default sources for templates, exprs,
+behaviors.
+
+
+=item v1.000.1 - 2000/10/19
+
+Support inheritance of templates between meta-methods with -import.
+
+Made "template" an attribute, rather than a special state variable.
+
+Allow any attribute to be specified as -foo=>'bar'. Changed
+selection of standard templates from '-java' to '--java'.
+
+Initial support for string-eval behaviors and code_exprs, and
+Generic.pm
+
+
+=item v1.000.0 - 2000/10/14, 2000/10/15
+
+Completed initial pass of full rewrite.
+
+Assorted cleanup of syntax and documentation.
+
+Moved Hash, Static, and Index implementations into separate packages.
+
+
+=item v0.9.3 - 2000/09/30
+
+Refactored subclass_name and class_registry.
+
+Folded in some misc improvements from Class::MethodMaker 1.0.
+
+
+=item v0.97x - 2000/08/04 to 2000/08/13
+
+Forked from Class::MethodMaker 0.96. Substantial rewrite started
+
+Created build_meta_method and refactored many methods to use it.
+
+Added new_hash, hash_init, new_from_prototype.
+
+Extended arg format. Added -template=>behavior_name. Added support
+for array-of-names arguments.
+
+Performance tuning. Additional refactoring to support AutoSplit
+functionality.
+
+Also folded in some older changes and additions from Evolution's
+internal collection of MethodMaker subclasses:
+
+=back
+
+=head2 Class::MethodMaker::Extensions
+
+Change notes from unreleased collection of extensions to Class::MethodMaker that were later folded into Class::MakeMethods:
+
+ 2000/01/12 Added set_foo, clear_foo to class_var hashes.
+ 1999/07/27 Added subclass_name.
+ 1999/04/15 Changed class_var to use symbol table lookups, not eval "".
+ 1999/04/05 Changed determine_once to check again if undefined.
+ 1999/03/25 Added singleton method.
+ 1998/09/18 Finished integration of class_registry handlers.
+ 1998/07/31 Added class_var and classnames handlers.
+ 1998/06/12 Added lookup handlers.
+ 1998/05/09 Created no_op and determine_once method groups.
+
+=cut
diff --git a/lib/Class/MakeMethods/Docs/Examples.pod b/lib/Class/MakeMethods/Docs/Examples.pod
new file mode 100644
index 0000000..787ace7
--- /dev/null
+++ b/lib/Class/MakeMethods/Docs/Examples.pod
@@ -0,0 +1,554 @@
+=head1 NAME
+
+Class::MakeMethods::Docs::Examples - Sample Declarations and Usage
+
+=head1 EXAMPLES
+
+The following examples indicate some of the capabilities of
+Class::MakeMethods.
+
+=head2 A Contrived Example
+
+Object-oriented Perl code is widespread -- you've probably seen code like the below a million times:
+
+ my $obj = MyStruct->new( foo=>"Foozle", bar=>"Bozzle" );
+ if ( $obj->foo() =~ /foo/i ) {
+ $obj->bar("Barbados!");
+ }
+
+Here's a possible implementation for the class whose interface is
+shown above:
+
+ package MyStruct;
+
+ sub new {
+ my $callee = shift;
+ my $self = bless { @_ }, (ref $callee || $callee);
+ return $self;
+ }
+
+ sub foo {
+ my $self = shift;
+ if ( scalar @_ ) {
+ $self->{'foo'} = shift();
+ } else {
+ $self->{'foo'}
+ }
+ }
+
+ sub bar {
+ my $self = shift;
+ if ( scalar @_ ) {
+ $self->{'bar'} = shift();
+ } else {
+ $self->{'bar'}
+ }
+ }
+
+Class::MakeMethods allows you to simply declare those methods to
+be of a predefined type, and it generates and installs the necessary
+methods in your package at compile-time.
+
+Here's the equivalent declaration for that same basic class:
+
+ package MyStruct;
+ use Class::MakeMethods::Standard::Hash (
+ 'new' => 'new',
+ 'scalar' => 'foo',
+ 'scalar' => 'bar',
+ );
+
+=head2 A Typical Example
+
+The following example shows a common case of constructing a class with several types of accessor methods
+
+ package MyObject;
+ use Class::MakeMethods::Standard::Hash (
+ new => 'new',
+ scalar => [ 'foo', 'bar' ],
+ array => 'my_list',
+ hash => 'my_index',
+ );
+
+This class now has a constructor named new, two scalar accessors named foo and bar, and a pair of reference accessors named my_list and my_index. Typical usage of the class might include calls like the following:
+
+ my $obj = MyObject->new( foo => 'Foozle' );
+ print $obj->foo();
+
+ $obj->bar('Barbados');
+ print $obj->bar();
+
+ $obj->my_list(0 => 'Foozle', 1 => 'Bang!');
+ print $obj->my_list(1);
+
+ $obj->my_index('broccoli' => 'Blah!', 'foo' => 'Fiddle');
+ print $obj->my_index('foo');
+
+=head2 Lvalue Accessors
+
+The Template subclasses support an optional "--lvalue" modifer that causes your accessors method to be marked as returning an lvalue which can be assigned to. (This feature is only available on Perl 5.6 or later.)
+
+ package MyStruct;
+ use Class::MakeMethods::Template::Hash (
+ 'new' => 'new',
+ 'scalar --get --lvalue' => 'foo',
+ 'array --get --lvalue' => 'bar',
+ );
+
+ $obj->foo = "Foozle";
+ print $obj->foo;
+
+ $obj->bar = ( 'baz', 'beep', 'boop' );
+ print $obj->bar->[1]; # beep
+
+=head2 String and Numeric Accessors
+
+In addition to the C<scalar> accessor supported by the C<Standard::*> classes, the Template subclasses also provide specialized accessors that can facilitate the use of specific types of data.
+
+For example, we could declare the following class to hold information
+about available Perl packages:
+
+ package MyVersionInfo;
+ use Class::MakeMethods::Template::Hash (
+ 'new' => 'new',
+ 'string' => 'package',
+ 'number' => 'version',
+ );
+
+ sub summary {
+ my $self = shift;
+ return $self->package() . " is at version " . $self->version()
+ }
+
+You could use this class as follows:
+
+ package main;
+ use MyVersionInfo;
+
+ my $obj = MyVersionInfo->new( package=>"Class::MakeMethods");
+ $obj->version( 2.0 );
+ print $obj->summary();
+
+These accessors will provide a bit of diagnostic type checking;
+an attempt to call C<$obj-E<gt>version("foo")> will cause your
+program to croak.
+
+
+=head2 String Concatenation Interface
+
+The following defines a get_concat method C<i>, and specifies
+a string to use when joining additional values when this method is
+called.
+
+ use Class::MakeMethods::Template::Hash
+ 'string' => [ '--get_concat', 'i', { join => ' - ' } ];
+
+(See L<Class::MakeMethods::Template::Generic> for information about the C<string> C<get_concat> interface.)
+
+
+=head2 Access Control Example
+
+The following defines a secret_password method, which will croak
+if it is called from outside of the declaring package.
+
+ use Class::MakeMethods::Composite::Hash
+ 'scalar' => [ 'secret_password' => { permit => 'pp' } ];
+
+(See L<Class::MakeMethods::Composite> for information
+about the C<permit> modifier.)
+
+For template classes, the same thing is accomplished with '--private':
+
+ use Class::MakeMethods::Template::Hash
+ 'scalar' => [ '--private', 'secret_password' ];
+
+(See L<Class::MakeMethods::Template::Universal> for information
+about the C<private> modifier.)
+
+
+=head2 Lazy-Init Interface
+
+Templapte scalar accessors declared with the "init_and_get" interface
+can be used for "memoization" or lazy-evaluation for object
+attributes. If the current accessor value is undefined, they will
+first call a user-provided init_* method and save its value.
+
+ package MyWidget;
+ use Class::MakeMethods::Template::Hash (
+ 'new --with_values' => [ 'new' ],
+ 'scalar --init_and_get' => [ 'foo', 'count', 'result' ],
+ );
+
+ sub init_foo {
+ return 'foofle';
+ }
+
+ sub init_count {
+ return '3';
+ }
+
+ sub init_result {
+ my $self = shift;
+ return $self->foo x $self->count;
+ }
+ ...
+
+ my $widget = MyWidget->new();
+ print $widget->result; # output: fooflefooflefoofle
+
+ # if values are predefined, the init methods are not used
+ my $other_widget = MyWidget->new( foo => 'bar', count => 2 );
+ print $widget->result; # output: barbar
+
+(See L<Class::MakeMethods::Template::Generic> for more information about
+C<init_and_get>. This interface is also supported by all of Generic's
+subclasses, so you can add lazy-init methods for global data, class
+data, array objects, etc. Unfortunately, to date it is only supported
+for scalar-value accessors...)
+
+
+=head2 Helper Methods
+
+Template methods often include similarly-named "helper" methods. For example, specifying the "--with_clear" interface for Template::*:scalar methods creates an extra method for each accessor x named clear_x.
+
+ package MyClass;
+ use Class::MakeMethods::Template::Hash('scalar --with_clear' => 'foo');
+
+ my $obj = MyClass->new;
+ $obj->foo(23);
+ $obj->clear_foo;
+ print $obj->foo();
+
+
+=head2 Reference Accessor and Helper Methods
+
+For references to arrays and hashes, the Template subclasses provide
+accessors with extra "helper methods" to facilitate method-based
+interaction.
+
+Here's a class whose instances each store a string and an array
+reference, along with a method to search the directories:
+
+ package MySearchPath;
+ use Class::MakeMethods::Template::Hash (
+ 'new' => 'new',
+ 'string' => 'name',
+ 'array' => 'directories',
+ );
+
+ sub search {
+ my $self = shift;
+ my $target = shift;
+ foreach my $dir ( $self->directories ) {
+ my $candidate = $dir . '/' . $target;
+ return $candidate if ( -e $candidate );
+ }
+ return;
+ }
+
+Note that the directories accessor returns the contents of the
+array when called in a list context, making it easier to loop over.
+
+And here's a sample usage:
+
+ package main;
+ use MySearchPath;
+
+ my $libs = MySearchPath->new( name=>"libs", directories=>['/usr/lib'] );
+ $libs->push_directories( '/usr/local/lib' );
+
+ print "Searching in " . $libs->count_directories() . "directories.\n";
+ foreach ( 'libtiff', 'libjpeg' ) {
+ my $file = $libs->search("$_.so");
+ print "Checking $_: " . ( $file || 'not found' ) . "\n";
+ }
+
+Note the use of the push_* and count_* "helper" accessor methods,
+which are defined by default for all 'Template::*:array' declarations.
+
+Consult L<Class::MakeMethods::Template::Generic> for more information about
+the available types of reference accessors, and the various methods
+they define.
+
+
+=head2 Object Accessors
+
+There's also a specialized accessor for object references:
+
+ package MyStruct;
+ use Class::MakeMethods::Template::Hash (
+ 'new' => 'new',
+ 'object' => [ 'widget' => {class=>'MyWidgetClass', delegate=>"twiddle"} ],
+ );
+
+(Note that the C<class> and C<delegate> values specified above are
+method parameters, which provide additional information about the
+C<widget> declaration; see L<"Standard Declaration Syntax"> for more information.)
+
+The above declaration creates methods equivalent to the following:
+
+ package MyStruct;
+
+ sub widget {
+ my $self = shift;
+ if ( scalar @_ ) {
+ if (ref $_[0] and UNIVERSAL::isa($_[0], 'MyWidgetClass')) {
+ $self->{widget} = shift;
+ } else {
+ $self->{widget} = MyWidgetClass->new(@_);
+ }
+ } else {
+ return $self->{widget};
+ }
+ }
+
+ sub clear_widget {
+ my $self = shift;
+ $self->{widget} = undef;
+ }
+
+ sub twiddle {
+ my $self = shift;
+ my $obj = $self->widget()
+ or Carp::croak("Can't forward twiddle because widget is empty");
+ $obj->twiddle(@_)
+ }
+
+
+=head2 Mixing Object and Global Methods
+
+Here's a package declaration using two of the included subclasses, C<Standard::Hash>, for creating and accessing hash-based objects, and C<Basic::Global>, for simple global-value accessors:
+
+ package MyQueueItem;
+
+ use Class::MakeMethods::Standard::Hash (
+ new => { name => 'new', defaults=>{ foo => 'Foozle' } },
+ scalar => [ 'foo', 'bar' ],
+ hash => 'history'
+ );
+
+ use Class::MakeMethods::Basic::Global (
+ scalar => 'Debug',
+ array => 'InQueue',
+ );
+
+ sub AddQueueItem {
+ my $class = shift;
+ my $instance = shift;
+ $instance->history('AddQueueItem' => time());
+ $class->InQueue([0, 0], $instance);
+ }
+
+ sub GetQueueItem {
+ my $class = shift;
+ $class->InQueue([0, 1], []) or $class->new
+ }
+
+=head2 Adding Custom Initialization to Constructors
+
+Frequently you'll want to provide some custom code to initialize new objects of your class. Most of the C<*:new> constructor methods provides a way to ensure that this code is consistently called every time a new instance is created.
+
+=over 4
+
+=item Composite::Hash:new { post_rules => [] }
+
+The Composite classes allow you to add pre- and post-operations to any method, so you can pass in a code-ref to be executed after the new() method.
+
+ package MyClass;
+
+ sub new_post_init {
+ my $self = ${(pop)->{result}}; # get result of original new()
+ length($self->foo) or $self->foo('FooBar'); # default value
+ warn "Initialized new object '$self'";
+ }
+
+ use Class::MakeMethods (
+ 'Composite::Hash:new' => [
+ 'new' => { post_rules=>[ \&new_post_init ] }
+ ],
+ 'Composite::Hash:scalar' => 'foo;,
+ );
+ ...
+ package main;
+ my $self = MyClass->new( foo => 'Foozle' )
+
+=item Template::Hash:new --and_then_init
+
+Use 'Template::Hash:new --and_then_init', which will first create the object and initialize it with the provided values, and then call an init() method on the new object before returning it.
+
+ package MyClass;
+ use Class::MakeMethods::Template::Hash (
+ 'new --and_then_init' => 'new'
+ 'string' => 'foo'
+ );
+ sub init {
+ my $self = shift;
+ length($self->foo) or $self->foo('FooBar'); # default value
+ warn "Initialized new object '$self'";
+ }
+ ...
+ package main;
+ my $self = MyClass->new( foo => 'Foozle' )
+
+=item Template::Hash:new --with_init
+
+If you don't want your constructor to use the default hash-of-method-names style of initialization, use 'Template::Hash:new --with_init', which will create an empty object, pass its arguments to the init() method on the new object, and then return it.
+
+ package MyClass;
+ use Class::MakeMethods::Template::Hash (
+ 'new --with_init' => 'new'
+ 'string' => 'foo'
+ );
+ sub init {
+ my $self = shift;
+ $self->foo( shift || 'FooBar' ); # init with arg or default
+ warn "Initialized new object '$self'";
+ }
+ ...
+ package main;
+ my $self = MyClass->new( 'Foozle' )
+
+=back
+
+Some additional notes about these constructors:
+
+=over 4
+
+=item *
+
+The C<Template::*:new> methods allow you to specify a name for your method other than C<init> by passing the C<init_method> parameter:
+
+ use Class::MakeMethods::Template::Hash (
+ 'new --and_then_init' => [
+ 'new' => { init_method => 'my_init' }
+ ],
+ );
+
+=item *
+
+If you know that you're not going to have a complex class hierarchy, you can reduce resource consumption a bit by changing the above declarations from "*::Hash" to "*::Array" so your objects end up as blessed arrays rather than blessed hashes.
+
+=back
+
+
+=head2 Changing Method Names
+
+The Template subclasses allow you to control the names assigned to
+the methods you generate by selecting from several naming interfaces.
+
+For example, the accessors declared above use a default, Perl-ish
+style interface, in which a single method can be called without an
+argument to retrieve the value, or with an argument to set it.
+However, you can also select a more Java-like syntax, with separate
+get* and set* methods, by including the '--java' template specification:
+
+ package MyStruct;
+ use Class::MakeMethods::Template::Hash (
+ 'new' => 'new',
+ 'scalar' => '--java Foo',
+ );
+
+(Note that the declaration of Foo could also have been written as
+C<'scalar --java' =E<gt> 'Foo'> or C<'scalar' =E<gt> ['--java',
+'Foo']>, or C<'scalar' =E<gt> [ 'foo' => { 'interface'=>'java' }
+], all of which are interpreted identically; see the
+L<Class::MakeMethods> section on "Argument Normalization" for
+details.)
+
+Usage of this accessor would then be as follows:
+
+ package main;
+ use MyStruct;
+
+ my $obj = MyStruct->new( setFoo => "Foozle" );
+ print $obj->getFoo();
+ $obj->setFoo("Bozzle");
+
+
+=head2 Selecting Specific Helper Methods
+
+You can use the ability to specify interfaces to select specific helper methods rather than getting the default collection.
+
+For example, let's say you wanted to use a Template::Hash:array, but you only wanted two methods to be installed in your class, a foo() accessor and a shift_foo() mutator. Any of the below combinations of syntax should do the trick:
+
+ use Class::MakeMethods::Template::Hash
+ 'array' => [
+ 'foo' => { interface=>{'foo'=>'get_set', 'shift_foo'=>'shift'} },
+ ];
+
+If you're going to have a lot of methods with the same interface, you could pre-declare a named interface once and use it repeatedly:
+
+ BEGIN {
+ require Class::MakeMethods::Template::Hash;
+ Class::MakeMethods::Template::Hash->named_method('array')->
+ {'interface'}->{'my_get_set_shift'} =
+ { '*'=>'get_set', 'shift_*'=>'shift' };
+ }
+
+ use Class::MakeMethods::Template::Hash
+ 'array --my_get_set_shift' => [ 'foo', 'bar' ];
+
+
+=head2 Tree Structure Example
+
+In this example we will create a pair of classes with references
+to other objects.
+
+The first class is a single-value data object implemented as a
+reference to a scalar.
+
+ package MyTreeData;
+ use Class::MakeMethods::Template::Scalar (
+ 'new' => 'new',
+ 'string' => 'value',
+ );
+
+The second class defines a node in a tree, with a constructor, an
+accessor for a data object from the class above, and accessors for
+a list of child nodes.
+
+ package MyTreeNode;
+ use Class::MakeMethods::Template::Hash (
+ 'new' => 'new',
+ 'object -class MyTreeData' => 'data',
+ 'array_of_objects -class MyTreeNode' => 'children',
+ );
+
+ sub depth_first_data {
+ my $self = shift;
+ return $self->data, map { $_->depth_first_data() } $self->children;
+ }
+
+Here's a sample of how the above classes could be used in a program.
+
+ package main;
+ use MyTreeData;
+ use MyTreeNode;
+
+ my $node = MyTreeNode->new(
+ data => { value=>'data1' },
+ children => [ { value=>'data3' } ]
+ );
+ $node->push_children( MyTreeNode->new( data => { value=>'data2' } ) );
+
+ foreach my $data ( $node->depth_first_data ) {
+ print $data->value();
+ }
+
+
+=head1 SEE ALSO
+
+See L<Class::MakeMethods> for general information about this distribution.
+
+=head2 Annotated Tutorials
+
+Ron Savage has posted a pair of annotated examples, linked to below.
+Each demonstrates building a class with MakeMethods, and each
+includes scads of comments that walk you through the logic and
+demonstrate how the various methods work together.
+
+ http://savage.net.au/Perl-tutorials.html
+ http://savage.net.au/Perl-tutorials/tut-33.tgz
+ http://savage.net.au/Perl-tutorials/tut-34.tgz
+
+=cut
diff --git a/lib/Class/MakeMethods/Docs/ReadMe.pod b/lib/Class/MakeMethods/Docs/ReadMe.pod
new file mode 100644
index 0000000..6fd7890
--- /dev/null
+++ b/lib/Class/MakeMethods/Docs/ReadMe.pod
@@ -0,0 +1,279 @@
+=head1 NAME
+
+Class::MakeMethods::Docs::ReadMe - About Class::MakeMethods
+
+
+=head1 DESCRIPTION
+
+This is an updated release of Class::MakeMethods, for distribution through
+CPAN.
+
+This distribution includes the Class::MakeMethods::Template and
+Class::MakeMethods::Emulator modules which were packaged sepearately in some
+previous releases.
+
+
+=head1 MOTIVATION
+
+By passing arguments to "use Class::MakeMethods ..." statements, you can
+select from a library of hundreds of common types of methods, which are
+dynamically installed as subroutines in your module, simplifying the code
+for your class.
+
+
+=head1 DISTRIBUTION AND INSTALLATION
+
+=head2 Version
+
+This is Class::MakeMethods v1.010, intended for general use.
+
+This module's CPAN registration should read:
+
+ Name DSLIP Description
+ -------------- ----- ---------------------------------------------
+ Class::
+ ::MakeMethods RdpOp Generate common types of methods
+
+=head2 Prerequisites
+
+In general, this module should work with Perl 5.003 or later,
+without requring any modules beyond the core Perl distribution.
+
+The following optional feature may not be available on some platforms:
+
+=over 4
+
+=item *
+
+Class::MakeMethods::Attribute: The C<:MakeMethod> subroutine
+attribute requires Perl version 5.6 and the Attribute::Handlers
+module (from CPAN).
+
+=item *
+
+Class::MakeMethods::Template C<--lvalue>: The lvalue modifier
+provided by the Template generator subclasses will only work on
+Perl version 5.6 or later.
+
+=item *
+
+Some third-party tests used to check the compliance of Emulator modules
+require Test::More and will be automatically skipped on machines which do
+not have this installed.
+
+=back
+
+=head2 Installation
+
+You should be able to install this module using the CPAN shell interface:
+
+ perl -MCPAN -e 'install Class::MakeMethods'
+
+Alternately, you may retrieve this package from CPAN or from the author's site:
+
+=over 2
+
+=item *
+
+http://search.cpan.org/~evo/
+
+=item *
+
+http://www.cpan.org/modules/by-authors/id/E/EV/EVO
+
+=item *
+
+http://www.evoscript.org/Class-MakeMethods/dist/
+
+=back
+
+After downloading the distribution, follow the normal procedure to unpack and install it, using the commands shown below or their local equivalents on your system:
+
+ tar xzf Class-MakeMethods-*.tar.gz
+ cd Class-MakeMethods-*
+ perl Makefile.PL
+ make test && sudo make install
+
+Thanks to the kind generosity of other members of the Perl community,
+this distribution is also available repackaged in the FreeBSD
+"ports" and Linux RPM formats. This may simplify installation for
+some users, but be aware that these alternate distributions may
+lag a few versions behind the latest release on CPAN.
+
+=over 2
+
+=item *
+
+http://www.freebsd.org/cgi/ports.cgi?query=Class-MakeMethods
+
+=item *
+
+http://www.rpmfind.net/linux/rpm2html/search.php?query=perl-Class-MakeMethods
+
+=back
+
+=head2 Tested Platforms
+
+This release has been tested succesfully on the following platforms:
+
+ 5.6.1 on darwin
+
+Earlier releases have also tested OK on the following platforms:
+
+ IP30-R12000-irix
+ OpenBSD.i386-openbsd
+ i386-freebsd / i386-freebsd-thread-multi
+ i386-linux
+ i386-netbsd / i386-netbsd-thread-multi
+ i586-linux / i586-linux-thread-multi-ld
+ i686-linux / i686-pld-linux-thread-multi
+ ia64-linux
+ ppc-linux
+ sparc-linux
+ sparc-netbsd
+ sun4-solaris
+
+Some earlier versions failed to "make test" on MSWin32, although
+a forced installation would still work; that problem should be
+fixed in the most recent releases.
+
+You may also review the current test results from CPAN-Testers:
+
+=over 2
+
+=item *
+
+http://testers.cpan.org/show/Class-MakeMethods.html
+
+=back
+
+=head1 SUPPORT
+
+=head2 Release Status
+
+This module has been used in a variety of production systems and
+has been available on CPAN for over two years, with several other
+distributions dependant on it, so it would be fair to say that it
+is fully released.
+
+However, while the commonly-used portions are well tested, some of
+the more obscure combinations of options are less so, and new bug
+reports do trickle in occasionally. If you do encounter any problems,
+please inform the author and I'll endeavor to patch them promptly.
+
+Additional features have been outlined for future development, but
+the intent is support these by adding more options to the declaration
+interface, while maintaining backward compatibility.
+
+See L<Class::MakeMethods::Docs::ToDo> for other outstanding issues
+and development plans.
+
+=head2 Support
+
+If you have questions or feedback about this module, please feel
+free to contact the author at the below address. Although there is
+no formal support program, I do attempt to answer email promptly.
+
+I would be particularly interested in any suggestions towards
+improving the documentation and correcting any Perl-version or platform
+dependencies, as well as general feedback and suggested additions.
+
+Bug reports that contain a failing test case are greatly appreciated,
+and suggested patches will be promptly considered for inclusion in
+future releases.
+
+To report bugs via the CPAN web tracking system, go to
+C<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Class-MakeMethods> or send mail
+to C<Dist=Class-MakeMethods#rt.cpan.org>, replacing C<#> with C<@>.
+
+=head2 Community
+
+If you've found this module useful or have feedback about your
+experience with it, consider sharing your opinion with other Perl
+users by posting your comment to CPAN's ratings system:
+
+=over 2
+
+=item *
+
+http://cpanratings.perl.org/rate/?distribution=Class-MakeMethods
+
+=back
+
+For more general discussion, you may wish to post a message on PerlMonks or the comp.lang.perl.misc newsgroup:
+
+=over 2
+
+=item *
+
+http://www.perlmonks.org/index.pl?node=Seekers%20of%20Perl%20Wisdom
+
+=item *
+
+http://groups.google.com/groups?group=comp.lang.perl.misc
+
+=back
+
+
+=head1 CREDITS AND COPYRIGHT
+
+=head2 Author
+
+Developed by Matthew Simon Cavalletto at Evolution Softworks.
+More free Perl software is available at C<www.evoscript.org>.
+
+You may contact the author directly at C<evo@cpan.org> or C<simonm@cavalletto.org>.
+
+=head2 Feedback and Suggestions
+
+Thanks to the following people for bug reports, suggestions, and other feedback:
+
+ Martyn J. Pearce
+ Scott R. Godin
+ Ron Savage
+ Jay Lawrence
+ Adam Spiers
+ Malcolm Cook
+ Terrence Brannon
+ Jared Rhine
+ Peter Chen
+ Mike Castle
+
+=head2 Source Material
+
+This package was inspired by the ground-breaking original closure-generating method maker module:
+
+ Class::MethodMaker, by Peter Seibel.
+
+Additional inspiration, cool tricks, and blocks of useful code for
+this module were extracted from the following CPAN modules:
+
+ Class::Accessor, by Michael G Schwern
+ Class::Contract, by Damian Conway
+ Class::SelfMethods, by Toby Everett
+
+=head2 Copyright
+
+Copyright 2002, 2003 Matthew Simon Cavalletto.
+
+Portions copyright 1998, 1999, 2000, 2001 Evolution Online Systems, Inc.
+
+Based on Class::MethodMaker, originally developed by Peter Seibel. Portions Copyright 1996 Organic Online. Portions Copyright 2000 Martyn J. Pearce.
+
+Class::MakeMethods::Emulator::accessors is based on accessors. Portions by Steve Purkis.
+
+Class::MakeMethods::Emulator::AccessorFast is based on Class::Accessor::Fast. Portions Copyright 2000 Michael G Schwern.
+
+Class::MakeMethods::Emulator::Inheritable is based on Class::Data::Inheritable. Portions Copyright 2000 Damian Conway and Michael G Schwern.
+
+Class::MakeMethods::Emulator::mcoder is based on mcoder. Portions Copyright 2003 by Salvador Fandiño.
+
+Class::MakeMethods::Emulator::Singleton is based on Class::Singleton, by Andy Wardley. Portions Copyright 1998 Canon Research Centre Europe Ltd.
+
+Class::MakeMethods::Utility::Ref is based on Ref.pm. Portions Copyright 1994 David Muir Sharnoff.
+
+=head2 License
+
+You may use, modify, and distribute this software under the same terms as Perl.
+
+=cut
diff --git a/lib/Class/MakeMethods/Docs/RelatedModules.pod b/lib/Class/MakeMethods/Docs/RelatedModules.pod
new file mode 100644
index 0000000..93ef930
--- /dev/null
+++ b/lib/Class/MakeMethods/Docs/RelatedModules.pod
@@ -0,0 +1,962 @@
+=head1 NAME
+
+Class::MakeMethods::Docs::RelatedModules - Survey of Class Builders
+
+
+=head1 SYNOPSIS
+
+ http://search.cpan.org/search?mode=module&query=Class
+
+
+=head1 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.
+
+
+=head2 Caution
+
+B<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.
+
+
+=head2 Points of Comparison
+
+In general, I compared the following characteristics:
+
+=over 4
+
+=item Distribution
+
+Is it included with Perl, or on CPAN? Is it being actively maintained?
+
+=item Usage
+
+How do you go about declaring your class's methods?
+
+=item Mechanism
+
+How are they generated and delivered?
+
+=item Instance type
+
+Are the objects of your class blessed hashes, or something else?
+
+=item Core Methods
+
+Does the module provide a constructor and basic accessors? Are there specialized methods for hash-ref, array-ref, and object-ref accessors?
+
+=item Extensible
+
+Can you subclass the package to create new types of methods, or is there some other way to extend it?
+
+=item Other Methods
+
+Other types of methods provided.
+
+=item Emulator
+
+Does Class::MakeMethods provide a drop-in replacement for this module?
+
+=item Comments
+
+Other characteristics or features of note.
+
+=back
+
+
+=head1 RELATED MODULES
+
+=head2 accessors
+
+=over 4
+
+=item Distribution
+
+CPAN. Uploaded Sep 2003.
+
+=item Comments
+
+I have not yet reviewed this module in detail.
+
+=item Example
+
+ package MyObject;
+ use accessors qw( foo bar baz );
+
+=back
+
+=head2 Attribute::Property
+
+=over 4
+
+=item Distribution
+
+CPAN.
+
+=item Comments
+
+I have not yet reviewed this module in detail.
+
+=back
+
+
+=head2 Class::Accessor
+
+=over 4
+
+=item Distribution
+
+CPAN. Last update 4/01.
+
+=item Usage
+
+Inherit and call function with declaration arguments
+
+=item Mechanism
+
+Generates and installs closures
+
+=item Instance Type
+
+Hash.
+
+=item Subclasses Cleanly
+
+Cleanly.
+
+=item Standard Methods
+
+Scalar accessors.
+
+=item Extensible
+
+Yes.
+
+=item Comments
+
+Accessor methods call overwritable C<self-E<lt>get(I<key>)> and
+C<self-E<lt>set(I<key>, I<value>)> methods.
+
+Also includes Class::Accessor::Fast, which creates direct hash keys accessors without calling get and set methods.
+
+=item Emulator
+
+Yes, but only for the Fast variation; see Class::MakeMethods::Emulator::AccessorFast.
+
+=item Example
+
+ package MyObject;
+ @ISA = qw(Class::Accessor);
+ MyObject->mk_accessors(qw( simple ordered mapping obj_ref ));
+
+=back
+
+
+=head2 Class::Class
+
+=over 4
+
+=item Distribution
+
+CPAN. Last update 1/00.
+
+=item Usage
+
+Inherit and fill %MEMBERS hash; methods created when first object is created
+
+=item Mechanism
+
+Generates and installs closures
+
+=item Instance Type
+
+Hash.
+
+=item Subclasses Cleanly
+
+Yes.
+
+=item Standard Methods
+
+Constructor and various accessors.
+
+=item Extensible
+
+No.
+
+=item Example
+
+Usage is similar to Class::Struct:
+
+ package MyObject;
+ use Class::Class;
+ @ISA = qw(Class::Class);
+ %MEMBERS = (
+ simple => '$',
+ ordered => '@',
+ mapping => '%',
+ obj_ref => 'FooObject'
+ );
+
+=item Other Method Types
+
+Provides a polymorph() method that is similar to Class::Method's "ClassName:class_name -require".
+
+=back
+
+
+=head2 Class::Constructor
+
+=over 4
+
+=item Distribution
+
+CPAN. Last update 11/01.
+
+=item Usage
+
+Inherit and call function with declaration arguments
+
+=item Mechanism
+
+Generates and installs closures
+
+=item Instance Type
+
+Hash.
+
+=item Subclasses Cleanly
+
+Cleanly.
+
+=item Standard Methods
+
+Hash constructor, with bells.
+
+=item Extensible
+
+No.
+
+=item Emulator
+
+No, but possible.
+
+=item Example
+
+ package MyObject;
+ @ISA = qw(Class::Constructor);
+ MyObject->mk_constructor( Name => 'new' );
+
+=back
+
+
+=head2 Class::Classgen
+
+=over 4
+
+=item Distribution
+
+CPAN. Last update 12/00.
+
+=item Usage
+
+Pre-processor run against declaration files.
+
+=item Mechanism
+
+Assembles and saves code file
+
+=item Instance Type
+
+Hash.
+
+=item Subclasses Cleanly
+
+Yes. (I think.)
+
+=item Standard Methods
+
+Constructor and various accessors.
+
+=item Extensible
+
+No. (I think.)
+
+=item Example
+
+ header:
+ package MyObject;
+ variables:
+ $simple
+ @ordered
+ %mapping
+ $obj_ref
+
+=back
+
+
+=head2 Class::Contract
+
+=over 4
+
+=item Distribution
+
+CPAN. Last update 5/01.
+
+=item Usage
+
+Call function with declaration arguments
+
+=item Mechanism
+
+Generates and installs closures
+
+=item Instance Type
+
+Scalar reference with external data storage.
+
+=item Subclasses Cleanly
+
+Yes.
+
+=item Standard Methods
+
+Constructor and various accessors.
+
+=item Extensible
+
+Yes. (I think.)
+
+=item Comments
+
+Supports pre- and post-conditions, class invariants, and other
+software engineering goodies.
+
+=item Example
+
+ package MyObject;
+ use Class::Contract;
+ contract {
+ ctor 'new';
+ attr 'simple' => SCALAR;
+ attr 'ordered' => ARRAY;
+ attr 'mapping' => HASH;
+ attr 'obj_ref' => 'FooObject';
+ }
+
+=back
+
+
+=head2 Class::Data::Inheritable
+
+=over 4
+
+=item Distribution
+
+CPAN. Last update 4/00.
+
+=item Usage
+
+Inherit and call function with declaration arguments
+
+=item Mechanism
+
+Generates and installs closures
+
+=item Instance Type
+
+Class data, with inheritance.
+
+=item Subclasses Cleanly
+
+Yes, specifically.
+
+=item Standard Methods
+
+Scalar accessors.
+
+=item Extensible
+
+No.
+
+=item Example
+
+Usage is similar to Class::Accessor:
+
+ package MyObject;
+ @ISA = qw(Class::Data::Inheritable);
+ MyObject->mk_classdata(qw( simple ordered mapping obj_ref ));
+
+=item Emulator
+
+Yes, Class::MakeMethods::Emulator::Inheritable, passes original test suite.
+
+=back
+
+
+=head2 Class::Delegate
+
+=over 4
+
+=item Distribution
+
+CPAN. Uploaded 12/0.
+
+=item Comments
+
+I have not yet reviewed this module in detail.
+
+=back
+
+=head2 Class::Delegation
+
+=over 4
+
+=item Distribution
+
+CPAN. Uploaded 12/01.
+
+=item Comments
+
+I have not yet reviewed this module in detail.
+
+=back
+
+=head2 Class::Generate
+
+=over 4
+
+=item Distribution
+
+CPAN. Last update 11/00.
+
+=item Usage
+
+Call function with declaration arguments
+
+=item Mechanism
+
+Assembles and evals code string, or saves code file.
+
+=item Instance Type
+
+Hash.
+
+=item Subclasses Cleanly
+
+Yes.
+
+=item Standard Methods
+
+Constructor and accessors (scalar, array, hash, object, object array, etc).
+
+=item Extensible
+
+Unknown.
+
+=item Comments
+
+Handles private/protected limitations, pre and post conditions,
+assertions, and more.
+
+=item Example
+
+Usage is similar to Class::Struct:
+
+ package MyObject;
+ use Class::Generate;
+ class MyObject => [
+ simple => '$',
+ ordered => '@',
+ mapping => '%',
+ obj_ref => 'FooObject'
+ ];
+
+=back
+
+=head2 Class::Hook
+
+=item Distribution
+
+CPAN. Uploaded 12/01.
+
+=item Comments
+
+I have not yet reviewed this module in detail.
+
+
+=head2 Class::Holon
+
+=over 4
+
+=item Distribution
+
+CPAN. Experimental/Alpha release 07/2001.
+
+=item Instance Type
+
+Hash, array, or flyweight-index.
+
+=item Subclasses Cleanly
+
+No. (I think.)
+
+=item Standard Methods
+
+Constructor and scalar accessors; flywieght objects also get scalar mutator methods.
+
+=item Extensible
+
+No. (I think.)
+
+=item Comments
+
+I'm not sure I understand the intent of this module; perhaps future versions will make this clearer....
+
+=back
+
+
+=head2 Class::MethodMaker
+
+=over 4
+
+=item Distribution
+
+CPAN. Last update 1/01.
+
+=item Usage
+
+Import, or call function, with declaration arguments
+
+=item Mechanism
+
+Generates and installs closures
+
+=item Instance Type
+
+Hash, Static.
+
+=item Subclasses Cleanly
+
+Yes.
+
+=item Standard Methods
+
+Constructor and various accessors.
+
+=item Extensible
+
+Yes.
+
+=item 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' ],
+ );
+
+=item Emulator
+
+Yes, Class::MakeMethods::Emulator::MethodMaker, passes original test suite.
+
+=back
+
+
+=head2 Class::MakeMethods
+
+=over 4
+
+=item Distribution
+
+CPAN.
+
+=item Usage
+
+Import, or call function, with declaration arguments; or if desired, make methods on-demand with Autoload, or declare subroutines with a special Attribute.
+
+=item Mechanism
+
+Generates and installs closures
+
+=item Instance Type
+
+Hash, Array, Scalar, Static, Class data, others.
+
+=item Subclasses Cleanly
+
+Yes.
+
+=item Standard Methods
+
+Constructor and various accessors.
+
+=item Extensible
+
+Yes.
+
+=item 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' } ],
+ );
+
+=back
+
+
+=head2 Class::Maker
+
+=over 4
+
+=item Distribution
+
+CPAN. Last update 7/02.
+
+=item Usage
+
+Call function with declaration arguments.
+
+=item Mechanism
+
+Generates and installs closures (I think).
+
+=item Instance Type
+
+Hash (I think).
+
+=item Subclasses Cleanly
+
+Unknown.
+
+=item Standard Methods
+
+Constructor and various scalar and reference accessors.
+
+=item Extensible
+
+Unknown.
+
+=item Comments
+
+I haven't yet reviewed this module closely.
+
+=back
+
+
+=head2 Class::SelfMethods
+
+=over 4
+
+=item Distribution
+
+CPAN. Last update 2/00.
+
+=item Usage
+
+Inherit; methods created via AUTOLOAD
+
+=item Mechanism
+
+Generates and installs closures (I think)
+
+=item Instance Type
+
+Hash.
+
+=item Subclasses Cleanly
+
+Yes.
+
+=item Standard Methods
+
+Constructor and scalar/code accessors (see Comments).
+
+=item Extensible
+
+No.
+
+=item 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.
+
+=back
+
+
+=head2 Class::Struct
+
+=over 4
+
+=item Distribution
+
+Included in the standard Perl distribution. Replaces Class::Template.
+
+=item Usage
+
+Call function with declaration arguments
+
+=item Mechanism
+
+Assembles and evals code string
+
+=item Instance Type
+
+Hash or Array
+
+=item Subclasses Cleanly
+
+No.
+
+=item Standard Methods
+
+Constructor and various accessors.
+
+=item Extensible
+
+No.
+
+ package MyObject;
+ use Class::Struct;
+ struct(
+ simple => '$',
+ ordered => '@',
+ mapping => '%',
+ obj_ref => 'FooObject'
+ );
+
+=item Emulator
+
+Yes, Class::MakeMethods::Emulator::Struct.
+
+=back
+
+
+=head2 Class::StructTemplate
+
+=over 4
+
+=item Distribution
+
+CPAN. Last update 12/00.
+
+No documentation available.
+
+=item Usage
+
+Unknown.
+
+=item Mechanism
+
+Unknown.
+
+=back
+
+
+=head2 Class::Template
+
+=over 4
+
+=item Distribution
+
+CPAN. Out of date.
+
+=item Usage
+
+Call function with declaration arguments (I think)
+
+=item Mechanism
+
+Assembles and evals code string (I think)
+
+=item Instance Type
+
+Hash.
+
+=item Subclasses Cleanly
+
+Yes. (I think.)
+
+=item Standard Methods
+
+Constructor and various accessors.
+
+=item Extensible
+
+No. (I think.)
+
+=item Example
+
+Usage is similar to Class::Struct:
+
+ package MyObject;
+ use Class::Template;
+ members MyObject {
+ simple => '$',
+ ordered => '@',
+ mapping => '%',
+ obj_ref => 'FooObject'
+ };
+
+=back
+
+
+=head2 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.
+
+=over 4
+
+=item Distribution
+
+CPAN. Last update 3/01.
+
+=item Extensible
+
+Unknown.
+
+=item Mechanism
+
+Uses Class::Data::Inheritable and installs additional closures.
+
+=back
+
+
+=head2 CodeGen::PerlBean
+
+=over 4
+
+=item Distribution
+
+CPAN.
+
+=item Usage
+
+Call function with declaration arguments.
+
+=item Mechanism
+
+Generates and writes source code to a file.
+
+=item Instance Type
+
+Hash (I think).
+
+=item Subclasses Cleanly
+
+Unknown.
+
+=item Standard Methods
+
+Constructor and various scalar and reference accessors.
+
+=item Extensible
+
+Unknown.
+
+=item Comments
+
+I haven't yet reviewed this module closely.
+
+=back
+
+
+=head2 HTML::Mason::MethodMaker
+
+=over 4
+
+=item Distribution
+
+CPAN.
+
+=item Usage
+
+Package import with declaration arguments
+
+=item Mechanism
+
+Generates and installs closures
+
+=item Instance Type
+
+Hash.
+
+=item Standard Methods
+
+Scalar accessors.
+
+=item Extensible
+
+No.
+
+=item Example
+
+ use HTML::Mason::MethodMaker (
+ read_write => [ qw( simple ordered mapping obj_ref ) ]
+ );
+
+=back
+
+
+=head1 TO DO
+
+The following modules are relevant but have not yet been cataloged above.
+
+=head2 Attribute::Property
+
+=head2 Class::Accessor::Chained
+
+=head2 Class::Accessor::Lvalue
+
+=head2 Class::Accessor::Ref
+
+=head2 Class::AutoClass
+
+=head2 Class::Builder
+
+=head2 Class::Member
+
+=head2 Class::Trigger
+
+
+=head1 SEE ALSO
+
+See L<Class::MakeMethods> for general information about this distribution.
+
+
+=head1 CREDITS AND COPYRIGHT
+
+=head2 Developed By
+
+ M. Simon Cavalletto, simonm@cavalletto.org
+ Evolution Softworks, www.evoscript.org
+
+=head2 Copyright
+
+Copyright 2002 Matthew Simon Cavalletto.
+
+Portions copyright 2000, 2001 Evolution Online Systems, Inc.
+
+=head2 License
+
+You may use, modify, and distribute this document under the same terms as Perl.
+
+=cut
diff --git a/lib/Class/MakeMethods/Docs/ToDo.pod b/lib/Class/MakeMethods/Docs/ToDo.pod
new file mode 100644
index 0000000..312bdc0
--- /dev/null
+++ b/lib/Class/MakeMethods/Docs/ToDo.pod
@@ -0,0 +1,296 @@
+=head1 NAME
+
+Class::MakeMethods::Docs::ToDo - Ideas, problems, and suggestions
+
+
+=head1 SYNOPSIS
+
+There are lots of things that could be done to improve this module.
+
+
+=head1 DISTRIBUTION ISSUES
+
+Issues about the distribution and supporting files, rather than the code:
+
+=head2 Documentation
+
+=over 4
+
+=item *
+
+Make sure that the documentation is broken up into appropriately-sized
+chunks, and that people will know which section to look at.
+
+=item *
+
+As user questions arrive, add the answers as documentation points or examples.
+
+=item *
+
+Assemble annotated examples and tutorials, and either link to or distribute them.
+
+=item *
+
+Finish overhauling Template documentation.
+
+=item *
+
+Include Global and InsideOut uses in the EXAMPLES section
+
+=item *
+
+Template Internals: Finish documenting disk-based meta-method code-caching.
+
+=back
+
+=head2 Tests
+
+=over 4
+
+=item *
+
+Use Devel::Coverage to measure test coverage, and fill in missing
+cases.
+
+=item *
+
+Finish tests for Standard and Composite modules.
+
+=back
+
+
+=head1 GENERAL ISSUES
+
+=over 4
+
+=item *
+
+It does not appear to be possible to assign subroutine names to
+closures within Perl. As a result, debugging output from Carp and
+similar sources will show all generated methods as "ANON()" rather
+than "YourClass::methodname()".
+
+UPDATE: There now seem to be fixes for this which should be integrated: See the new Sub::Name module and http://perlmonks.org/index.pl?node_id=304883
+
+=item *
+
+For scalar methods (and others) it would be nice to have a simple
+bounds-checking interface to approve or reject (with an exception)
+new values that were passed in.
+
+As pointed out by Terrence Brannon, the right interface to
+adopt is probably that of Attribute::Types:
+
+ use Class::MakeMethods::Standard::Hash (
+ 'scalar' => [ 'count' => { TYPE => 'INTEGER' } ],
+ 'scalar' => [ 'name' => { TYPE => qr/^[A-Z]\w*$/ } ],
+ 'scalar' => [ 'account' => { TYPE => &checksum_account_number } ]
+ );
+
+=item *
+
+Improve use of _diagnostic hooks for debugging. Add various "(Q)"
+debug diagnostics.
+
+=item *
+
+Finish building Inheritable array and object accessors.
+
+=item *
+
+Finish building Composite::* packages.
+
+=item *
+
+Resolve DESTROY-time issues with Standard::Inheritable, Composite::Inheritable, and Template::InsideOut.
+
+=item *
+
+Add slice and splice functionality to Standard::*:hash and Composite::*:hash.
+
+=back
+
+
+=head1 TEMPLATE CLASSES
+
+=head2 Template::Generic
+
+=over 4
+
+=item *
+
+Allow untyped object accesors if C<class> attribute is not set.
+(Suggested in Jan-01 NY Perl Seminar discussion.)
+
+=item *
+
+Standardize naming templates for array, hash, other method types.
+
+Deprecate verb_x methods? Or at last make them consistently available both ways.
+
+Make list methods consistent with hash_of_lists methods, in action, and
+in name (x_verb). Also for others (e.g., set_ clear_ boolean)
+
+=item *
+
+Should default object template provide auto-create behavior on ->get()?
+
+=item *
+
+Generalize the "Generic:scalar -init_and_get" interface to support
+memoizing values for other accessor types.
+
+=item *
+
+Consider adding hash each and array iterator methods, using a closure
+to provide iteration.
+
+=item *
+
+Add support for tied arrays & scalars, a la tiedhash
+
+=item *
+
+Add string_multiple_index.
+
+=item *
+
+Extend index methods to support weak indexes with WeakRef. Perhaps
+just have it accept a hash ref to use as the index, and then allow
+people to pass in tied hashes?
+
+=item *
+
+Maybe make private or protected method croak if they were called by a
+method_init method which was called by an outside package.
+
+Not entirely clear what the right semantics or security precautions are here...
+
+=back
+
+
+=head2 Template::Generic Subclasses
+
+=over 4
+
+=item *
+
+Finish building code_or_scalar meta-method.
+
+=item *
+
+Finish building Class::MakeMethods::ClassInherit subclass.
+
+Need to work out how to capture changes for non-scalar values. For
+example, if a subclass inherits an array accessor and then pops
+it, is there some way to provide them with copy-on-write?
+
+=item *
+
+Add enumerated string/number type.
+
+Provide helper methods with map of associated values (ex $o->port
+= 80 ... $o->port_readable eq 'HTTP' ). Cf. code for earlier
+unpublished 'lookup' method type.
+
+=item *
+
+For StructBuiltin:
+
+Add -fatal flag to die if core func returns false / undef
+Add call method to recall method with alternative arguments.
+Add -nocall flag to not call core func on new.
+
+=item *
+
+Replace ClassName:static_hash_classname with Class:indexed_string.
+
+=back
+
+
+=head2 Template Internals
+
+=over 4
+
+=item *
+
+Figure out which modules, if any, should actually be using AutoLoader.
+Probably just Template::Generic?
+
+=item *
+
+Give users a way to do meta-method code-caching in Perl library
+hierarchy, rather than in /tmp/auto or other user-specified
+directory..
+
+Provide mechanism for pre-generating these at install time.
+
+Perhaps load these via do, rather than open/read/eval?
+
+Perhaps pre-generate expanded libs with all of the -imports resolved?
+
+=item *
+
+Support generating code files and loading them as needed.
+
+This would be similar to Class::Classgen, except that we'd do the
+generation at run-time the first time it was required, rather than
+in a separate pass.
+
+For example, given the following declaration:
+
+ package Foo::Bar;
+ Class::MakeMethods::Template::Hash->import(-codecache=>'auto', scalar=>'foo');
+
+We should be able to write out the following file:
+
+ cat 'auto/Foo/Bar/methods-line-2.pl'
+ # NOTE: Generated for Foo::Bar by the Class::MakeMethods module.
+ # Changes made here will be lost when Foo::Bar is modified.
+ package Foo::Bar;
+ sub foo {
+ my $self = shift;
+ if ( scalar @_ ) {
+ $self->{'foo'} = shift();
+ }
+ $self->{'foo'}
+ }
+
+Then on subsequent uses, we can just re-load the generated code:
+
+ require "auto/Foo/Bar/methods-line-2.pl";
+
+To do this, we need to:
+
+=over 4
+
+=item *
+
+Provide an option to select this if desired; maybe ...
+import('-cache' => 'auto/', ...)?
+
+=item *
+
+Figure out which directory we can/should write into.
+
+=item *
+
+Re-evaluate the textual code templates, without generating the
+closures. Substitute in any _STATIC_ATTR_ values. Make other _ATTR_
+values point to some public lookup table or package scalar.
+
+=item *
+
+Notice if the source file (or Class::MakeMethods modules) has
+been updated more recently than the generated file.
+
+=back
+
+=back
+
+
+=head1 SEE ALSO
+
+See L<Class::MakeMethods> for general information about this distribution.
+
+=cut
diff --git a/lib/Class/MakeMethods/Emulator.pm b/lib/Class/MakeMethods/Emulator.pm
new file mode 100644
index 0000000..96786da
--- /dev/null
+++ b/lib/Class/MakeMethods/Emulator.pm
@@ -0,0 +1,165 @@
+package Class::MakeMethods::Emulator;
+
+$VERSION = 1.009;
+
+########################################################################
+### IMPORT BEHAVIOR: import(), _handle_namespace()
+########################################################################
+
+@EXPORT_OK = qw( namespace_capture namespace_release );
+sub import {
+
+ if ( scalar @_ == 2 and $_[1] eq '-isasubclass' ) {
+ splice @_, 1, 1;
+ my $target_class = ( caller )[0];
+ no strict;
+ push @{"$target_class\::ISA"}, $_[0];
+ }
+
+ if ( $_[0] eq __PACKAGE__ ) {
+ require Exporter and goto &Exporter::import # lazy Exporter
+ }
+}
+
+sub _handle_namespace {
+ my $class = shift;
+ my $emulation_target = shift;
+ my $firstarg = shift or return;
+ my $take = shift || '-take_namespace';
+ my $release = shift || '-release_namespace';
+
+ if ( $firstarg eq $take) {
+ Class::MakeMethods::Emulator::namespace_capture($class, $emulation_target);
+ return 1;
+ } elsif ( $firstarg eq $release) {
+ Class::MakeMethods::Emulator::namespace_release($class, $emulation_target);
+ return 1;
+ }
+}
+
+########################################################################
+### NAMESPACE MUNGING: _namespace_capture(), _namespace_release()
+########################################################################
+
+sub namespace_capture {
+ my $source_package = shift;
+ my $target_package = shift;
+
+ # warn "Mapping $source_package over $target_package \n";
+
+ my $source_file = "$source_package.pm";
+ $source_file =~ s{::}{/}g;
+
+ my $target_file = "$target_package.pm";
+ $target_file =~ s{::}{/}g;
+
+ my $temp_package = $source_package . '::Target::' . $target_package;
+ my $temp_file = "$temp_package.pm";
+ $temp_file =~ s{::}{/}g;
+
+ no strict;
+ unless ( ${$temp_package . "::TargetCaptured"} ++ ) {
+ *{$temp_package . "::"} = *{$target_package . "::"};
+ $::INC{$temp_file} = $::INC{$target_file};
+ }
+ *{$target_package . "::"} = *{$source_package . "::"};
+ $::INC{$target_file} = $::INC{$source_file}
+}
+
+sub namespace_release {
+ my $source_package = shift;
+ my $target_package = shift;
+
+ my $target_file = "$target_package.pm";
+ $target_file =~ s{::}{/}g;
+
+ my $temp_package = $source_package . '::Target::' . $target_package;
+ my $temp_file = "$temp_package.pm";
+ $temp_file =~ s{::}{/}g;
+
+ no strict;
+ unless ( ${"${temp_package}::TargetCaptured"} ) {
+ Carp::croak("Can't _namespace_release: -take_namespace not called yet.");
+ }
+ *{$target_package . "::"} = *{$temp_package. "::"};
+ $::INC{$target_file} = $::INC{$temp_file};
+}
+
+########################################################################
+
+1;
+
+__END__
+
+
+=head1 NAME
+
+Class::MakeMethods::Emulator - Demonstrate class-generator equivalency
+
+
+=head1 SYNOPSIS
+
+ # Equivalent to use Class::Singleton;
+ use Class::MakeMethods::Emulator::Singleton;
+
+ # Equivalent to use Class::Struct;
+ use Class::MakeMethods::Emulator::Struct;
+ struct ( ... );
+
+ # Equivalent to use Class::MethodMaker( ... );
+ use Class::MakeMethods::Emulator::MethodMaker( ... );
+
+ # Equivalent to use base 'Class::Inheritable';
+ use base 'Class::MakeMethods::Emulator::Inheritable';
+ MyClass->mk_classdata( ... );
+
+ # Equivalent to use base 'Class::AccessorFast';
+ use base 'Class::MakeMethods::Emulator::AccessorFast';
+ MyClass->mk_accessors(qw(this that whatever));
+
+ # Equivalent to use accessors( ... );
+ use Class::MakeMethods::Emulator::accessors( ... );
+
+ # Equivalent to use mcoder( ... );
+ use Class::MakeMethods::Emulator::mcoder( ... );
+
+
+=head1 DESCRIPTION
+
+In several cases, Class::MakeMethods provides functionality closely
+equivalent to that of an existing module, and it is simple to map
+the existing module's interface to that of Class::MakeMethods.
+
+Class::MakeMethods::Emulator provides emulators for Class::MethodMaker,
+Class::Accessor::Fast, Class::Data::Inheritable, Class::Singleton,
+Class::Struct, accessors, and mcoder, each of which passes the
+original module's test suite, usually requiring only the addition
+of a a single line to each test, activating the emulation module.
+
+Beyond demonstrating compatibility, these emulators also generally
+indicate the changes needed to switch to direct use of Class::MakeMethods
+functionality, illustrate commonalities between the various modules,
+and serve as a source for new ideas that can be integrated into
+Class::MakeMethods.
+
+
+=head1 SEE ALSO
+
+See L<Class::MakeMethods> for general information about this distribution.
+
+See L<Class::MakeMethods::Emulator::accessors>, and L<accessors> from CPAN.
+
+See L<Class::MakeMethods::Emulator::Struct>, and L<Class::Struct> from CPAN.
+
+See L<Class::MakeMethods::Emulator::AccessorFast>, and L<Class::Accessor::Fast> from CPAN.
+
+See L<Class::MakeMethods::Emulator::Inheritable>, and L<Class::Data::Inheritable> from CPAN.
+
+See L<Class::MakeMethods::Emulator::MethodMaker>, and L<Class::MethodMaker> from CPAN.
+
+See L<Class::MakeMethods::Emulator::Singleton>, and L<Class::Singleton> from CPAN.
+
+See L<Class::MakeMethods::Emulator::mcoder>, and L<mcoder> from CPAN.
+
+=cut
+
diff --git a/lib/Class/MakeMethods/Emulator/AccessorFast.pm b/lib/Class/MakeMethods/Emulator/AccessorFast.pm
new file mode 100644
index 0000000..0f47e04
--- /dev/null
+++ b/lib/Class/MakeMethods/Emulator/AccessorFast.pm
@@ -0,0 +1,102 @@
+package Class::MakeMethods::Emulator::AccessorFast;
+
+use strict;
+use Class::MakeMethods::Composite::Hash;
+use Class::MakeMethods::Emulator '-isasubclass';
+
+sub _emulator_target { 'Class::Accessor::Fast' }
+
+sub import {
+ my $class = shift;
+ $class->_handle_namespace( $class->_emulator_target, $_[0] ) and shift;
+}
+
+########################################################################
+
+sub mk_accessors {
+ Class::MakeMethods::Composite::Hash->make(
+ -TargetClass => (shift),
+ 'new' => { name => 'new', modifier => 'with_values' },
+ 'scalar' => [ map {
+ $_,
+ "_${_}_accessor", { 'hash_key' => $_ }
+ } @_ ],
+ );
+}
+
+sub mk_ro_accessors {
+ Class::MakeMethods::Composite::Hash->make(
+ -TargetClass => (shift),
+ 'new' => { name => 'new', modifier => 'with_values' },
+ 'scalar' => [ map {
+ $_, { permit => 'ro' },
+ "_${_}_accessor", { 'hash_key' => $_, permit => 'ro' }
+ } @_ ],
+ );
+}
+
+sub mk_wo_accessors {
+ Class::MakeMethods::Composite::Hash->make(
+ -TargetClass => (shift),
+ 'new' => { name => 'new', modifier => 'with_values' },
+ 'scalar' => [ map {
+ $_, { permit => 'wo' },
+ "_${_}_accessor", { 'hash_key' => $_, permit => 'wo' }
+ } @_ ],
+ );
+}
+
+########################################################################
+
+1;
+
+__END__
+
+
+=head1 NAME
+
+Class::MakeMethods::Emulator::AccessorFast - Emulate Class::Accessor::Fast
+
+
+=head1 SYNOPSIS
+
+ package Foo;
+
+ use base qw(Class::MakeMethods::Emulator::AccessorFast);
+ Foo->mk_accessors(qw(this that whatever));
+
+ # Meanwhile, in a nearby piece of code!
+ # Emulator::AccessorFast provides new().
+ my $foo = Foo->new;
+
+ my $whatever = $foo->whatever; # gets $foo->{whatever}
+ $foo->this('likmi'); # sets $foo->{this} = 'likmi'
+
+
+=head1 DESCRIPTION
+
+This module emulates the functionality of Class::Accessor::Fast, using Class::MakeMethods to generate similar methods.
+
+You may use it directly, as shown in the SYNOPSIS above,
+
+Furthermore, you may call C<use Class::MakeMethods::Emulator::AccessorFast
+'-take_namespace';> to alias the Class::Accessor::Fast namespace
+to this package, and subsequent calls to the original package will
+be transparently handled by this emulator. To remove the emulation
+aliasing, call C<use Class::MakeMethods::Emulator::AccessorFast
+'-release_namespace'>.
+
+B<Caution:> This affects B<all> subsequent uses of Class::Accessor::Fast
+in your program, including those in other modules, and might cause
+unexpected effects.
+
+
+=head1 SEE ALSO
+
+See L<Class::MakeMethods> for general information about this distribution.
+
+See L<Class::MakeMethods::Emulator> for more about this family of subclasses.
+
+See L<Class::Accessor::Fast> for documentation of the original module.
+
+=cut
diff --git a/lib/Class/MakeMethods/Emulator/Inheritable.pm b/lib/Class/MakeMethods/Emulator/Inheritable.pm
new file mode 100644
index 0000000..90b0a91
--- /dev/null
+++ b/lib/Class/MakeMethods/Emulator/Inheritable.pm
@@ -0,0 +1,162 @@
+package Class::MakeMethods::Emulator::Inheritable;
+
+use strict;
+
+use Class::MakeMethods::Template::ClassInherit;
+use Class::MakeMethods::Emulator qw( namespace_capture namespace_release );
+
+my $emulation_target = 'Class::Data::Inheritable';
+
+sub import {
+ my $mm_class = shift;
+ if ( scalar @_ and $_[0] =~ /^-take_namespace/ and shift) {
+ namespace_capture(__PACKAGE__, $emulation_target);
+ } elsif ( scalar @_ and $_[0] =~ /^-release_namespace/ and shift) {
+ namespace_release(__PACKAGE__, $emulation_target);
+ }
+ # The fallback should really be to NEXT::import.
+ $mm_class->SUPER::import( @_ );
+}
+
+########################################################################
+
+sub mk_classdata {
+ my $declaredclass = shift;
+ my $attribute = shift;
+ Class::MakeMethods::Template::ClassInherit->make(
+ -TargetClass => $declaredclass,
+ 'scalar' => [ -interface => { '*'=>'get_set', '_*_accessor'=>'get_set' },
+ $attribute ],
+ );
+ if ( scalar @_ ) {
+ $declaredclass->$attribute( @_ );
+ }
+}
+
+########################################################################
+
+1;
+
+__END__
+
+=head1 NAME
+
+Class::MakeMethods::Emulator::Inheritable - Emulate Class::Inheritable
+
+
+=head1 SYNOPSIS
+
+ package Stuff;
+ use base qw(Class::MakeMethods::Emulator::Inheritable);
+
+ # Set up DataFile as inheritable class data.
+ Stuff->mk_classdata('DataFile');
+
+ # Declare the location of the data file for this class.
+ Stuff->DataFile('/etc/stuff/data');
+
+
+=head1 DESCRIPTION
+
+This module is an adaptor that provides emulatation of Class::Data::Inheritable by invoking similiar functionality provided by Class::MakeMethods::ClassInherit.
+
+The public interface provided by Class::MakeMethods::Emulator::Inheritable is identical to that of Class::Data::Inheritable.
+
+Class::Data::Inheritable is for creating accessor/mutators to class
+data. That is, if you want to store something about your class as a
+whole (instead of about a single object). This data is then inherited
+by your subclasses and can be overriden.
+
+=head1 USAGE
+
+As specified by L<Class::Data::Inheritable>, clients should inherit from this module and then invoke the mk_classdata() method for each class method desired:
+
+ Class->mk_classdata($data_accessor_name);
+
+This is a class method used to declare new class data accessors. A
+new accessor will be created in the Class using the name from
+$data_accessor_name.
+
+ Class->mk_classdata($data_accessor_name, $initial_value);
+
+You may also pass a second argument to initialize the value.
+
+To facilitate overriding, mk_classdata creates an alias to the
+accessor, _field_accessor(). So Suitcase() would have an alias
+_Suitcase_accessor() that does the exact same thing as Suitcase().
+This is useful if you want to alter the behavior of a single accessor
+yet still get the benefits of inheritable class data. For example.
+
+ sub Suitcase {
+ my($self) = shift;
+ warn "Fashion tragedy" if @_ and $_[0] eq 'Plaid';
+
+ $self->_Suitcase_accessor(@_);
+ }
+
+
+=head1 COMPATIBILITY
+
+Note that the internal implementation of Class::MakeMethods::ClassInherit does not match that of Class::Data::Inheritable. In particular, Class::Data::Inheritable installs new methods in subclasses when they first initialize their value, while
+
+=head1 EXAMPLE
+
+The example provided by L<Class::Data::Inheritable> is equally applicable to this emulator.
+
+ package Pere::Ubu;
+ use base qw(Class::MakeMethods::Emulator::Inheritable);
+ Pere::Ubu->mk_classdata('Suitcase');
+
+will generate the method Suitcase() in the class Pere::Ubu.
+
+This new method can be used to get and set a piece of class data.
+
+ Pere::Ubu->Suitcase('Red');
+ $suitcase = Pere::Ubu->Suitcase;
+
+The interesting part happens when a class inherits from Pere::Ubu:
+
+ package Raygun;
+ use base qw(Pere::Ubu);
+
+ # Raygun's suitcase is Red.
+ $suitcase = Raygun->Suitcase;
+
+Raygun inherits its Suitcase class data from Pere::Ubu.
+
+Inheritance of class data works analgous to method inheritance. As
+long as Raygun does not "override" its inherited class data (by using
+Suitcase() to set a new value) it will continue to use whatever is set
+in Pere::Ubu and inherit further changes:
+
+ # Both Raygun's and Pere::Ubu's suitcases are now Blue
+ Pere::Ubu->Suitcase('Blue');
+
+However, should Raygun decide to set its own Suitcase() it has now
+"overridden" Pere::Ubu and is on its own, just like if it had
+overriden a method:
+
+ # Raygun has an orange suitcase, Pere::Ubu's is still Blue.
+ Raygun->Suitcase('Orange');
+
+Now that Raygun has overridden Pere::Ubu futher changes by Pere::Ubu
+no longer effect Raygun.
+
+ # Raygun still has an orange suitcase, but Pere::Ubu is using Samsonite.
+ Pere::Ubu->Suitcase('Samsonite');
+
+
+=head1 SEE ALSO
+
+See L<Class::MakeMethods> for general information about this distribution.
+
+See L<Class::MakeMethods::Emulator> for more about this family of subclasses.
+
+See L<Class::Data::Inheritable> for documentation of the original module.
+
+See L<perltootc> for a discussion of class data in Perl.
+
+See L<Class::MakeMethods::Standard::Inheritable> and L<Class::MakeMethods::Template::ClassInherit> for inheritable data methods.
+
+=cut
+
diff --git a/lib/Class/MakeMethods/Emulator/MethodMaker.pm b/lib/Class/MakeMethods/Emulator/MethodMaker.pm
new file mode 100644
index 0000000..4956ba3
--- /dev/null
+++ b/lib/Class/MakeMethods/Emulator/MethodMaker.pm
@@ -0,0 +1,676 @@
+package Class::MakeMethods::Emulator::MethodMaker;
+
+use Class::MakeMethods '-isasubclass';
+require Class::MakeMethods::Emulator;
+
+$VERSION = 1.03;
+
+use strict;
+
+=head1 NAME
+
+Class::MakeMethods::Emulator::MethodMaker - Emulate Class::MethodMaker
+
+
+=head1 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 / ];
+ );
+
+
+=head1 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.
+
+
+=head1 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
+C<Class::MakeMethods::Emulator::MethodMaker> in the place of
+C<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, C<'get_concat --noundef'>,
+which restores the earlier behavior.)
+
+
+=head1 USAGE
+
+There are several ways to call this emulation module:
+
+=over 4
+
+=item *
+
+Direct Access
+
+Replace occurances in your code of C<Class::MethodMaker> with C<Class::MakeMethods::Emulator::MethodMaker>.
+
+=item *
+
+Install Emulation
+
+If you C<use Class::MakeMethods::Emulator::MethodMaker '-take_namespace'>, the Class::MethodMaker namespace will be aliased to this package, and calls to the original package will be transparently handled by this emulator.
+
+To remove the emulation aliasing, call C<use Class::MakeMethods::Emulator::MethodMaker '-release_namespace'>.
+
+B<Note:> This affects B<all> subsequent uses of Class::MethodMaker in your program, including those in other modules, and might cause unexpected effects.
+
+=item *
+
+The -sugar Option
+
+Passing '-sugar' as the first argument in a use or import call will cause the 'methods' package to be declared as an alias to this one.
+
+This allows you to write declarations in the following manner.
+
+ use Class::MakeMethods::Emulator::MethodMaker '-sugar';
+
+ make methods
+ get_set => [ qw / foo bar baz / ],
+ list => [ qw / a b c / ];
+
+B<Note:> This feature is deprecated in Class::MethodMaker version 0.96 and later.
+
+=back
+
+=cut
+
+my $emulation_target = 'Class::MethodMaker';
+
+sub import {
+ my $mm_class = shift;
+
+ if ( scalar @_ and $_[0] =~ /^-take_namespace/ and shift ) {
+ Class::MakeMethods::Emulator::namespace_capture(__PACKAGE__, $emulation_target);
+ } elsif ( scalar @_ and $_[0] =~ /^-release_namespace/ and shift ) {
+ Class::MakeMethods::Emulator::namespace_release(__PACKAGE__, $emulation_target);
+ }
+
+ if ( scalar @_ and $_[0] eq '-sugar' and shift ) {
+ Class::MakeMethods::Emulator::namespace_capture(__PACKAGE__, "methods");
+ }
+
+ $mm_class->make( @_ ) if ( scalar @_ );
+}
+
+
+=head1 METHOD CATALOG
+
+B<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.
+
+
+=head1 CONSTRUCTOR METHODS
+
+=head2 new
+
+Equivalent to Class::MakeMethods 'Template::Hash:new --with_values'.
+
+=cut
+
+sub new { return 'Template::Hash:new --with_values' }
+
+
+=head2 new_with_init
+
+Equivalent to Class::MakeMethods 'Template::Hash:new --with_init'.
+
+=cut
+
+sub new_with_init { return 'Template::Hash:new --with_init' }
+
+
+=head2 new_hash_init
+
+Equivalent to Class::MakeMethods 'Template::Hash:new --instance_with_methods'.
+
+=cut
+
+sub new_hash_init { return 'Template::Hash:new --instance_with_methods' }
+
+
+=head2 new_with_args
+
+Equivalent to Class::MakeMethods 'Template::Hash:new --with_values'.
+
+=cut
+
+sub new_with_args { return 'Template::Hash:new --with_values' }
+
+
+=head2 copy
+
+Equivalent to Class::MakeMethods 'Template::Hash:new --copy_with_values'.
+
+=cut
+
+sub copy { return 'Template::Hash:new --copy_with_values' }
+
+
+=head1 SCALAR ACCESSORS
+
+=head2 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.
+
+=cut
+
+my $scalar_interface = { '*'=>'get_set', 'clear_*'=>'clear' };
+
+sub get_set {
+ shift and return [
+ ( ( $_[0] and $_[0] eq '-static' and shift ) ? 'Template::Static:scalar'
+ : 'Template::Hash:scalar' ),
+ '-interface' => $scalar_interface,
+ map {
+ ( ref($_) eq 'ARRAY' )
+ ? ( '-interface'=>{
+ ( $_->[0] ? ( $_->[0] => 'get_set' ) : () ),
+ ( $_->[1] ? ( $_->[1] => 'clear' ) : () ),
+ ( $_->[2] ? ( $_->[2] => 'get' ) : () ),
+ ( $_->[3] ? ( $_->[3] => 'set_return' ) : () ),
+ } )
+ : ($_ eq '-compatibility')
+ ? ( '-interface', $scalar_interface )
+ : ($_ eq '-noclear')
+ ? ( '-interface', 'default' )
+ : ( /^-/ ? "-$_" : $_ )
+ } @_
+ ]
+}
+
+
+=head2 get_concat
+
+Equivalent to Class::MakeMethods 'Template::Hash:string' with a special interface declaration that provides the get_concat and clear behaviors.
+
+=cut
+
+my $get_concat_interface = {
+ '*'=>'get_concat', 'clear_*'=>'clear',
+ '-params'=>{ 'join' => '', 'return_value_undefined' => undef() }
+};
+
+my $old_get_concat_interface = {
+ '*'=>'get_concat', 'clear_*'=>'clear',
+ '-params'=>{ 'join' => '', 'return_value_undefined' => '' }
+};
+
+sub get_concat {
+ shift and return [ 'Template::Hash:string', '-interface',
+ ( $_[0] eq '--noundef' ? ( shift and $old_get_concat_interface )
+ : $get_concat_interface ), @_ ]
+}
+
+=head2 counter
+
+Equivalent to Class::MakeMethods 'Template::Hash:number --counter'.
+
+=cut
+
+sub counter { return 'Template::Hash:number --counter' }
+
+
+=head1 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.
+
+=cut
+
+my $object_interface = { '*'=>'get_set_init', 'delete_*'=>'clear' };
+
+sub object {
+ shift and return [
+ 'Template::Hash:object',
+ '-interface' => $object_interface,
+ _object_args(@_)
+ ]
+}
+
+sub _object_args {
+ my @meta_methods;
+ ! (@_ % 2) or Carp::croak("Odd number of arguments for object declaration");
+ while ( scalar @_ ) {
+ my ($class, $list) = (shift(), shift());
+ push @meta_methods, map {
+ (! ref $_) ? { name=> $_, class=>$class }
+ : { name=> $_->{'slot'}, class=>$class,
+ delegate=>( $_->{'forward'} || $_->{'comp_mthds'} ) }
+ } ( ( ref($list) eq 'ARRAY' ) ? @$list : ($list) );
+ }
+ return @meta_methods;
+}
+
+
+=head2 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.
+
+=cut
+
+my $array_interface = {
+ '*'=>'get_push',
+ '*_set'=>'set_items', 'set_*'=>'set_items',
+ map( ('*_'.$_ => $_, $_.'_*' => $_ ),
+ qw( pop push unshift shift splice clear count ref index )),
+};
+
+sub object_list {
+ shift and return [
+ 'Template::Hash:array_of_objects',
+ '-interface' => $array_interface,
+ _object_args(@_)
+ ];
+}
+
+=head2 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 C<method1> will be handled by component C<comp>, whilst method
+C<method2> will be handled by component C<comp2>.
+
+=cut
+
+sub forward {
+ my $class = shift;
+ my @results;
+ while ( scalar @_ ) {
+ my ($comp, $method) = ( shift, shift );
+ push @results, { name=> $method, target=> $comp };
+ }
+ [ 'forward_methods', @results ]
+}
+
+
+
+=head1 REFERENCE ACCESSORS
+
+=head2 list
+
+Equivalent to Class::MakeMethods 'Template::Hash:array' with a custom method naming interface.
+
+=cut
+
+sub list {
+ shift and return [ 'Template::Hash:array', '-interface' => $array_interface, @_ ];
+}
+
+
+=head2 hash
+
+Equivalent to Class::MakeMethods 'Template::Hash:hash' with a custom method naming interface.
+
+=cut
+
+my $hash_interface = {
+ '*'=>'get_push',
+ '*s'=>'get_push',
+ 'add_*'=>'get_set_items',
+ 'add_*s'=>'get_set_items',
+ 'clear_*'=>'delete',
+ 'clear_*s'=>'delete',
+ map {'*_'.$_ => $_} qw(push set keys values exists delete tally clear),
+};
+
+sub hash {
+ shift and return [ 'Template::Hash:hash', '-interface' => $hash_interface, @_ ];
+}
+
+
+=head2 tie_hash
+
+Equivalent to Class::MakeMethods 'Template::Hash:tiedhash' with a custom method naming interface.
+
+=cut
+
+sub tie_hash {
+ shift and return [ 'Template::Hash:tiedhash', '-interface' => $hash_interface, @_ ];
+}
+
+=head2 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'.
+
+=cut
+
+sub hash_of_lists {
+ shift and return ( $_[0] and $_[0] eq '-static' and shift )
+ ? [ 'Template::Static:hash_of_arrays', @_ ]
+ : [ 'Template::Hash:hash_of_arrays', @_ ]
+}
+
+
+=head1 STATIC ACCESSORS
+
+=head2 static_get_set
+
+Equivalent to Class::MakeMethods 'Template::Static:scalar' with a custom method naming interface.
+
+=cut
+
+sub static_get_set {
+ shift and return [ 'Template::Static:scalar', '-interface', $scalar_interface, @_ ]
+}
+
+=head2 static_list
+
+Equivalent to Class::MakeMethods 'Template::Static:array' with a custom method naming interface.
+
+=cut
+
+sub static_list {
+ shift and return [ 'Template::Static:array', '-interface' => $array_interface, @_ ];
+}
+
+=head2 static_hash
+
+Equivalent to Class::MakeMethods 'Template::Static:hash' with a custom method naming interface.
+
+=cut
+
+sub static_hash {
+ shift and return [ 'Template::Static:hash', '-interface' => $hash_interface, @_ ];
+}
+
+
+=head1 GROUPED ACCESSORS
+
+=head2 boolean
+
+Equivalent to Class::MakeMethods 'Template::Static:bits' with a custom method naming interface.
+
+=cut
+
+my $bits_interface = {
+ '*'=>'get_set', 'set_*'=>'set_true', 'clear_*'=>'set_false',
+ 'bit_fields'=>'bit_names', 'bits'=>'bit_string', 'bit_dump'=>'bit_hash'
+};
+
+sub boolean {
+ shift and return [ 'Template::Hash:bits', '-interface' => $bits_interface, @_ ];
+}
+
+
+=head2 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.
+
+=cut
+
+sub grouped_fields {
+ my ($class, %args) = @_;
+ my @methods;
+ foreach (keys %args) {
+ my @slots = @{ $args{$_} };
+ push @methods,
+ $_, sub { @slots },
+ $class->make( 'get_set', \@slots );
+ }
+ return @methods;
+}
+
+=head2 struct
+
+Equivalent to Class::MakeMethods 'Template::Hash::struct'.
+
+B<Note:> This feature is included but not documented in Class::MethodMaker version 1.
+
+
+=cut
+
+sub struct { return 'Template::Hash:struct' }
+
+
+=head1 INDEXED ACCESSORS
+
+=head2 listed_attrib
+
+Equivalent to Class::MakeMethods 'Template::Flyweight:boolean_index' with a custom method naming interface.
+
+=cut
+
+sub listed_attrib {
+ shift and return [ 'Template::Flyweight:boolean_index', '-interface' => {
+ '*'=>'get_set', 'set_*'=>'set_true', 'clear_*'=>'set_false',
+ '*_objects'=>'find_true', }, @_ ]
+}
+
+
+=head2 key_attrib
+
+Equivalent to Class::MakeMethods 'Template::Hash:string_index'.
+
+=cut
+
+sub key_attrib { return 'Template::Hash:string_index' }
+
+=head2 key_with_create
+
+Equivalent to Class::MakeMethods 'Template::Hash:string_index --find_or_new'.
+
+=cut
+
+sub key_with_create { return 'Template::Hash:string_index --find_or_new'}
+
+
+=head1 CODE ACCESSORS
+
+=head2 code
+
+Equivalent to Class::MakeMethods 'Template::Hash:code'.
+
+=cut
+
+sub code { return 'Template::Hash:code' }
+
+
+=head2 method
+
+Equivalent to Class::MakeMethods 'Template::Hash:code --method'.
+
+=cut
+
+sub method { return 'Template::Hash:code --method' }
+
+
+=head2 abstract
+
+Equivalent to Class::MakeMethods 'Template::Universal:croak --abstract'.
+
+=cut
+
+sub abstract { return 'Template::Universal:croak --abstract' }
+
+
+=head1 ARRAY CONSTRUCTOR AND ACCESSORS
+
+=head2 builtin_class (EXPERIMENTAL)
+
+Equivalent to Class::MakeMethods 'Template::StructBuiltin:builtin_isa' with a modified argument order.
+
+=cut
+
+sub builtin_class {
+ shift and return [ 'Template::StructBuiltin:builtin_isa',
+ '-new_function'=>(shift), @{(shift)} ]
+}
+
+=head1 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 C<use> or C<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 C<counter> is an alias for C<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 C<forward>, C<object>, and C<object_list> method types, marked "(with modified arguments)" below, require their arguments to be specified differently.
+
+See L<Class::MakeMethods::Template::Generic> for more information about the default interfaces of these method types.
+
+
+=head2 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'
+
+=head2 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)
+
+=head2 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'
+
+=head2 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'
+
+=head2 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)
+
+
+=head1 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.
+
+=over 4
+
+=item *
+
+install_methods - now simply return the desired methods
+
+=item *
+
+find_target_class - now passed in as the target_class attribute
+
+=item *
+
+ima_method_maker - no longer supported; use target_class instead
+
+=back
+
+=cut
+
+sub find_target_class { (shift)->_context('TargetClass') }
+sub get_target_class { (shift)->_context('TargetClass') }
+sub install_methods { (shift)->_install_methods(@_) }
+sub ima_method_maker { 1 }
+
+
+=head1 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.
+
+
+=head1 SEE ALSO
+
+See L<Class::MakeMethods> for general information about this distribution.
+
+See L<Class::MakeMethods::Emulator> for more about this family of subclasses.
+
+See L<Class::MethodMaker> for more information about the original module.
+
+A good introduction to Class::MethodMaker is provided by pages 222-234 of I<Object Oriented Perl>, by Damian Conway (Manning, 1999).
+
+ http://www.browsebooks.com/Conway/
+
+=cut
+
+1;
diff --git a/lib/Class/MakeMethods/Emulator/Singleton.pm b/lib/Class/MakeMethods/Emulator/Singleton.pm
new file mode 100644
index 0000000..c47ad9e
--- /dev/null
+++ b/lib/Class/MakeMethods/Emulator/Singleton.pm
@@ -0,0 +1,85 @@
+package Class::MakeMethods::Emulator::Singleton;
+
+use strict;
+require Class::MakeMethods::Emulator;
+
+my $emulation_target = 'Class::Singleton';
+
+sub import {
+ my $mm_class = shift;
+ if ( scalar @_ and $_[0] =~ /^-take_namespace/ and shift) {
+ Class::MakeMethods::Emulator::namespace_capture(__PACKAGE__, $emulation_target);
+ } elsif ( scalar @_ and $_[0] =~ /^-release_namespace/ and shift) {
+ Class::MakeMethods::Emulator::namespace_release(__PACKAGE__, $emulation_target);
+ }
+ # The fallback should really be to NEXT::import.
+ $mm_class->SUPER::import( @_ );
+}
+
+########################################################################
+
+use Class::MakeMethods (
+ 'Template::Hash:new --with_values' => '_new_instance',
+ 'Template::ClassVar:instance --get_init' => [ 'instance',
+ {new_method=>'_new_instance', variable=>'_instance'} ]
+);
+
+########################################################################
+
+1;
+
+__END__
+
+=head1 NAME
+
+Class::MakeMethods::Emulator::Singleton - Emulate Class::Singleton
+
+
+=head1 SYNOPSIS
+
+ use Class::MakeMethods::Emulator::Singleton;
+
+ # returns a new instance
+ my $one = Class::MakeMethods::Emulator::Singleton->instance();
+
+ # returns same instance
+ my $two = Class::MakeMethods::Emulator::Singleton->instance();
+
+
+=head1 COMPATIBILITY
+
+This module emulates the functionality of Class::Singleton, using Class::MakeMethods to generate similar methods.
+
+You may use it directly, as shown in the SYNOPSIS above,
+
+Furthermore, you may call C<use Class::MakeMethods::Emulator::Singleton '-take_namespace';> to alias the Class::Singleton namespace to this package, and subsequent calls to the original package will be transparently handled by this emulator. To remove the emulation aliasing, call C<use Class::MakeMethods::Emulator::Singleton '-release_namespace'>.
+
+B<Caution:> This affects B<all> subsequent uses of Class::Singleton in your program, including those in other modules, and might cause unexpected effects.
+
+
+=head1 DESCRIPTION
+
+A Singleton describes an object class that can have only one instance
+in any system. An example of a Singleton might be a print spooler
+or system registry. This module implements a Singleton class from
+which other classes can be derived. By itself, the Class::Singleton
+module does very little other than manage the instantiation of a
+single object. In deriving a class from Class::Singleton, your
+module will inherit the Singleton instantiation method and can
+implement whatever specific functionality is required.
+
+
+=head1 SEE ALSO
+
+See L<Class::MakeMethods> for general information about this distribution.
+
+See L<Class::MakeMethods::Emulator> for more about this family of subclasses.
+
+See L<Class::Singleton> for documentation of the original module.
+
+For a description and discussion of the Singleton class, see
+"Design Patterns", Gamma et al, Addison-Wesley, 1995, ISBN 0-201-63361-2.
+
+See L<Class::MakeMethods::Hash/new> and L<Class::MakeMethods::ClassVar/instance> for documentation of the created methods.
+
+=cut
diff --git a/lib/Class/MakeMethods/Emulator/Struct.pm b/lib/Class/MakeMethods/Emulator/Struct.pm
new file mode 100644
index 0000000..4dad355
--- /dev/null
+++ b/lib/Class/MakeMethods/Emulator/Struct.pm
@@ -0,0 +1,154 @@
+package Class::MakeMethods::Emulator::Struct;
+
+use strict;
+
+use Class::MakeMethods;
+
+use vars qw(@ISA @EXPORT);
+require Exporter;
+push @ISA, qw(Exporter);
+@EXPORT = qw(struct);
+
+sub import {
+ my $self = shift;
+
+ if ( @_ == 0 ) {
+ $self->export_to_level( 1, $self, @EXPORT );
+ } elsif ( @_ == 1 ) {
+ $self->export_to_level( 1, $self, @_ );
+ } else {
+ &struct;
+ }
+}
+
+########################################################################
+
+my %type_map = (
+ '$' => 'scalar',
+ '@' => 'array',
+ '%' => 'hash',
+ '_' => 'object',
+);
+
+sub struct {
+ my ($class, @decls);
+ my $base_type = ref $_[1] ;
+ if ( $base_type eq 'HASH' ) {
+ $base_type = 'Standard::Hash';
+ $class = shift;
+ @decls = %{shift()};
+ _usage_error() if @_;
+ }
+ elsif ( $base_type eq 'ARRAY' ) {
+ $base_type = 'Standard::Array';
+ $class = shift;
+ @decls = @{shift()};
+ _usage_error() if @_;
+ }
+ else {
+ $base_type = 'Standard::Array';
+ $class = (caller())[0];
+ @decls = @_;
+ }
+ _usage_error() if @decls % 2 == 1;
+
+ my @rewrite;
+ while ( scalar @decls ) {
+ my ($name, $type) = splice(@decls, 0, 2);
+ push @rewrite, $type_map{$type}
+ ? ( $type_map{$type} => { 'name'=>$name, auto_init=>1 } )
+ : ( $type_map{'_'} => { 'name'=>$name, 'class'=>$type, auto_init=>1 } );
+ }
+ Class::MakeMethods->make(
+ -TargetClass => $class,
+ -MakerClass => $base_type,
+ "new" => 'new',
+ @rewrite
+ );
+}
+
+sub _usage_error {
+ require Carp;
+ Carp::confess "struct usage error";
+}
+
+########################################################################
+
+1;
+
+__END__
+
+=head1 NAME
+
+Class::MakeMethods::Emulator::Struct - Emulate Class::Struct
+
+
+=head1 SYNOPSIS
+
+ use Class::MakeMethods::Emulator::Struct;
+
+ struct (
+ simple => '$',
+ ordered => '@',
+ mapping => '%',
+ obj_ref => 'FooObject'
+ );
+
+
+=head1 DESCRIPTION
+
+This module emulates the functionality of Class::Struct by munging the provided field-declaration arguments to match those expected by Class::MakeMethods.
+
+It supports the same four types of accessors, the choice of array-based or hash-based objects, and the choice of installing methods in the current package or a specified target.
+
+
+=head1 EXAMPLE
+
+The below three declarations create equivalent methods for a simple hash-based class with a constructor and four accessors.
+
+ use Class::Struct;
+ struct (
+ simple => '$',
+ ordered => '@',
+ mapping => '%',
+ obj_ref => 'FooObject'
+ );
+
+ use Class::MakeMethods::Emulator::Struct;
+ struct (
+ simple => '$',
+ ordered => '@',
+ mapping => '%',
+ obj_ref => 'FooObject'
+ );
+
+ use Class::MakeMethods (
+ -MakerClass => 'Standard::Array',
+ 'new' => 'new',
+ 'scalar' => 'simple',
+ 'array -auto_init 1' => 'ordered',
+ 'hash -auto_init 1' => 'mapping',
+ 'object -auto_init 1' => '-class FooObject obj_ref'
+ );
+
+=head1 COMPATIBILITY
+
+This module aims to offer a "95% compatible" drop-in replacement for the core Class::Struct module for purposes of comparison and code migration.
+
+The C<class-struct.t> test for the core Class::Struct module is included with this package. The test is unchanged except for the a direct substitution of this emulator's name in the place of the core module.
+
+However, there are numerous internal differences between the methods generated by the original Class::Struct and this emulator, and some existing code may not work correctly without modification.
+
+
+=head1 SEE ALSO
+
+See L<Class::MakeMethods> for general information about this distribution.
+
+See L<Class::MakeMethods::Emulator> for more about this family of subclasses.
+
+See L<Class::Struct> for documentation of the original module.
+
+See L<Class::MakeMethods::Standard::Hash> and L<Class::MakeMethods::Standard::Array> for documentation of the created methods.
+
+=cut
+
diff --git a/lib/Class/MakeMethods/Emulator/accessors.pm b/lib/Class/MakeMethods/Emulator/accessors.pm
new file mode 100644
index 0000000..69c3bb8
--- /dev/null
+++ b/lib/Class/MakeMethods/Emulator/accessors.pm
@@ -0,0 +1,122 @@
+package Class::MakeMethods::Emulator::accessors;
+
+$VERSION = '0.02';
+
+use Class::MakeMethods::Emulator '-isasubclass';
+use Class::MakeMethods::Template::Hash '-isasubclass';
+
+sub _emulator_target { 'accessors' }
+sub _accessor_type { 'scalar --get_set_chain' }
+
+sub import {
+ my $class = shift;
+
+ $class->_handle_namespace( $class->_emulator_target, $_[0] ) and shift;
+
+ foreach ( @_ ) {
+ die "invalid accessor - $_" unless ( /\A[a-z]\w+\z/i and
+ $_ ne 'DESTROY' and $_ ne 'AUTOLOAD' )
+ }
+
+ $class->make($class->_accessor_type => [@_]);
+}
+
+########################################################################
+
+package Class::MakeMethods::Emulator::accessors::chained;
+@ISA = 'Class::MakeMethods::Emulator::accessors';
+$INC{'Class/MakeMethods/Emulator/accessors/chained.pm'} =
+ $INC{'Class/MakeMethods/Emulator/accessors.pm'};
+
+sub _emulator_target { 'accessors::chained' }
+sub _accessor_type { 'scalar --get_set_chain' }
+
+########################################################################
+
+package Class::MakeMethods::Emulator::accessors::classic;
+@ISA = 'Class::MakeMethods::Emulator::accessors';
+$INC{'Class/MakeMethods/Emulator/accessors/classic.pm'} =
+ $INC{'Class/MakeMethods/Emulator/accessors.pm'};
+
+sub _emulator_target { 'accessors::classic' }
+sub _accessor_type { 'scalar' }
+
+########################################################################
+
+1;
+
+__END__
+
+
+=head1 NAME
+
+Class::MakeMethods::Emulator::accessors - Emulate the accessors module
+
+
+=head1 SYNOPSIS
+
+ package Foo;
+ use Class::MakeMethods::Emulator::accessors qw( foo bar baz );
+
+ my $obj = bless {}, 'Foo';
+
+ # generates chaining accessors:
+ $obj->foo( 'hello ' )
+ ->bar( 'world' )
+ ->baz( "!\n" );
+
+ print $obj->foo, $obj->bar, $obj->baz;
+
+This module also defines subpackages for the classic and chaining subclasses:
+
+ package Bar;
+ use Class::MakeMethods::Emulator::accessors;
+ use Class::MakeMethods::Emulator::accessors::classic qw( foo bar baz );
+
+ my $obj = bless {}, 'Bar';
+
+ # always return the current value, even on set:
+ $obj->foo( 'hello ' ) if $obj->bar( 'world' );
+
+ print $obj->foo, $obj->bar, $obj->baz( "!\n" );
+
+
+=head1 DESCRIPTION
+
+This module emulates the functionality of the accessors module, using
+Class::MakeMethods to generate similar methods.
+
+In particular, the following lines are equivalent:
+
+ use accessors 'foo';
+ use Class::MakeMethods::Template::Hash 'scalar --get_set_chain' => 'foo';
+
+ use accessors::chained 'foo';
+ use Class::MakeMethods::Template::Hash 'scalar --get_set_chain' => 'foo';
+
+ use accessors::classic 'foo';
+ use Class::MakeMethods::Template::Hash 'scalar' => 'foo';
+
+You may use this module directly, as shown in the SYNOPSIS above,
+
+Furthermore, you may call C<use Class::MakeMethods::Emulator::accessors
+'-take_namespace';> to alias the accessors namespace to this package,
+and subsequent calls to the original package will be transparently
+handled by this emulator. To remove the emulation aliasing, call
+C<use Class::MakeMethods::Emulator::accessors '-release_namespace'>.
+The same mechanism is also available for the classic and chained subclasses.
+
+B<Caution:> This affects B<all> subsequent uses of the accessors module in
+your program, including those in other modules, and might cause
+unexpected effects.
+
+
+=head1 SEE ALSO
+
+See L<Class::MakeMethods> for general information about this distribution.
+
+See L<Class::MakeMethods::Emulator> for more about this family of subclasses.
+
+See L<accessors> for documentation of the original module.
+
+=cut
diff --git a/lib/Class/MakeMethods/Emulator/mcoder.pm b/lib/Class/MakeMethods/Emulator/mcoder.pm
new file mode 100644
index 0000000..84ef034
--- /dev/null
+++ b/lib/Class/MakeMethods/Emulator/mcoder.pm
@@ -0,0 +1,116 @@
+package Class::MakeMethods::Emulator::mcoder;
+
+$VERSION = '0.05';
+
+use Class::MakeMethods::Emulator '-isasubclass';
+use Class::MakeMethods::Template '-isasubclass';
+
+########################################################################
+
+sub import {
+ my $class = shift;
+ ( my $target = $class ) =~ s/^Class::MakeMethods::Emulator:://;
+ $class->_handle_namespace( $target, $_[0] ) and shift;
+ $class->make( @_ ) if ( scalar @_ );
+}
+
+
+sub new { 'Template::Hash::new --with_values' }
+sub proxy { 'Template::Universal:forward_methods -target' }
+sub generic { { '-import' => { 'Template::Hash:scalar' => '*' } } }
+sub get { { interface => { default => { '*' =>'get' } } } }
+sub set { { interface => { default => { 'set_*' =>'set' } } } }
+sub undef { { interface => { default => { 'undef_*' =>'clear' } } } }
+sub delete { { interface => { default => { 'delete_*'=>'hash_delete' } } } }
+sub bool_set { { interface => { default => { 'set_*' =>'set_value' } },
+ '-import' => { 'Template::Hash:boolean' => '*' } } }
+sub bool_unset { { interface => { default => { 'unset_*' =>'clear' } } } }
+sub calculated { { interface => { default => { '*' =>'get_init' } },
+ params => { init_method=>'_calculate_*' } } }
+
+########################################################################
+
+foreach my $type ( qw( new get set proxy calculated ) ) {
+ $INC{"Class/MakeMethods/Emulator/mcoder/$type.pm"} =
+ $INC{"mcoder/$type.pm"} = __FILE__;
+ *{__PACKAGE__ . "::${type}::import"} = sub {
+ (shift) and (__PACKAGE__)->make( $type => [ @_ ] )
+ };
+}
+
+########################################################################
+
+1;
+
+__END__
+
+package Class::MakeMethods::Emulator::mcoder::get;
+@ISA = 'Class::MakeMethods::Emulator::mcoder';
+$INC{"Class/MakeMethods/Emulator/mcoder/get.pm"} = __FILE__;
+sub import { goto &Class::MakeMethods::Emulator::mcoder::sub_import }
+
+package Class::MakeMethods::Emulator::mcoder::set;
+@ISA = 'Class::MakeMethods::Emulator::mcoder';
+$INC{"Class/MakeMethods/Emulator/mcoder/set.pm"} = __FILE__;
+sub import { goto &Class::MakeMethods::Emulator::mcoder::sub_import }
+
+package Class::MakeMethods::Emulator::mcoder::proxy;
+@ISA = 'Class::MakeMethods::Emulator::mcoder';
+$INC{"Class/MakeMethods/Emulator/mcoder/proxy.pm"} = __FILE__;
+sub import { goto &Class::MakeMethods::Emulator::mcoder::sub_import }
+
+
+1;
+
+__END__
+
+=head1 NAME
+
+Class::MakeMethods::Emulator::mcoder - Emulate the mcoder module
+
+
+=head1 SYNOPSIS
+
+ package MyClass;
+
+ use Class::MakeMethods::Emulator::mcoder
+ [qw(get set)] => [qw(color sound height)],
+ proxy => [qw(runner run walk stop)],
+ calculated => weight;
+
+ sub _calculate_weight { shift->ask_weight }
+
+
+=head1 DESCRIPTION
+
+This module emulates the functionality of the mcoder module, using
+Class::MakeMethods to generate similar methods.
+
+For example, the following lines are equivalent:
+
+ use mcoder 'get' => 'foo';
+ use mcoder::get 'foo';
+ use Class::MakeMethods::Template::Hash 'scalar --get' => 'foo';
+
+You may use this module directly, as shown in the SYNOPSIS above,
+or you may call C<use Class::MakeMethods::Emulator::mcoder
+'-take_namespace';> to alias the mcoder namespace to this package,
+and subsequent calls to the original package will be transparently
+handled by this emulator. To remove the emulation aliasing, call
+C<use Class::MakeMethods::Emulator::mcoder '-release_namespace'>.
+The same mechanism is also available for the "sugar" subclasses.
+
+B<Caution:> This affects B<all> subsequent uses of the mcoder module in
+your program, including those in other modules, and might cause
+unexpected effects.
+
+
+=head1 SEE ALSO
+
+See L<Class::MakeMethods> for general information about this distribution.
+
+See L<Class::MakeMethods::Emulator> for more about this family of subclasses.
+
+See L< mcoder> for documentation of the original module.
+
+=cut
diff --git a/lib/Class/MakeMethods/Evaled.pm b/lib/Class/MakeMethods/Evaled.pm
new file mode 100644
index 0000000..233c9c6
--- /dev/null
+++ b/lib/Class/MakeMethods/Evaled.pm
@@ -0,0 +1,97 @@
+=head1 NAME
+
+Class::MakeMethods::Evaled - Make methods with simple string evals
+
+
+=head1 SYNOPSIS
+
+ package MyObject;
+ use Class::MakeMethods::Evaled::Hash (
+ new => 'new',
+ scalar => [ 'foo', 'bar' ],
+ array => 'my_list',
+ hash => 'my_index',
+ );
+
+
+=head1 DESCRIPTION
+
+This document describes the various subclasses of Class::MakeMethods
+included under the Evaled::* namespace, and the method types each
+one provides.
+
+The Evaled subclasses generate methods using a simple string templating mechanism and basic string evals.
+
+
+=head2 Calling Conventions
+
+When you C<use> this package, the method names you provide
+as arguments cause subroutines to be generated and installed in
+your module.
+
+See L<Class::MakeMethods::Standard/"Calling Conventions"> for more information.
+
+=head2 Declaration Syntax
+
+To declare methods, pass in pairs of a method-type name followed
+by one or more method names.
+
+Valid method-type names for this package are listed in L<"METHOD
+GENERATOR TYPES">.
+
+See L<Class::MakeMethods::Standard/"Declaration Syntax"> and L<Class::MakeMethods::Standard/"Parameter Syntax"> for more information.
+
+=cut
+
+package Class::MakeMethods::Evaled;
+
+$VERSION = 1.000;
+use strict;
+use Carp;
+
+use Class::MakeMethods::Standard '-isasubclass';
+use Class::MakeMethods::Utility::TextBuilder 'text_builder';
+
+########################################################################
+
+=head2 About Evaled Methods
+
+
+=cut
+
+sub evaled_methods {
+ my $class = shift;
+ my $template = shift;
+ my $package = $Class::MakeMethods::CONTEXT{TargetClass};
+ my @declarations = $class->_get_declarations( @_ );
+ my @code_chunks;
+ foreach my $method ( @declarations ) {
+ my $code = $template;
+ $code =~ s/__(\w+?)__/$method->{lc $1}/eg;
+
+ # my $code = text_builder( $template, {
+ # '__NAME__' => $method->{name},
+ # '__METHOD__{}' => $method,
+ # '__CONTEXT__{}' => $Class::MakeMethods::CONTEXT,
+ # } );
+
+ push @code_chunks, $code;
+ }
+ my $code = join( "\n", "package $package;", @code_chunks, "1;" );
+ eval $code;
+ $@ and Class::MakeMethods::_diagnostic('inst_eval_syntax', 'from eval', $@, $code);
+ return;
+}
+
+########################################################################
+
+=head1 SEE ALSO
+
+See L<Class::MakeMethods> for general information about this distribution.
+
+For distribution, installation, support, copyright and license
+information, see L<Class::MakeMethods::Docs::ReadMe>.
+
+=cut
+
+1;
diff --git a/lib/Class/MakeMethods/Evaled/Hash.pm b/lib/Class/MakeMethods/Evaled/Hash.pm
new file mode 100644
index 0000000..e306c76
--- /dev/null
+++ b/lib/Class/MakeMethods/Evaled/Hash.pm
@@ -0,0 +1,349 @@
+=head1 NAME
+
+Class::MakeMethods::Evaled::Hash - Typical hash methods
+
+
+=head1 SYNOPSIS
+
+ package MyObject;
+ use Class::MakeMethods::Evaled::Hash (
+ new => 'new',
+ scalar => [ 'foo', 'bar' ],
+ array => 'my_list',
+ hash => 'my_index',
+ );
+ ...
+
+ # Constructor
+ my $obj = MyObject->new( foo => 'Foozle' );
+
+ # Scalar Accessor
+ print $obj->foo();
+
+ $obj->bar('Barbados');
+ print $obj->bar();
+
+ # Array accessor
+ $obj->my_list(0 => 'Foozle', 1 => 'Bang!');
+ print $obj->my_list(1);
+
+ # Hash accessor
+ $obj->my_index('broccoli' => 'Blah!', 'foo' => 'Fiddle');
+ print $obj->my_index('foo');
+
+
+=head1 DESCRIPTION
+
+The Evaled::Hash subclass of MakeMethods provides a simple constructor and accessors for blessed-hash object instances.
+
+=head2 Calling Conventions
+
+When you C<use> this package, the method names you provide
+as arguments cause subroutines to be generated and installed in
+your module.
+
+See L<Class::MakeMethods::Standard/"Calling Conventions"> for a summary, or L<Class::MakeMethods/"USAGE"> for full details.
+
+=head2 Declaration Syntax
+
+To declare methods, pass in pairs of a method-type name followed
+by one or more method names. Valid method-type names for this
+package are listed in L<"METHOD GENERATOR TYPES">.
+
+See L<Class::MakeMethods::Standard/"Declaration Syntax"> for more
+syntax information.
+
+
+=cut
+
+package Class::MakeMethods::Evaled::Hash;
+
+$VERSION = 1.000;
+use strict;
+use Class::MakeMethods::Evaled '-isasubclass';
+
+########################################################################
+
+=head1 METHOD GENERATOR TYPES
+
+=head2 new - Constructor
+
+For each method name passed, returns a subroutine with the following characteristics:
+
+=over 4
+
+=item *
+
+If called as a class method, makes a new hash and blesses it into that class.
+
+=item *
+
+If called on a hash-based instance, makes a copy of it and blesses the copy into the same class as the original instance.
+
+=item *
+
+If passed a list of key-value pairs, appends them to the new hash. These arguments override any copied values, and later arguments with the same name will override earlier ones.
+
+=item *
+
+Returns the new instance.
+
+=back
+
+Sample declaration and usage:
+
+ package MyObject;
+ use Class::MakeMethods::Evaled::Hash (
+ new => 'new',
+ );
+ ...
+
+ # Bare constructor
+ my $empty = MyObject->new();
+
+ # Constructor with initial values
+ my $obj = MyObject->new( foo => 'Foozle', bar => 'Barbados' );
+
+ # Copy with overriding value
+ my $copy = $obj->new( bar => 'Bob' );
+
+=cut
+
+sub new {
+ (shift)->evaled_methods( q{
+ sub __NAME__ {
+ my $callee = shift;
+ if ( ref $callee ) {
+ bless { %$callee, @_ }, ref $callee;
+ } else {
+ bless { @_ }, $callee;
+ }
+ }
+ }, @_ )
+}
+
+########################################################################
+
+=head2 scalar - Instance Accessor
+
+For each method name passed, uses a closure to generate a subroutine with the following characteristics:
+
+=over 4
+
+=item *
+
+Must be called on a hash-based instance.
+
+=item *
+
+Uses the method name as a hash key to access the related value for each instance.
+
+=item *
+
+If called without any arguments returns the current value.
+
+=item *
+
+If called with an argument, stores that as the value, and returns it,
+
+=back
+
+Sample declaration and usage:
+
+ package MyObject;
+ use Class::MakeMethods::Evaled::Hash (
+ scalar => 'foo',
+ );
+ ...
+
+ # Store value
+ $obj->foo('Foozle');
+
+ # Retrieve value
+ print $obj->foo;
+
+=cut
+
+sub scalar {
+ (shift)->evaled_methods( q{
+ sub __NAME__ {
+ my $self = shift;
+ if ( scalar @_ ) {
+ $self->{'__NAME__'} = shift;
+ } else {
+ $self->{'__NAME__'};
+ }
+ }
+ }, @_ )
+}
+
+########################################################################
+
+=head2 array - Instance Ref Accessor
+
+For each method name passed, uses a closure to generate a subroutine with the following characteristics:
+
+=over 4
+
+=item *
+
+Must be called on a hash-based instance.
+
+=item *
+
+Uses the method name as a hash key to access the related value for each instance.
+
+=item *
+
+The value for each instance will be a reference to an array (or undef).
+
+=item *
+
+If called without any arguments, returns the current array-ref value (or undef).
+
+=item *
+
+If called with one argument, uses that argument as an index to retrieve from the referenced array, and returns that value (or undef).
+
+=item *
+
+If called with a list of index-value pairs, stores the value at the given index in the referenced array. If the instance's value was previously undefined, a new array is autovivified. The current value in each position will be overwritten, and later arguments with the same index will override earlier ones. Returns the current array-ref value.
+
+=back
+
+Sample declaration and usage:
+
+ package MyObject;
+ use Class::MakeMethods::Evaled::Hash (
+ array => 'bar',
+ );
+ ...
+
+ # Set values by position
+ $obj->bar(0 => 'Foozle', 1 => 'Bang!');
+
+ # Positions may be overwritten, and in any order
+ $obj->bar(2 => 'And Mash', 1 => 'Blah!');
+
+ # Retrieve value by position
+ print $obj->bar(1);
+
+ # Direct access to referenced array
+ print scalar @{ $obj->bar() };
+
+ # Reset the array contents to empty
+ @{ $obj->bar() } = ();
+
+=cut
+
+sub array {
+ (shift)->evaled_methods( q{
+ sub __NAME__ {
+ my $self = shift;
+ if ( scalar(@_) == 0 ) {
+ return $self->{'__NAME__'};
+ } elsif ( scalar(@_) == 1 ) {
+ $self->{'__NAME__'}->[ shift() ];
+ } elsif ( scalar(@_) % 2 ) {
+ Carp::croak "Odd number of items in assigment to __NAME__";
+ } else {
+ while ( scalar(@_) ) {
+ my $key = shift();
+ $self->{'__NAME__'}->[ $key ] = shift();
+ }
+ return $self->{'__NAME__'};
+ }
+ }
+ }, @_ )
+}
+
+########################################################################
+
+=head2 hash - Instance Ref Accessor
+
+For each method name passed, uses a closure to generate a subroutine with the following characteristics:
+
+=over 4
+
+=item *
+
+Must be called on a hash-based instance.
+
+=item *
+
+Uses the method name as a hash key to access the related value for each instance.
+
+=item *
+
+The value for each instance will be a reference to a hash (or undef).
+
+=item *
+
+If called without any arguments, returns the current hash-ref value (or undef).
+
+=item *
+
+If called with one argument, uses that argument as an index to retrieve from the referenced hash, and returns that value (or undef).
+
+=item *
+
+If called with a list of key-value pairs, stores the value under the given key in the referenced hash. If the instance's value was previously undefined, a new hash is autovivified. The current value under each key will be overwritten, and later arguments with the same key will override earlier ones. Returns the current hash-ref value.
+
+=back
+
+Sample declaration and usage:
+
+ package MyObject;
+ use Class::MakeMethods::Evaled::Hash (
+ hash => 'baz',
+ );
+ ...
+
+ # Set values by key
+ $obj->baz('foo' => 'Foozle', 'bar' => 'Bang!');
+
+ # Values may be overwritten, and in any order
+ $obj->baz('broccoli' => 'Blah!', 'foo' => 'Fiddle');
+
+ # Retrieve value by key
+ print $obj->baz('foo');
+
+ # Direct access to referenced hash
+ print keys %{ $obj->baz() };
+
+ # Reset the hash contents to empty
+ @{ $obj->baz() } = ();
+
+=cut
+
+sub hash {
+ (shift)->evaled_methods( q{
+ sub __NAME__ {
+ my $self = shift;
+ if ( scalar(@_) == 0 ) {
+ return $self->{'__NAME__'};
+ } elsif ( scalar(@_) == 1 ) {
+ $self->{'__NAME__'}->{ shift() };
+ } elsif ( scalar(@_) % 2 ) {
+ Carp::croak "Odd number of items in assigment to '__NAME__'";
+ } else {
+ while ( scalar(@_) ) {
+ $self->{'__NAME__'}->{ shift() } = shift();
+ }
+ return $self->{'__NAME__'};
+ }
+ }
+ }, @_ )
+}
+
+########################################################################
+
+=head1 SEE ALSO
+
+See L<Class::MakeMethods> for general information about this distribution.
+
+See L<Class::MakeMethods::Evaled> for more about this family of subclasses.
+
+=cut
+
+1;
diff --git a/lib/Class/MakeMethods/Standard.pm b/lib/Class/MakeMethods/Standard.pm
new file mode 100644
index 0000000..024049e
--- /dev/null
+++ b/lib/Class/MakeMethods/Standard.pm
@@ -0,0 +1,68 @@
+=head1 NAME
+
+Class::MakeMethods::Standard - Make common object accessors
+
+
+=head1 SYNOPSIS
+
+ package MyObject;
+ use Class::MakeMethods::Standard::Hash (
+ new => 'new',
+ scalar => [ 'foo', 'bar' ],
+ array => 'my_list',
+ hash => 'my_index',
+ );
+
+
+=head1 DESCRIPTION
+
+This document describes the various subclasses of Class::MakeMethods
+included under the Standard::* namespace, and the method types each
+one provides.
+
+The Standard subclasses provide a parameterized set of method-generation
+implementations.
+
+Subroutines are generated as closures bound to a hash containing
+the method name and (optionally) additional parameters.
+
+
+=head1 USAGE AND SYNTAX
+
+When you C<use> a subclass of this package, the method declarations
+you provide as arguments cause subroutines to be generated and
+installed in your module. You can also omit the arguments to C<use>
+and instead make methods at runtime by passing the declarations to
+a subsequent call to C<make()>.
+
+You may include any number of declarations in each call to C<use>
+or C<make()>. If methods with the same name already exist, earlier
+calls to C<use> or C<make()> win over later ones, but within each
+call, later declarations superceed earlier ones.
+
+You can install methods in a different package by passing
+C<-target_class =E<gt> I<package>> as your first arguments to C<use>
+or C<make>.
+
+See L<Class::MakeMethods/"USAGE"> for more details.
+
+=cut
+
+package Class::MakeMethods::Standard;
+
+$VERSION = 1.000;
+use strict;
+use Class::MakeMethods '-isasubclass';
+
+########################################################################
+
+=head1 SEE ALSO
+
+See L<Class::MakeMethods> for general information about this distribution.
+
+For distribution, installation, support, copyright and license
+information, see L<Class::MakeMethods::Docs::ReadMe>.
+
+=cut
+
+1;
diff --git a/lib/Class/MakeMethods/Standard/Array.pm b/lib/Class/MakeMethods/Standard/Array.pm
new file mode 100644
index 0000000..52c1b0b
--- /dev/null
+++ b/lib/Class/MakeMethods/Standard/Array.pm
@@ -0,0 +1,555 @@
+=head1 NAME
+
+Class::MakeMethods::Standard::Array - Methods for Array objects
+
+=head1 SYNOPSIS
+
+ package MyObject;
+ use Class::MakeMethods::Standard::Array (
+ new => 'new',
+ scalar => [ 'foo', 'bar' ],
+ array => 'my_list',
+ hash => 'my_index',
+ );
+ ...
+
+ my $obj = MyObject->new( foo => 'Foozle' );
+ print $obj->foo();
+
+ $obj->bar('Barbados');
+ print $obj->bar();
+
+ $obj->my_list(0 => 'Foozle', 1 => 'Bang!');
+ print $obj->my_list(1);
+
+ $obj->my_index('broccoli' => 'Blah!', 'foo' => 'Fiddle');
+ print $obj->my_index('foo');
+
+=head1 DESCRIPTION
+
+The Standard::Array suclass of MakeMethods provides a basic
+constructor and accessors for blessed-array object instances.
+
+=head2 Calling Conventions
+
+When you C<use> this package, the method names you provide
+as arguments cause subroutines to be generated and installed in
+your module.
+
+See L<Class::MakeMethods::Standard/"Calling Conventions"> for more information.
+
+=head2 Declaration Syntax
+
+To declare methods, pass in pairs of a method-type name followed
+by one or more method names.
+
+Valid method-type names for this package are listed in L<"METHOD
+GENERATOR TYPES">.
+
+See L<Class::MakeMethods::Standard/"Declaration Syntax"> and L<Class::MakeMethods::Standard/"Parameter Syntax"> for more information.
+
+=cut
+
+package Class::MakeMethods::Standard::Array;
+
+$VERSION = 1.000;
+use strict;
+use Class::MakeMethods::Standard '-isasubclass';
+use Class::MakeMethods::Utility::ArraySplicer 'array_splicer';
+
+########################################################################
+
+=head2 Positional Accessors and %FIELDS
+
+Each accessor method is assigned the next available array index at
+which to store its value.
+
+The mapping between method names and array positions is stored in
+a hash named %FIELDS in the declaring package. When a package
+declares its first positional accessor, its %FIELDS are initialized
+by searching its inheritance tree.
+
+B<Warning>: Subclassing packages that use positional accessors is
+somewhat fragile, since you may end up with two distinct methods assigned to the same position. Specific cases to avoid are:
+
+=over 4
+
+=item *
+
+If you inherit from more than one class with positional accessors,
+the positions used by the two sets of methods will overlap.
+
+=item *
+
+If your superclass adds additional positional accessors after you
+declare your first, they will overlap yours.
+
+=back
+
+=cut
+
+sub _array_index {
+ my $class = shift;
+ my $name = shift;
+ no strict;
+ local $^W = 0;
+ if ( ! scalar %{$class . "::FIELDS"} ) {
+ my @classes = @{$class . "::ISA"};
+ my @fields;
+ while ( @classes ) {
+ my $superclass = shift @classes;
+ if ( scalar %{$superclass . "::FIELDS"} ) {
+ push @fields, %{$superclass . "::FIELDS"};
+ } else {
+ unshift @classes, @{$superclass . "::ISA"}
+ }
+ }
+ %{$class . "::FIELDS"} = @fields
+ }
+ my $field_hash = \%{$class . "::FIELDS"};
+ $field_hash->{$name} or $field_hash->{$name} = scalar keys %$field_hash
+}
+
+########################################################################
+
+=head1 METHOD GENERATOR TYPES
+
+=head2 new - Constructor
+
+For each method name passed, returns a subroutine with the following characteristics:
+
+=over 4
+
+=item *
+
+Has a reference to a sample item to copy. This defaults to a reference to an empty array, but you may override this with the C<'defaults' => I<array_ref>> method parameter.
+
+=item *
+
+If called as a class method, makes a new array containing values from the sample item, and blesses it into that class.
+
+=item *
+
+If called on an array-based instance, makes a copy of it and blesses the copy into the same class as the original instance.
+
+=item *
+
+If passed a list of method-value pairs, calls each named method with the associated value as an argument.
+
+=item *
+
+Returns the new instance.
+
+=back
+
+Sample declaration and usage:
+
+ package MyObject;
+ use Class::MakeMethods::Standard::Array (
+ new => 'new',
+ );
+ ...
+
+ # Bare constructor
+ my $empty = MyObject->new();
+
+ # Constructor with initial sequence of method calls
+ my $obj = MyObject->new( foo => 'Foozle', bar => 'Barbados' );
+
+ # Copy with overriding sequence of method calls
+ my $copy = $obj->new( bar => 'Bob' );
+
+=cut
+
+sub new {
+ my $class = shift;
+ map {
+ my $name = $_->{name};
+ my $defaults = $_->{defaults} || [];
+ $name => sub {
+ my $callee = shift;
+ my $self = ref($callee) ? bless( [@$callee], ref($callee) )
+ : bless( [@$defaults], $callee );
+ while ( scalar @_ ) {
+ my $method = shift;
+ $self->$method( shift );
+ }
+ return $self;
+ }
+ } $class->_get_declarations(@_)
+}
+
+########################################################################
+
+=head2 scalar - Instance Accessor
+
+For each method name passed, uses a closure to generate a subroutine with the following characteristics:
+
+=over 4
+
+=item *
+
+Must be called on an array-based instance.
+
+=item *
+
+Determines the array position associated with the method name, and uses that as an index into each instance to access the related value. This defaults to the next available slot in %FIELDS, but you may override this with the C<'array_index' => I<number>> method parameter, or by pre-filling the contents of %FIELDS.
+
+=item *
+
+If called without any arguments returns the current value (or undef).
+
+=item *
+
+If called with an argument, stores that as the value, and returns it,
+
+=back
+
+Sample declaration and usage:
+
+ package MyObject;
+ use Class::MakeMethods::Standard::Array (
+ scalar => 'foo',
+ );
+ ...
+
+ # Store value
+ $obj->foo('Foozle');
+
+ # Retrieve value
+ print $obj->foo;
+
+=cut
+
+sub scalar {
+ my $class = shift;
+ map {
+ my $name = $_->{name};
+ my $index = $_->{array_index} ||
+ _array_index( $class->_context('TargetClass'), $name );
+ $name => sub {
+ my $self = shift;
+ if ( scalar @_ ) {
+ $self->[$index] = shift;
+ } else {
+ $self->[$index];
+ }
+ }
+ } $class->_get_declarations(@_)
+}
+
+########################################################################
+
+=head2 array - Instance Ref Accessor
+
+For each method name passed, uses a closure to generate a subroutine with the following characteristics:
+
+=over 4
+
+=item *
+
+Must be called on an array-based instance.
+
+=item *
+
+Determines the array position associated with the method name, and uses that as an index into each instance to access the related value. This defaults to the next available slot in %FIELDS, but you may override this with the C<'array_index' => I<number>> method parameter, or by pre-filling the contents of %FIELDS.
+
+=item *
+
+The value for each instance will be a reference to an array (or undef).
+
+=item *
+
+If called without any arguments, returns the current array-ref value (or undef).
+
+=item *
+
+If called with a single non-ref argument, uses that argument as an index to retrieve from the referenced array, and returns that value (or undef).
+
+=item *
+
+If called with a single array ref argument, uses that list to return a slice of the referenced array.
+
+=item *
+
+If called with a list of argument pairs, each with a non-ref index and an associated value, stores the value at the given index in the referenced array. If the instance's value was previously undefined, a new array is autovivified. The current value in each position will be overwritten, and later arguments with the same index will override earlier ones. Returns the current array-ref value.
+
+=item *
+
+If called with a list of argument pairs, each with the first item being a reference to an array of up to two numbers, loops over each pair and uses those numbers to splice the value array.
+
+The first controlling number is the position at which the splice will begin. Zero will start before the first item in the list. Negative numbers count backwards from the end of the array.
+
+The second number is the number of items to be removed from the list. If it is omitted, or undefined, or zero, no items are removed. If it is a positive integer, that many items will be returned.
+
+If both numbers are omitted, or are both undefined, they default to containing the entire value array.
+
+If the second argument is undef, no values will be inserted; if it is a non-reference value, that one value will be inserted; if it is an array-ref, its values will be copied.
+
+The method returns the items that removed from the array, if any.
+
+=back
+
+Sample declaration and usage:
+
+ package MyObject;
+ use Class::MakeMethods::Standard::Array (
+ array => 'bar',
+ );
+ ...
+
+ # Clear and set contents of list
+ print $obj->bar([ 'Spume', 'Frost' ] );
+
+ # Set values by position
+ $obj->bar(0 => 'Foozle', 1 => 'Bang!');
+
+ # Positions may be overwritten, and in any order
+ $obj->bar(2 => 'And Mash', 1 => 'Blah!');
+
+ # Retrieve value by position
+ print $obj->bar(1);
+
+ # Direct access to referenced array
+ print scalar @{ $obj->bar() };
+
+There are also calling conventions for slice and splice operations:
+
+ # Retrieve slice of values by position
+ print join(', ', $obj->bar( undef, [0, 2] ) );
+
+ # Insert an item at position in the array
+ $obj->bar([3], 'Potatoes' );
+
+ # Remove 1 item from position 3 in the array
+ $obj->bar([3, 1], undef );
+
+ # Set a new value at position 2, and return the old value
+ print $obj->bar([2, 1], 'Froth' );
+
+=cut
+
+sub array {
+ my $class = shift;
+ map {
+ my $name = $_->{name};
+ my $index = $_->{array_index} ||
+ _array_index( $class->_context('TargetClass'), $name );
+ my $init = $_->{auto_init};
+ $name => sub {
+ my $self = shift;
+ if ( scalar(@_) == 0 ) {
+ if ( $init and ! defined $self->[$index] ) {
+ $self->[$index] = [];
+ }
+ ( ! $self->[$index] ) ? () :
+ ( wantarray ) ? @{ $self->[$index] } :
+ $self->[$index]
+ } elsif ( scalar(@_) == 1 and ref $_[0] eq 'ARRAY' ) {
+ $self->[$index] = [ @{ $_[0] } ];
+ ( ! $self->[$index] ) ? () :
+ ( wantarray ) ? @{ $self->[$index] } :
+ $self->[$index]
+ } else {
+ $self->[$index] ||= [];
+ array_splicer( $self->[$index], @_ );
+ }
+ }
+ } $class->_get_declarations(@_)
+}
+
+########################################################################
+
+=head2 hash - Instance Ref Accessor
+
+For each method name passed, uses a closure to generate a subroutine with the following characteristics:
+
+=over 4
+
+=item *
+
+Must be called on an array-based instance.
+
+=item *
+
+Determines the array position associated with the method name, and uses that as an index into each instance to access the related value. This defaults to the next available slot in %FIELDS, but you may override this with the C<'array_index' => I<number>> method parameter, or by pre-filling the contents of %FIELDS.
+
+
+=item *
+
+The value for each instance will be a reference to a hash (or undef).
+
+=item *
+
+If called without any arguments, returns the contents of the hash in list context, or a hash reference in scalar context (or undef).
+
+=item *
+
+If called with one argument, uses that argument as an index to retrieve from the referenced hash, and returns that value (or undef). If the single argument is an array ref, then a slice of the referenced hash is returned.
+
+=item *
+
+If called with a list of key-value pairs, stores the value under the given key in the referenced hash. If the instance's value was previously undefined, a new hash is autovivified. The current value under each key will be overwritten, and later arguments with the same key will override earlier ones. Returns the contents of the hash in list context, or a hash reference in scalar context.
+
+=back
+
+Sample declaration and usage:
+
+ package MyObject;
+ use Class::MakeMethods::Standard::Array (
+ hash => 'baz',
+ );
+ ...
+
+ # Set values by key
+ $obj->baz('foo' => 'Foozle', 'bar' => 'Bang!');
+
+ # Values may be overwritten, and in any order
+ $obj->baz('broccoli' => 'Blah!', 'foo' => 'Fiddle');
+
+ # Retrieve value by key
+ print $obj->baz('foo');
+
+ # Retrive slice of values by position
+ print join(', ', $obj->baz( ['foo', 'bar'] ) );
+
+ # Direct access to referenced hash
+ print keys %{ $obj->baz() };
+
+ # Reset the hash contents to empty
+ @{ $obj->baz() } = ();
+
+=cut
+
+sub hash {
+ my $class = shift;
+ map {
+ my $name = $_->{name};
+ my $index = $_->{array_index} ||
+ _array_index( $class->_context('TargetClass'), $name );
+ my $init = $_->{auto_init};
+ $name => sub {
+ my $self = shift;
+ if ( scalar(@_) == 0 ) {
+ if ( $init and ! defined $self->[$index] ) {
+ $self->[$index] = {};
+ }
+ ( ! $self->[$index] ) ? () :
+ ( wantarray ) ? %{ $self->[$index] } :
+ $self->[$index]
+ } elsif ( scalar(@_) == 1 ) {
+ if ( ref($_[0]) eq 'HASH' ) {
+ my $hash = shift;
+ $self->[$index] = { %$hash };
+ } elsif ( ref($_[0]) eq 'ARRAY' ) {
+ return @{$self->[$index]}{ @{$_[0]} }
+ } else {
+ return $self->[$index]->{ $_[0] }
+ }
+ } elsif ( scalar(@_) % 2 ) {
+ Carp::croak "Odd number of items in assigment to $name";
+ } else {
+ while ( scalar(@_) ) {
+ my $key = shift();
+ $self->[$index]->{ $key } = shift();
+ }
+ ( wantarray ) ? %{ $self->[$index] } :
+ $self->[$index]
+ }
+ }
+ } $class->_get_declarations(@_)
+}
+
+########################################################################
+
+=head2 object - Instance Ref Accessor
+
+For each method name passed, uses a closure to generate a subroutine with the following characteristics:
+
+=over 4
+
+=item *
+
+Must be called on an array-based instance.
+
+=item *
+
+Determines the array position associated with the method name, and uses that as an index into each instance to access the related value. This defaults to the next available slot in %FIELDS, but you may override this with the C<'array_index' => I<number>> method parameter, or by pre-filling the contents of %FIELDS.
+
+=item *
+
+The value for each instance will be a reference to an object (or undef).
+
+=item *
+
+If called without any arguments returns the current value.
+
+=item *
+
+If called with an argument, stores that as the value, and returns it,
+
+=back
+
+Sample declaration and usage:
+
+ package MyObject;
+ use Class::MakeMethods::Standard::Hash (
+ object => 'foo',
+ );
+ ...
+
+ # Store value
+ $obj->foo( Foozle->new() );
+
+ # Retrieve value
+ print $obj->foo;
+
+=cut
+
+sub object {
+ my $class = shift;
+ map {
+ my $name = $_->{name};
+ my $index = $_->{array_index} ||
+ _array_index( $class->_context('TargetClass'), $name );
+ my $class = $_->{class};
+ my $init = $_->{auto_init};
+ if ( $init and ! $class ) {
+ Carp::croak("Use of auto_init requires value for class parameter")
+ }
+ my $new_method = $_->{new_method} || 'new';
+ $name => sub {
+ my $self = shift;
+ if ( scalar @_ ) {
+ my $value = shift;
+ if ( $class and ! UNIVERSAL::isa( $value, $class ) ) {
+ Carp::croak "Wrong argument type ('$value') in assigment to $name";
+ }
+ $self->[$index] = $value;
+ } else {
+ if ( $init and ! defined $self->[$index] ) {
+ $self->[$index] = $class->$new_method();
+ } else {
+ $self->[$index];
+ }
+ }
+ }
+ } $class->_get_declarations(@_)
+}
+
+########################################################################
+
+=head1 SEE ALSO
+
+See L<Class::MakeMethods> for general information about this distribution.
+
+See L<Class::MakeMethods::Standard> for more about this family of subclasses.
+
+See L<Class::MakeMethods::Standard::Hash> for equivalent functionality
+based on blessed hashes. If your module will be extensively
+subclassed, consider switching to Standard::Hash to avoid the
+subclassing concerns described above.
+
+=cut
+
+1;
diff --git a/lib/Class/MakeMethods/Standard/Global.pm b/lib/Class/MakeMethods/Standard/Global.pm
new file mode 100644
index 0000000..9c1e48d
--- /dev/null
+++ b/lib/Class/MakeMethods/Standard/Global.pm
@@ -0,0 +1,405 @@
+=head1 NAME
+
+Class::MakeMethods::Standard::Global - Global data
+
+=head1 SYNOPSIS
+
+ package MyClass;
+ use Class::MakeMethods::Standard::Global (
+ scalar => [ 'foo' ],
+ array => [ 'my_list' ],
+ hash => [ 'my_index' ],
+ );
+ ...
+
+ MyClass->foo( 'Foozle' );
+ print MyClass->foo();
+
+ print MyClass->new(...)->foo(); # same value for any instance
+ print MySubclass->foo(); # ... and for any subclass
+
+ MyClass->my_list(0 => 'Foozle', 1 => 'Bang!');
+ print MyClass->my_list(1);
+
+ MyClass->my_index('broccoli' => 'Blah!', 'foo' => 'Fiddle');
+ print MyClass->my_index('foo');
+
+
+=head1 DESCRIPTION
+
+The Standard::Global suclass of MakeMethods provides basic accessors for shared data.
+
+=head2 Calling Conventions
+
+When you C<use> this package, the method names you provide
+as arguments cause subroutines to be generated and installed in
+your module.
+
+See L<Class::MakeMethods::Standard/"Calling Conventions"> for more information.
+
+=head2 Declaration Syntax
+
+To declare methods, pass in pairs of a method-type name followed
+by one or more method names.
+
+Valid method-type names for this package are listed in L<"METHOD
+GENERATOR TYPES">.
+
+See L<Class::MakeMethods::Standard/"Declaration Syntax"> and L<Class::MakeMethods::Standard/"Parameter Syntax"> for more information.
+
+=cut
+
+package Class::MakeMethods::Standard::Global;
+
+$VERSION = 1.000;
+use strict;
+use Class::MakeMethods::Standard '-isasubclass';
+use Class::MakeMethods::Utility::ArraySplicer 'array_splicer';
+
+########################################################################
+
+=head1 METHOD GENERATOR TYPES
+
+=head2 scalar - Global Accessor
+
+For each method name passed, uses a closure to generate a subroutine with the following characteristics:
+
+=over 4
+
+=item *
+
+May be called as a class method, or on any instance or subclass, and behaves identically regardless of what it was called on.
+
+=item *
+
+If called without any arguments returns the current value.
+
+=item *
+
+If called with an argument, stores that as the value, and returns it,
+
+=back
+
+Sample declaration and usage:
+
+ package MyClass;
+ use Class::MakeMethods::Standard::Global (
+ scalar => 'foo',
+ );
+ ...
+
+ # Store value
+ MyClass->foo('Foozle');
+
+ # Retrieve value
+ print MyClass->foo;
+
+=cut
+
+sub scalar {
+ map {
+ my $name = $_->{name};
+ my $data;
+ $name => sub {
+ my $self = shift;
+ if ( scalar(@_) == 0 ) {
+ $data;
+ } else {
+ $data = shift;
+ }
+ }
+ } (shift)->_get_declarations(@_)
+}
+
+########################################################################
+
+=head2 array - Global Ref Accessor
+
+For each method name passed, uses a closure to generate a subroutine with the following characteristics:
+
+=over 4
+
+=item *
+
+May be called as a class method, or on any instance or subclass, and behaves identically regardless of what it was called on.
+
+=item *
+
+The global value will be a reference to an array (or undef).
+
+=item *
+
+If called without any arguments, returns the current array-ref value (or undef).
+
+
+=item *
+
+If called with a single non-ref argument, uses that argument as an index to retrieve from the referenced array, and returns that value (or undef).
+
+=item *
+
+If called with a single array ref argument, uses that list to return a slice of the referenced array.
+
+=item *
+
+If called with a list of argument pairs, each with a non-ref index and an associated value, stores the value at the given index in the referenced array. If the global value was previously undefined, a new array is autovivified. The current value in each position will be overwritten, and later arguments with the same index will override earlier ones. Returns the current array-ref value.
+
+=item *
+
+If called with a list of argument pairs, each with the first item being a reference to an array of up to two numbers, loops over each pair and uses those numbers to splice the value array.
+
+The first controlling number is the position at which the splice will begin. Zero will start before the first item in the list. Negative numbers count backwards from the end of the array.
+
+The second number is the number of items to be removed from the list. If it is omitted, or undefined, or zero, no items are removed. If it is a positive integer, that many items will be returned.
+
+If both numbers are omitted, or are both undefined, they default to containing the entire value array.
+
+If the second argument is undef, no values will be inserted; if it is a non-reference value, that one value will be inserted; if it is an array-ref, its values will be copied.
+
+The method returns the items that removed from the array, if any.
+
+=back
+
+Sample declaration and usage:
+
+ package MyClass;
+ use Class::MakeMethods::Standard::Global (
+ array => 'bar',
+ );
+ ...
+
+ # Clear and set contents of list
+ print MyClass->bar([ 'Spume', 'Frost' ] );
+
+ # Set values by position
+ MyClass->bar(0 => 'Foozle', 1 => 'Bang!');
+
+ # Positions may be overwritten, and in any order
+ MyClass->bar(2 => 'And Mash', 1 => 'Blah!');
+
+ # Retrieve value by position
+ print MyClass->bar(1);
+
+ # Direct access to referenced array
+ print scalar @{ MyClass->bar() };
+
+There are also calling conventions for slice and splice operations:
+
+ # Retrieve slice of values by position
+ print join(', ', MyClass->bar( undef, [0, 2] ) );
+
+ # Insert an item at position in the array
+ MyClass->bar([3], 'Potatoes' );
+
+ # Remove 1 item from position 3 in the array
+ MyClass->bar([3, 1], undef );
+
+ # Set a new value at position 2, and return the old value
+ print MyClass->bar([2, 1], 'Froth' );
+
+=cut
+
+sub array {
+ map {
+ my $name = $_->{name};
+ my $data;
+ my $init = $_->{auto_init};
+ $name => sub {
+ my $self = shift;
+ if ( scalar(@_) == 0 ) {
+ if ( $init and ! defined $data ) {
+ $data = [];
+ }
+ ! $data ? () : wantarray ? @$data : $data;
+ } elsif ( scalar(@_) == 1 and ref $_[0] eq 'ARRAY' ) {
+ $data = [ @{ $_[0] } ];
+ wantarray ? @$data : $data;
+ } else {
+ $data ||= [];
+ return array_splicer( $data, @_ );
+ }
+ }
+ } (shift)->_get_declarations(@_)
+}
+
+########################################################################
+
+=head2 hash - Global Ref Accessor
+
+For each method name passed, uses a closure to generate a subroutine with the following characteristics:
+
+=over 4
+
+=item *
+
+May be called as a class method, or on any instance or subclass, and behaves identically regardless of what it was called on.
+
+=item *
+
+The global value will be a reference to a hash (or undef).
+
+=item *
+
+If called without any arguments, returns the contents of the hash in list context, or a hash reference in scalar context (or undef).
+
+=item *
+
+If called with one non-ref argument, uses that argument as an index to retrieve from the referenced hash, and returns that value (or undef).
+
+=item *
+
+If called with one array-ref argument, uses the contents of that array to retrieve a slice of the referenced hash.
+
+=item *
+
+If called with one hash-ref argument, sets the contents of the referenced hash to match that provided.
+
+=item *
+
+If called with a list of key-value pairs, stores the value under the given key in the referenced hash. If the global value was previously undefined, a new hash is autovivified. The current value under each key will be overwritten, and later arguments with the same key will override earlier ones. Returns the contents of the hash in list context, or a hash reference in scalar context.
+
+=back
+
+Sample declaration and usage:
+
+ package MyClass;
+ use Class::MakeMethods::Standard::Global (
+ hash => 'baz',
+ );
+ ...
+
+ # Set values by key
+ MyClass->baz('foo' => 'Foozle', 'bar' => 'Bang!');
+
+ # Values may be overwritten, and in any order
+ MyClass->baz('broccoli' => 'Blah!', 'foo' => 'Fiddle');
+
+ # Retrieve value by key
+ print MyClass->baz('foo');
+
+ # Retrive slice of values by position
+ print join(', ', MyClass->baz( ['foo', 'bar'] ) );
+
+ # Direct access to referenced hash
+ print keys %{ MyClass->baz() };
+
+ # Reset the hash contents to empty
+ @{ MyClass->baz() } = ();
+
+=cut
+
+sub hash {
+ map {
+ my $name = $_->{name};
+ my $data;
+ my $init = $_->{auto_init};
+ $name => sub {
+ my $self = shift;
+ if ( scalar(@_) == 0 ) {
+ if ( $init and ! defined $data ) {
+ $data = {};
+ }
+ ! $data ? () : wantarray ? %$data : $data
+ } elsif ( scalar(@_) == 1 ) {
+ if ( ref($_[0]) eq 'HASH' ) {
+ my $hash = shift;
+ $data = { %$hash };
+ } elsif ( ref($_[0]) eq 'ARRAY' ) {
+ return @{$data}{ @{$_[0]} }
+ } else {
+ return $data->{ $_[0] }
+ }
+ } elsif ( scalar(@_) % 2 ) {
+ Carp::croak "Odd number of items in assigment to $name";
+ } else {
+ while ( scalar(@_) ) {
+ my $key = shift();
+ $data->{ $key } = shift();
+ }
+ wantarray ? %$data : $data;
+ }
+ }
+ } (shift)->_get_declarations(@_)
+}
+
+########################################################################
+
+=head2 object - Global Ref Accessor
+
+For each method name passed, uses a closure to generate a subroutine with the following characteristics:
+
+=over 4
+
+=item *
+
+May be called as a class method, or on any instance or subclass, and behaves identically regardless of what it was called on.
+
+=item *
+
+The global value will be a reference to an object (or undef).
+
+=item *
+
+If called without any arguments returns the current value.
+
+=item *
+
+If called with an argument, stores that as the value, and returns it,
+
+=back
+
+Sample declaration and usage:
+
+ package MyClass;
+ use Class::MakeMethods::Standard::Global (
+ object => 'foo',
+ );
+ ...
+
+ # Store value
+ MyClass->foo( Foozle->new() );
+
+ # Retrieve value
+ print MyClass->foo;
+
+=cut
+
+sub object {
+ map {
+ my $name = $_->{name};
+ my $data;
+ my $class = $_->{class};
+ my $init = $_->{auto_init};
+ if ( $init and ! $class ) {
+ Carp::croak("Use of auto_init requires value for class parameter")
+ }
+ my $new_method = $_->{new_method} || 'new';
+ $name => sub {
+ my $self = shift;
+ if ( scalar @_ ) {
+ my $value = shift;
+ if ( $class and ! UNIVERSAL::isa( $value, $class ) ) {
+ Carp::croak "Wrong argument type ('$value') in assigment to $name";
+ }
+ $data = $value;
+ } else {
+ if ( $init and ! defined $data ) {
+ $data = $class->$new_method();
+ }
+ $data;
+ }
+ }
+ } (shift)->_get_declarations(@_)
+}
+
+########################################################################
+
+=head1 SEE ALSO
+
+See L<Class::MakeMethods> for general information about this distribution.
+
+See L<Class::MakeMethods::Standard> for more about this family of subclasses.
+
+=cut
+
+1;
diff --git a/lib/Class/MakeMethods/Standard/Hash.pm b/lib/Class/MakeMethods/Standard/Hash.pm
new file mode 100644
index 0000000..ba4f65b
--- /dev/null
+++ b/lib/Class/MakeMethods/Standard/Hash.pm
@@ -0,0 +1,501 @@
+=head1 NAME
+
+Class::MakeMethods::Standard::Hash - Standard hash methods
+
+=head1 SYNOPSIS
+
+ package MyObject;
+ use Class::MakeMethods::Standard::Hash (
+ new => 'new',
+ scalar => [ 'foo', 'bar' ],
+ array => 'my_list',
+ hash => 'my_index',
+ );
+ ...
+
+ my $obj = MyObject->new( foo => 'Foozle' );
+ print $obj->foo();
+
+ $obj->bar('Barbados');
+ print $obj->bar();
+
+ $obj->my_list(0 => 'Foozle', 1 => 'Bang!');
+ print $obj->my_list(1);
+
+ $obj->my_index('broccoli' => 'Blah!', 'foo' => 'Fiddle');
+ print $obj->my_index('foo');
+
+=head1 DESCRIPTION
+
+The Standard::Hash suclass of MakeMethods provides a basic constructor and accessors for blessed-hash object instances.
+
+=head2 Calling Conventions
+
+When you C<use> this package, the method names you provide
+as arguments cause subroutines to be generated and installed in
+your module.
+
+See L<Class::MakeMethods::Standard/"Calling Conventions"> for more information.
+
+=head2 Declaration Syntax
+
+To declare methods, pass in pairs of a method-type name followed
+by one or more method names.
+
+Valid method-type names for this package are listed in L<"METHOD
+GENERATOR TYPES">.
+
+See L<Class::MakeMethods::Standard/"Declaration Syntax"> and L<Class::MakeMethods::Standard/"Parameter Syntax"> for more information.
+
+=cut
+
+package Class::MakeMethods::Standard::Hash;
+
+$VERSION = 1.000;
+use strict;
+use Class::MakeMethods::Standard '-isasubclass';
+use Class::MakeMethods::Utility::ArraySplicer 'array_splicer';
+
+########################################################################
+
+=head1 METHOD GENERATOR TYPES
+
+=head2 new - Constructor
+
+For each method name passed, returns a subroutine with the following characteristics:
+
+=over 4
+
+=item *
+
+Has a reference to a sample item to copy. This defaults to a reference to an empty hash, but you may override this with the C<'defaults' => I<hash_ref>> method parameter.
+
+=item *
+
+If called as a class method, makes a new hash and blesses it into that class.
+
+=item *
+
+If called on a hash-based instance, makes a copy of it and blesses the copy into the same class as the original instance.
+
+=item *
+
+If passed a list of key-value pairs, appends them to the new hash. These arguments override any copied values, and later arguments with the same name will override earlier ones.
+
+=item *
+
+Returns the new instance.
+
+=back
+
+Sample declaration and usage:
+
+ package MyObject;
+ use Class::MakeMethods::Standard::Hash (
+ new => 'new',
+ );
+ ...
+
+ # Bare constructor
+ my $empty = MyObject->new();
+
+ # Constructor with initial values
+ my $obj = MyObject->new( foo => 'Foozle', bar => 'Barbados' );
+
+ # Copy with overriding value
+ my $copy = $obj->new( bar => 'Bob' );
+
+=cut
+
+sub new {
+ map {
+ my $name = $_->{name};
+ my $defaults = $_->{defaults} || {};
+ $name => sub {
+ my $callee = shift;
+ my $self = ref($callee) ? bless( { %$callee }, ref $callee )
+ : bless( { %$defaults }, $callee );
+ while ( scalar @_ ) {
+ my $method = shift;
+ UNIVERSAL::can( $self, $method )
+ or Carp::croak("Can't call method '$method' in constructor for " . ( ref($callee) || $callee ));
+ $self->$method( shift );
+ }
+ return $self;
+ }
+ } (shift)->_get_declarations(@_)
+}
+
+########################################################################
+
+=head2 scalar - Instance Accessor
+
+For each method name passed, uses a closure to generate a subroutine with the following characteristics:
+
+=over 4
+
+=item *
+
+Must be called on a hash-based instance.
+
+=item *
+
+Has a specific hash key to use to access the related value for each instance.
+This defaults to the method name, but you may override this with the C<'hash_key' => I<string>> method parameter.
+
+=item *
+
+If called without any arguments returns the current value.
+
+=item *
+
+If called with an argument, stores that as the value, and returns it,
+
+=back
+
+Sample declaration and usage:
+
+ package MyObject;
+ use Class::MakeMethods::Standard::Hash (
+ scalar => 'foo',
+ );
+ ...
+
+ # Store value
+ $obj->foo('Foozle');
+
+ # Retrieve value
+ print $obj->foo;
+
+=cut
+
+sub scalar {
+ map {
+ my $name = $_->{name};
+ my $hash_key = $_->{hash_key} || $_->{name};
+ $name => sub {
+ my $self = shift;
+ if ( scalar(@_) == 0 ) {
+ $self->{$hash_key};
+ } else {
+ $self->{$hash_key} = shift;
+ }
+ }
+ } (shift)->_get_declarations(@_)
+}
+
+########################################################################
+
+=head2 array - Instance Ref Accessor
+
+For each method name passed, uses a closure to generate a subroutine with the following characteristics:
+
+=over 4
+
+=item *
+
+Must be called on a hash-based instance.
+
+=item *
+
+Has a specific hash key to use to access the related value for each instance.
+This defaults to the method name, but you may override this with the C<'hash_key' => I<string>> method parameter.
+
+=item *
+
+The value for each instance will be a reference to an array (or undef).
+
+=item *
+
+If called without any arguments, returns the contents of the array in list context, or an array reference in scalar context (or undef).
+
+=item *
+
+If called with a single array ref argument, sets the contents of the array to match the contents of the provided one.
+
+=item *
+
+If called with a single numeric argument, uses that argument as an index to retrieve from the referenced array, and returns that value (or undef).
+
+=item *
+
+If called with a two arguments, the first undefined and the second an array ref argument, uses that array's contents as a list of indexes to return a slice of the referenced array.
+
+=item *
+
+If called with a list of argument pairs, each with a numeric index and an associated value, stores the value at the given index in the referenced array. If the instance's value was previously undefined, a new array is autovivified. The current value in each position will be overwritten, and later arguments with the same index will override earlier ones. Returns the current array-ref value.
+
+=item *
+
+If called with a list of argument pairs, each with the first item being a reference to an array of up to two numbers, loops over each pair and uses those numbers to splice the value array.
+
+The first controlling number is the position at which the splice will begin. Zero will start before the first item in the list. Negative numbers count backwards from the end of the array.
+
+The second number is the number of items to be removed from the list. If it is omitted, or undefined, or zero, no items are removed. If it is a positive integer, that many items will be returned.
+
+If both numbers are omitted, or are both undefined, they default to containing the entire value array.
+
+If the second argument is undef, no values will be inserted; if it is a non-reference value, that one value will be inserted; if it is an array-ref, its values will be copied.
+
+The method returns the items that removed from the array, if any.
+
+=back
+
+Sample declaration and usage:
+
+ package MyObject;
+ use Class::MakeMethods::Standard::Hash (
+ array => 'bar',
+ );
+ ...
+
+ # Clear and set contents of list
+ print $obj->bar([ 'Spume', 'Frost' ] );
+
+ # Set values by position
+ $obj->bar(0 => 'Foozle', 1 => 'Bang!');
+
+ # Positions may be overwritten, and in any order
+ $obj->bar(2 => 'And Mash', 1 => 'Blah!');
+
+ # Retrieve value by position
+ print $obj->bar(1);
+
+ # Direct access to referenced array
+ print scalar @{ $obj->bar() };
+
+There are also calling conventions for slice and splice operations:
+
+ # Retrieve slice of values by position
+ print join(', ', $obj->bar( undef, [0, 2] ) );
+
+ # Insert an item at position in the array
+ $obj->bar([3], 'Potatoes' );
+
+ # Remove 1 item from position 3 in the array
+ $obj->bar([3, 1], undef );
+
+ # Set a new value at position 2, and return the old value
+ print $obj->bar([2, 1], 'Froth' );
+
+=cut
+
+sub array {
+ map {
+ my $name = $_->{name};
+ my $hash_key = $_->{hash_key} || $_->{name};
+ my $init = $_->{auto_init};
+ $name => sub {
+ my $self = shift;
+ if ( scalar(@_) == 0 ) {
+ if ( $init and ! defined $self->{$hash_key} ) {
+ $self->{$hash_key} = [];
+ }
+ ( ! $self->{$hash_key} ) ? () :
+ ( wantarray ) ? @{ $self->{$hash_key} } :
+ $self->{$hash_key}
+ } elsif ( scalar(@_) == 1 and ref $_[0] eq 'ARRAY' ) {
+ $self->{$hash_key} = [ @{ $_[0] } ];
+ ( ! $self->{$hash_key} ) ? () :
+ ( wantarray ) ? @{ $self->{$hash_key} } :
+ $self->{$hash_key}
+ } else {
+ $self->{$hash_key} ||= [];
+ return array_splicer( $self->{$hash_key}, @_ );
+ }
+ }
+ } (shift)->_get_declarations(@_)
+}
+
+########################################################################
+
+=head2 hash - Instance Ref Accessor
+
+For each method name passed, uses a closure to generate a subroutine with the following characteristics:
+
+=over 4
+
+=item *
+
+Must be called on a hash-based instance.
+
+=item *
+
+Has a specific hash key to use to access the related value for each instance.
+This defaults to the method name, but you may override this with the C<'hash_key' => I<string>> method parameter.
+
+=item *
+
+The value for each instance will be a reference to a hash (or undef).
+
+=item *
+
+If called without any arguments, returns the contents of the hash in list context, or a hash reference in scalar context (or undef).
+
+=item *
+
+If called with one non-ref argument, uses that argument as an index to retrieve from the referenced hash, and returns that value (or undef).
+
+=item *
+
+If called with one array-ref argument, uses the contents of that array to retrieve a slice of the referenced hash.
+
+=item *
+
+If called with one hash-ref argument, sets the contents of the referenced hash to match that provided.
+
+=item *
+
+If called with a list of key-value pairs, stores the value under the given key in the referenced hash. If the instance's value was previously undefined, a new hash is autovivified. The current value under each key will be overwritten, and later arguments with the same key will override earlier ones. Returns the contents of the hash in list context, or a hash reference in scalar context.
+
+=back
+
+Sample declaration and usage:
+
+ package MyObject;
+ use Class::MakeMethods::Standard::Hash (
+ hash => 'baz',
+ );
+ ...
+
+ # Set values by key
+ $obj->baz('foo' => 'Foozle', 'bar' => 'Bang!');
+
+ # Values may be overwritten, and in any order
+ $obj->baz('broccoli' => 'Blah!', 'foo' => 'Fiddle');
+
+ # Retrieve value by key
+ print $obj->baz('foo');
+
+ # Retrive slice of values by position
+ print join(', ', $obj->baz( ['foo', 'bar'] ) );
+
+ # Direct access to referenced hash
+ print keys %{ $obj->baz() };
+
+ # Reset the hash contents to empty
+ %{ $obj->baz() } = ();
+
+=cut
+
+sub hash {
+ map {
+ my $name = $_->{name};
+ my $hash_key = $_->{hash_key} || $_->{name};
+ my $init = $_->{auto_init};
+ $name => sub {
+ my $self = shift;
+ if ( scalar(@_) == 0 ) {
+ if ( $init and ! defined $self->{$hash_key} ) {
+ $self->{$hash_key} = {};
+ }
+ ( ! $self->{$hash_key} ) ? () :
+ ( wantarray ) ? %{ $self->{$hash_key} } :
+ $self->{$hash_key}
+ } elsif ( scalar(@_) == 1 ) {
+ if ( ref($_[0]) eq 'HASH' ) {
+ $self->{$hash_key} = { %{$_[0]} };
+ } elsif ( ref($_[0]) eq 'ARRAY' ) {
+ return @{$self->{$hash_key}}{ @{$_[0]} }
+ } else {
+ return $self->{$hash_key}->{ $_[0] }
+ }
+ } elsif ( scalar(@_) % 2 ) {
+ Carp::croak "Odd number of items in assigment to $name";
+ } else {
+ while ( scalar(@_) ) {
+ my $key = shift();
+ $self->{$hash_key}->{ $key } = shift();
+ }
+ return $self->{$hash_key};
+ }
+ }
+ } (shift)->_get_declarations(@_)
+}
+
+########################################################################
+
+=head2 object - Instance Ref Accessor
+
+For each method name passed, uses a closure to generate a subroutine with the following characteristics:
+
+=over 4
+
+=item *
+
+Must be called on a hash-based instance.
+
+=item *
+
+Has a specific hash key to use to access the related value for each instance.
+This defaults to the method name, but you may override this with the C<'hash_key' => I<string>> method parameter.
+
+=item *
+
+The value for each instance will be a reference to an object (or undef).
+
+=item *
+
+If called without any arguments returns the current value.
+
+=item *
+
+If called with an argument, stores that as the value, and returns it,
+
+=back
+
+Sample declaration and usage:
+
+ package MyObject;
+ use Class::MakeMethods::Standard::Hash (
+ object => 'foo',
+ );
+ ...
+
+ # Store value
+ $obj->foo( Foozle->new() );
+
+ # Retrieve value
+ print $obj->foo;
+
+=cut
+
+sub object {
+ map {
+ my $name = $_->{name};
+ my $hash_key = $_->{hash_key} || $_->{name};
+ my $class = $_->{class};
+ my $init = $_->{auto_init};
+ if ( $init and ! $class ) {
+ Carp::croak("Use of auto_init requires value for class parameter")
+ }
+ my $new_method = $_->{new_method} || 'new';
+ $name => sub {
+ my $self = shift;
+ if ( scalar @_ ) {
+ my $value = shift;
+ if ( $class and ! UNIVERSAL::isa( $value, $class ) ) {
+ Carp::croak "Wrong argument type ('$value') in assigment to $name";
+ }
+ $self->{$hash_key} = $value;
+ } else {
+ if ( $init and ! defined $self->{$hash_key} ) {
+ $self->{$hash_key} = $class->$new_method();
+ }
+ $self->{$hash_key};
+ }
+ }
+ } (shift)->_get_declarations(@_)
+}
+
+########################################################################
+
+=head1 SEE ALSO
+
+See L<Class::MakeMethods> for general information about this distribution.
+
+See L<Class::MakeMethods::Standard> for more about this family of subclasses.
+
+=cut
+
+1;
diff --git a/lib/Class/MakeMethods/Standard/Inheritable.pm b/lib/Class/MakeMethods/Standard/Inheritable.pm
new file mode 100644
index 0000000..d1b72ac
--- /dev/null
+++ b/lib/Class/MakeMethods/Standard/Inheritable.pm
@@ -0,0 +1,428 @@
+=head1 NAME
+
+Class::MakeMethods::Standard::Inheritable - Overridable data
+
+=head1 SYNOPSIS
+
+ package MyClass;
+
+ use Class::MakeMethods( 'Standard::Inheritable:scalar' => 'foo' );
+ # We now have an accessor method for an "inheritable" scalar value
+
+ MyClass->foo( 'Foozle' ); # Set a class-wide value
+ print MyClass->foo(); # Retrieve class-wide value
+
+ my $obj = MyClass->new(...);
+ print $obj->foo(); # All instances "inherit" that value...
+
+ $obj->foo( 'Foible' ); # until you set a value for an instance.
+ print $obj->foo(); # This now finds object-specific value.
+ ...
+
+ package MySubClass;
+ @ISA = 'MyClass';
+
+ print MySubClass->foo(); # Intially same as superclass,
+ MySubClass->foo('Foobar'); # but overridable per subclass,
+ print $subclass_obj->foo(); # and shared by its instances
+ $subclass_obj->foo('Fosil');# until you override them...
+ ...
+
+ # Similar behaviour for hashes and arrays is currently incomplete
+ package MyClass;
+ use Class::MakeMethods::Standard::Inheritable (
+ array => 'my_list',
+ hash => 'my_index',
+ );
+
+ MyClass->my_list(0 => 'Foozle', 1 => 'Bang!');
+ print MyClass->my_list(1);
+
+ MyClass->my_index('broccoli' => 'Blah!', 'foo' => 'Fiddle');
+ print MyClass->my_index('foo');
+
+
+=head1 DESCRIPTION
+
+The MakeMethods subclass provides accessor methods that search an inheritance tree to find a value. This allows you to set a shared or default value for a given class, optionally override it in a subclass, and then optionally override it on a per-instance basis.
+
+Note that all MakeMethods methods are inheritable, in the sense that they work as expected for subclasses. These methods are different in that the I<data> accessed by each method can be inherited or overridden in each subclass or instance. See L< Class::MakeMethods::Utility::Inheritable> for more about this type of "inheritable" or overridable" data.
+
+
+=head2 Calling Conventions
+
+When you C<use> this package, the method names you provide
+as arguments cause subroutines to be generated and installed in
+your module.
+
+See L<Class::MakeMethods::Standard/"Calling Conventions"> for more information.
+
+=head2 Declaration Syntax
+
+To declare methods, pass in pairs of a method-type name followed
+by one or more method names.
+
+Valid method-type names for this package are listed in L<"METHOD
+GENERATOR TYPES">.
+
+See L<Class::MakeMethods::Standard/"Declaration Syntax"> and L<Class::MakeMethods::Standard/"Parameter Syntax"> for more information.
+
+=cut
+
+package Class::MakeMethods::Standard::Inheritable;
+
+$VERSION = 1.000;
+use strict;
+
+use Class::MakeMethods::Standard '-isasubclass';
+use Class::MakeMethods::Utility::Inheritable qw(get_vvalue set_vvalue find_vself);
+use Class::MakeMethods::Utility::ArraySplicer 'array_splicer';
+
+########################################################################
+
+=head1 METHOD GENERATOR TYPES
+
+=head2 scalar - Class-specific Accessor
+
+For each method name passed, uses a closure to generate a subroutine with the following characteristics:
+
+=over 4
+
+=item *
+
+May be called as a class or instance method, on the declaring class or any subclass.
+
+=item *
+
+If called without any arguments returns the current value for the callee. If the callee has not had a value defined for this method, searches up from instance to class, and from class to superclass, until a callee with a value is located.
+
+=item *
+
+If called with an argument, stores that as the value associated with the callee, whether instance or class, and returns it,
+
+=back
+
+Sample declaration and usage:
+
+ package MyClass;
+ use Class::MakeMethods::Standard::Inheritable (
+ scalar => 'foo',
+ );
+ ...
+
+ # Store value
+ MyClass->foo('Foozle');
+
+ # Retrieve value
+ print MyClass->foo;
+
+=cut
+
+sub scalar {
+ my $class = shift;
+ map {
+ my $method = $_;
+ my $name = $method->{name};
+ $method->{data} ||= {};
+ $name => sub {
+ my $self = shift;
+ if ( scalar(@_) == 0 ) {
+ get_vvalue($method->{data}, $self);
+ } else {
+ my $value = shift;
+ set_vvalue($method->{data}, $self, $value);
+ }
+ }
+ } $class->_get_declarations(@_)
+}
+
+########################################################################
+
+=head2 array - Class-specific Ref Accessor
+
+For each method name passed, uses a closure to generate a subroutine with the following characteristics:
+
+=over 4
+
+=item *
+
+May be called as a class method, or on any instance or subclass, Must be called on a hash-based instance.
+
+=item *
+
+The class value will be a reference to an array (or undef).
+
+=item *
+
+If called without any arguments, returns the contents of the array in list context, or an array reference in scalar context (or undef).
+
+=item *
+
+If called with a single array ref argument, sets the contents of the array to match the contents of the provided one.
+
+=item *
+
+If called with a single numeric argument, uses that argument as an index to retrieve from the referenced array, and returns that value (or undef).
+
+=item *
+
+If called with a two arguments, the first undefined and the second an array ref argument, uses that array's contents as a list of indexes to return a slice of the referenced array.
+
+=item *
+
+If called with a list of argument pairs, each with a non-ref index and an associated value, stores the value at the given index in the referenced array. If the class value was previously undefined, a new array is autovivified. The current value in each position will be overwritten, and later arguments with the same index will override earlier ones. Returns the current array-ref value.
+
+=item *
+
+If called with a list of argument pairs, each with the first item being a reference to an array of up to two numbers, loops over each pair and uses those numbers to splice the value array.
+
+The first controlling number is the position at which the splice will begin. Zero will start before the first item in the list. Negative numbers count backwards from the end of the array.
+
+The second number is the number of items to be removed from the list. If it is omitted, or undefined, or zero, no items are removed. If it is a positive integer, that many items will be returned.
+
+If both numbers are omitted, or are both undefined, they default to containing the entire value array.
+
+If the second argument is undef, no values will be inserted; if it is a non-reference value, that one value will be inserted; if it is an array-ref, its values will be copied.
+
+The method returns the items that removed from the array, if any.
+
+=back
+
+Sample declaration and usage:
+
+ package MyClass;
+ use Class::MakeMethods::Standard::Inheritable (
+ array => 'bar',
+ );
+ ...
+
+ # Clear and set contents of list
+ print MyClass->bar([ 'Spume', 'Frost' ] );
+
+ # Set values by position
+ MyClass->bar(0 => 'Foozle', 1 => 'Bang!');
+
+ # Positions may be overwritten, and in any order
+ MyClass->bar(2 => 'And Mash', 1 => 'Blah!');
+
+ # Retrieve value by position
+ print MyClass->bar(1);
+
+ # Direct access to referenced array
+ print scalar @{ MyClass->bar() };
+
+There are also calling conventions for slice and splice operations:
+
+ # Retrieve slice of values by position
+ print join(', ', MyClass->bar( undef, [0, 2] ) );
+
+ # Insert an item at position in the array
+ MyClass->bar([3], 'Potatoes' );
+
+ # Remove 1 item from position 3 in the array
+ MyClass->bar([3, 1], undef );
+
+ # Set a new value at position 2, and return the old value
+ print MyClass->bar([2, 1], 'Froth' );
+
+=cut
+
+sub array {
+ my $class = shift;
+ map {
+ my $method = $_;
+ my $name = $method->{name};
+ $name => sub {
+ my $self = shift;
+
+ if ( scalar(@_) == 0 ) {
+ my $v_self = find_vself($method->{data}, $self);
+ my $value = $v_self ? $method->{data}{$v_self} : ();
+ if ( $method->{auto_init} and ! $value ) {
+ $value = $method->{data}{$self} = [];
+ }
+ ! $value ? () : wantarray ? @$value : $value;
+
+ } elsif ( scalar(@_) == 1 and ref $_[0] eq 'ARRAY' ) {
+ $method->{data}{$self} = [ @{ $_[0] } ];
+ wantarray ? @{ $method->{data}{$self} } : $method->{data}{$self}
+
+ } else {
+ if ( ! exists $method->{data}{$self} ) {
+ my $v_self = find_vself($method->{data}, $self);
+ $method->{data}{$self} = [ $v_self ? @$v_self : () ];
+ }
+ return array_splicer( $method->{data}{$self}, @_ );
+ }
+ }
+ } $class->_get_declarations(@_)
+}
+
+########################################################################
+
+=head2 hash - Class-specific Ref Accessor
+
+For each method name passed, uses a closure to generate a subroutine with the following characteristics:
+
+=over 4
+
+=item *
+
+May be called as a class method, or on any instance or subclass, Must be called on a hash-based instance.
+
+=item *
+
+The class value will be a reference to a hash (or undef).
+
+=item *
+
+If called without any arguments, returns the contents of the hash in list context, or a hash reference in scalar context. If the callee has not had a value defined for this method, searches up from instance to class, and from class to superclass, until a callee with a value is located.
+
+=item *
+
+If called with one non-ref argument, uses that argument as an index to retrieve from the referenced hash, and returns that value (or undef). If the callee has not had a value defined for this method, searches up from instance to class, and from class to superclass, until a callee with a value is located.
+
+=item *
+
+If called with one array-ref argument, uses the contents of that array to retrieve a slice of the referenced hash. If the callee has not had a value defined for this method, searches up from instance to class, and from class to superclass, until a callee with a value is located.
+
+=item *
+
+If called with one hash-ref argument, sets the contents of the referenced hash to match that provided.
+
+=item *
+
+If called with a list of key-value pairs, stores the value under the given key in the hash associated with the callee, whether instance or class. If the callee did not previously have a hash-ref value associated with it, searches up instance to class, and from class to superclass, until a callee with a value is located, and copies that hash before making the assignments. The current value under each key will be overwritten, and later arguments with the same key will override earlier ones. Returns the contents of the hash in list context, or a hash reference in scalar context.
+
+=back
+
+Sample declaration and usage:
+
+ package MyClass;
+ use Class::MakeMethods::Standard::Inheritable (
+ hash => 'baz',
+ );
+ ...
+
+ # Set values by key
+ MyClass->baz('foo' => 'Foozle', 'bar' => 'Bang!');
+
+ # Values may be overwritten, and in any order
+ MyClass->baz('broccoli' => 'Blah!', 'foo' => 'Fiddle');
+
+ # Retrieve value by key
+ print MyClass->baz('foo');
+
+ # Retrive slice of values by position
+ print join(', ', MyClass->baz( ['foo', 'bar'] ) );
+
+ # Direct access to referenced hash
+ print keys %{ MyClass->baz() };
+
+ # Reset the hash contents to empty
+ @{ MyClass->baz() } = ();
+
+B<NOTE: THIS METHOD GENERATOR IS INCOMPLETE.>
+
+=cut
+
+sub hash {
+ my $class = shift;
+ map {
+ my $method = $_;
+ my $name = $method->{name};
+ $name => sub {
+ my $self = shift;
+ if ( scalar(@_) == 0 ) {
+ my $v_self = find_vself($method->{data}, $self);
+ my $value = $v_self ? $method->{data}{$v_self} : ();
+ if ( $method->{auto_init} and ! $value ) {
+ $value = $method->{data}{$self} = {};
+ }
+ ! $value ? () : wantarray ? %$value : $value;
+ } elsif ( scalar(@_) == 1 ) {
+ if ( ref($_[0]) eq 'HASH' ) {
+ $method->{data}{$self} = { %{$_[0]} };
+ } elsif ( ref($_[0]) eq 'ARRAY' ) {
+ my $v_self = find_vself($method->{data}, $self);
+ return unless $v_self;
+ return @{$method->{data}{$v_self}}{ @{$_[0]} }
+ } else {
+ my $v_self = find_vself($method->{data}, $self);
+ return unless $v_self;
+ return $method->{data}{$v_self}->{ $_[0] };
+ }
+ } elsif ( scalar(@_) % 2 ) {
+ Carp::croak "Odd number of items in assigment to $method->{name}";
+ } else {
+ if ( ! exists $method->{data}{$self} ) {
+ my $v_self = find_vself($method->{data}, $self);
+ $method->{data}{$self} = { $v_self ? %$v_self : () };
+ }
+ while ( scalar(@_) ) {
+ my $key = shift();
+ $method->{data}{$self}->{ $key } = shift();
+ }
+ wantarray ? %{ $method->{data}{$self} } : $method->{data}{$self};
+ }
+ }
+ } $class->_get_declarations(@_)
+}
+
+########################################################################
+
+=head2 object - Class-specific Ref Accessor
+
+For each method name passed, uses a closure to generate a subroutine with the following characteristics:
+
+=over 4
+
+=item *
+
+May be called as a class method, or on any instance or subclass, Must be called on a hash-based instance.
+
+=item *
+
+The class value will be a reference to an object (or undef).
+
+=item *
+
+If called without any arguments returns the current value for the callee. If the callee has not had a value defined for this method, searches up from instance to class, and from class to superclass, until a callee with a value is located.
+
+=item *
+
+If called with an argument, stores that as the value associated with the callee, whether instance or class, and returns it,
+
+=back
+
+Sample declaration and usage:
+
+ package MyClass;
+ use Class::MakeMethods::Standard::Inheritable (
+ object => 'foo',
+ );
+ ...
+
+ # Store value
+ MyClass->foo( Foozle->new() );
+
+ # Retrieve value
+ print MyClass->foo;
+
+B<NOTE: THIS METHOD GENERATOR HAS NOT BEEN WRITTEN YET.>
+
+=cut
+
+sub object { }
+
+########################################################################
+
+=head1 SEE ALSO
+
+See L<Class::MakeMethods> for general information about this distribution.
+
+See L<Class::MakeMethods::Standard> for more about this family of subclasses.
+
+=cut
+
+1;
diff --git a/lib/Class/MakeMethods/Standard/Universal.pm b/lib/Class/MakeMethods/Standard/Universal.pm
new file mode 100644
index 0000000..641b159
--- /dev/null
+++ b/lib/Class/MakeMethods/Standard/Universal.pm
@@ -0,0 +1,336 @@
+=head1 NAME
+
+Class::MakeMethods::Standard::Universal - Generic Methods
+
+
+=head1 SYNOPSIS
+
+ package MyObject;
+ use Class::MakeMethods::Standard::Universal (
+ no_op => 'this',
+ abstract => 'that',
+ delegate => { name=>'play_music', target=>'instrument', method=>'play' },
+ );
+
+
+=head1 DESCRIPTION
+
+The Standard::Universal suclass of MakeMethods provides a [INCOMPLETE].
+
+=head2 Calling Conventions
+
+When you C<use> this package, the method names you provide
+as arguments cause subroutines to be generated and installed in
+your module.
+
+See L<Class::MakeMethods::Standard/"Calling Conventions"> for more information.
+
+=head2 Declaration Syntax
+
+To declare methods, pass in pairs of a method-type name followed
+by one or more method names.
+
+Valid method-type names for this package are listed in L<"METHOD
+GENERATOR TYPES">.
+
+See L<Class::MakeMethods::Standard/"Declaration Syntax"> and L<Class::MakeMethods::Standard/"Parameter Syntax"> for more information.
+
+=cut
+
+package Class::MakeMethods::Standard::Universal;
+
+$VERSION = 1.000;
+use strict;
+use Carp;
+use Class::MakeMethods::Standard '-isasubclass';
+
+########################################################################
+
+=head1 METHOD GENERATOR TYPES
+
+=head2 no_op - Placeholder
+
+For each method name passed, returns a subroutine with the following characteristics:
+
+=over 4
+
+=item *
+
+Does nothing.
+
+=back
+
+You might want to create and use such methods to provide hooks for
+subclass activity.
+
+Sample declaration and usage:
+
+ package MyObject;
+ use Class::MakeMethods::Standard::Universal (
+ no_op => 'whatever',
+ );
+ ...
+
+ # Doesn't do anything
+ MyObject->whatever();
+
+=cut
+
+sub no_op {
+ map {
+ my $method = $_;
+ $method->{name} => sub { }
+ } (shift)->_get_declarations(@_)
+}
+
+########################################################################
+
+=head2 abstract - Placeholder
+
+For each method name passed, returns a subroutine with the following characteristics:
+
+=over 4
+
+=item *
+
+Fails with an error message.
+
+=back
+
+This is intended to support the use of abstract methods, that must
+be overidden in a useful subclass.
+
+If each subclass is expected to provide an implementation of a given method, using this abstract method will replace the generic error message below with the clearer, more explicit error message that follows it:
+
+ Can't locate object method "foo" via package "My::Subclass"
+ The "foo" method is abstract and can not be called on My::Subclass
+
+However, note that the existence of this method will be detected by UNIVERSAL::can(), so it is not suitable for use in optional interfaces, for which you may wish to be able to detect whether the method is supported or not.
+
+Sample declaration and usage:
+
+ package MyObject;
+ use Class::MakeMethods::Standard::Universal (
+ abstract => 'whatever',
+ );
+ ...
+
+ package MySubclass;
+ sub whatever { ... }
+
+ # Failure
+ MyObject->whatever();
+
+ # Success
+ MySubclass->whatever();
+
+=cut
+
+sub abstract {
+ map {
+ my $method = $_;
+ $method->{name} => sub {
+ my $self = shift;
+ my $class = ref($self) ? "a " . ref($self) . " object" : $self;
+ croak("The $method->{name} method is abstract and can not be called on $class");
+ }
+ } (shift)->_get_declarations(@_)
+}
+
+########################################################################
+
+=head2 call_methods - Call methods by name
+
+For each method name passed, returns a subroutine with the following characteristics:
+
+=over 4
+
+=item *
+
+Accepts a hash of key-value pairs, or a reference to hash of such pairs. For each pair, the key is interpreted as the name of a method to call, and the value is the argument to be passed to that method.
+
+=back
+
+Sample declaration and usage:
+
+ package MyObject;
+ use Class::MakeMethods::Standard::Universal (
+ call_methods => 'init',
+ );
+ ...
+
+ my $object = MyObject->new()
+ $object->init( foo => 'Foozle', bar => 'Barbados' );
+
+ # Equivalent to:
+ $object->foo('Foozle');
+ $object->bar('Barbados');
+
+=cut
+
+sub call_methods {
+ map {
+ my $method = $_;
+ $method->{name} => sub {
+ my $self = shift;
+ local @_ = %{$_[0]} if ( scalar @_ == 1 and ref($_[0]) eq 'HASH');
+ while (scalar @_) {
+ my $key = shift;
+ $self->$key( shift )
+ }
+ }
+ } (shift)->_get_declarations(@_)
+}
+
+
+########################################################################
+
+=head2 join_methods - Concatenate results of other methods
+
+For each method name passed, returns a subroutine with the following characteristics:
+
+=over 4
+
+=item *
+
+Has a list of other methods names as an arrayref in the 'methods' parameter. B<Required>.
+
+=item *
+
+When called, calls each of the named method on itself, in order, and returns the concatenation of their results.
+
+=item *
+
+If a 'join' parameter is provided it is included between each method result.
+
+=item *
+
+If the 'skip_blanks' parameter is omitted, or is provided with a true value, removes all undefined or empty-string values from the results.
+
+=back
+
+=cut
+
+sub join_methods {
+ map {
+ my $method = $_;
+ $method->{methods} or confess;
+ $method->{join} = '' if ( ! defined $method->{join} );
+ $method->{skip_blanks} = '1' if ( ! defined $method->{skip_blanks} );
+ $method->{name} => sub {
+ my $self = shift;
+ my $joiner = $method->{join};
+ my @values = map { $self->$_() } @{ $method->{methods} };
+ @values = grep { defined and length } @values if ( $method->{skip_blanks} );
+ join $joiner, @values;
+ }
+ } (shift)->_get_declarations(@_)
+}
+
+########################################################################
+
+=head2 alias - Call another method
+
+For each method name passed, returns a subroutine with the following characteristics:
+
+=over 4
+
+=item *
+
+Calls another method on the same callee.
+
+=back
+
+You might create such a method to extend or adapt your class' interface.
+
+Sample declaration and usage:
+
+ package MyObject;
+ use Class::MakeMethods::Standard::Universal (
+ alias => { name=>'click_here', target=>'complex_machinery' }
+ );
+ sub complex_machinery { ... }
+ ...
+
+ $myobj->click_here(...); # calls $myobj->complex_machinery(...)
+
+=cut
+
+sub alias {
+ map {
+ my $method = $_;
+ $method->{name} => sub {
+ my $self = shift;
+
+ my $t_method = $method->{target} or confess("no target");
+ my @t_args = $method->{target_args} ? @{$method->{target_args}} : ();
+
+ $self->$t_method(@t_args, @_);
+ }
+ } (shift)->_get_declarations(@_)
+}
+
+########################################################################
+
+=head2 delegate - Use another object to provide method
+
+For each method name passed, returns a subroutine with the following characteristics:
+
+=over 4
+
+=item *
+
+Calls a method on self to retrieve another object, and then calls a method on that object and returns its value.
+
+=back
+
+You might want to create and use such methods to faciliate composition of objects from smaller objects.
+
+Sample declaration and usage:
+
+ package MyObject;
+ use Class::MakeMethods::Standard::Universal (
+ 'Standard::Hash:object' => { name=>'instrument' },
+ delegate => { name=>'play_music', target=>'instrument', method=>'play' }
+ );
+ ...
+
+ my $object = MyObject->new();
+ $object->instrument( MyInstrument->new );
+ $object->play_music;
+
+=cut
+
+sub delegate {
+ map {
+ my $method = $_;
+ $method->{method} ||= $method->{name};
+ $method->{name} => sub {
+ my $self = shift;
+
+ my $t_method = $method->{target} or confess("no target");
+ my @t_args = $method->{target_args} ? @{$method->{target_args}} : ();
+
+ my $m_method = $method->{method} or confess("no method");
+ my @m_args = $method->{method_args} ? @{$method->{method_args}} : ();
+ push @m_args, $self if ( $method->{target_args_self} );
+
+ my $obj = $self->$t_method( @t_args )
+ or croak("Can't delegate $method->{name} because $t_method is empty");
+
+ $obj->$m_method(@m_args, @_);
+ }
+ } (shift)->_get_declarations(@_)
+}
+
+########################################################################
+
+=head1 SEE ALSO
+
+See L<Class::MakeMethods> for general information about this distribution.
+
+See L<Class::MakeMethods::Standard> for more about this family of subclasses.
+
+=cut
+
+1;
diff --git a/lib/Class/MakeMethods/Template.pm b/lib/Class/MakeMethods/Template.pm
new file mode 100644
index 0000000..d5cd8f5
--- /dev/null
+++ b/lib/Class/MakeMethods/Template.pm
@@ -0,0 +1,1255 @@
+package Class::MakeMethods::Template;
+
+use strict;
+use Carp;
+
+use Class::MakeMethods '-isasubclass';
+
+use vars qw( $VERSION );
+$VERSION = 1.008;
+
+sub _diagnostic { &Class::MakeMethods::_diagnostic }
+
+########################################################################
+### TEMPLATE LOOKUP AND CACHING: named_method(), _definition()
+########################################################################
+
+use vars qw( %TemplateCache );
+
+# @results = $class->named_method( $name, @arguments );
+sub named_method {
+ my $class = shift;
+ my $name = shift;
+
+ # Support direct access to cached Template information
+ if (exists $TemplateCache{"$class\::$name"}) {
+ return $TemplateCache{"$class\::$name"};
+ }
+
+ my @results = $class->$name( @_ );
+
+ if ( scalar @results == 1 and ref $results[0] eq 'HASH' ) {
+ # If this is a hash-definition format, cache the results for speed.
+ my $def = $results[0];
+ $TemplateCache{"$class\::$name"} = $def;
+ _expand_definition($class, $name, $def);
+ return $def;
+ }
+
+ return wantarray ? @results : $results[0];
+}
+
+# $mm_def = _definition( $class, $target );
+sub _definition {
+ my ($class, $target) = @_;
+
+ while ( ! ref $target ) {
+ $target =~ s/\s.*//;
+
+ # If method name contains a colon or double colon, call the method on the
+ # indicated class.
+ my $call_class = ( ( $target =~ s/^(.*)\:{1,2}// )
+ ? Class::MakeMethods::_find_subclass($class, $1) : $class );
+ $target = $call_class->named_method( $target );
+ }
+ _diagnostic('mmdef_not_interpretable', $target)
+ unless ( ref($target) eq 'HASH' or ref($target) eq __PACKAGE__ );
+
+ return $target;
+}
+
+########################################################################
+### TEMPLATE INTERNALS: _expand_definition()
+########################################################################
+
+sub _expand_definition {
+ my ($class, $name, $mm_def) = @_;
+
+ return $mm_def if $mm_def->{'-parsed'};
+
+ $mm_def->{'template_class'} = $class;
+ $mm_def->{'template_name'} = $name;
+
+ # Allow definitions to import values from each other.
+ my $importer;
+ foreach $importer ( qw( interface params behavior code_expr modifier ) ) {
+ my $rules = $mm_def->{$importer}->{'-import'} || $mm_def->{'-import'};
+ my @rules = ( ref $rules eq 'HASH' ? %$rules : ref $rules eq 'ARRAY' ? @$rules : () );
+ unshift @rules, '::' . $class . ':generic' => '*' if $class->can('generic');
+ while (
+ my ($source, $names) = splice @rules, 0, 2
+ ) {
+ my $mmi = _definition($class, $source);
+ foreach ( ( $names eq '*' ) ? keys %{ $mmi->{$importer} }
+ : ( ref $names ) ? @{ $names } : ( $names ) ) {
+ my $current = $mm_def->{$importer}{$_};
+ my $import = $mmi->{$importer}{$_};
+ if ( ! $current ) {
+ $mm_def->{$importer}{$_} = $import;
+ } elsif ( ref($current) eq 'ARRAY' ) {
+ my @imports = ref($import) ? @$import : $import;
+ foreach my $imp ( @imports ) {
+ push @$current, $imp unless ( grep { $_ eq $imp } @$current );
+ }
+ }
+ }
+ }
+ delete $mm_def->{$importer}->{'-import'};
+ }
+ delete $mm_def->{'-import'};
+
+ _describe_definition( $mm_def ) if $Class::MakeMethods::CONTEXT{Debug};
+
+
+ $mm_def->{'-parsed'} = "$_[1]";
+
+ bless $mm_def, __PACKAGE__;
+}
+
+sub _describe_definition {
+ my $mm_def = shift;
+
+ my $def_type = "$mm_def->{template_class}:$mm_def->{template_name}";
+ warn "----\nMethods info for $def_type:\n";
+ if ( $mm_def->{interface} ) {
+ warn join '', "Templates: \n", map {
+ " $_: " . _describe_value($mm_def->{interface}{$_}) . "\n"
+ } keys %{$mm_def->{interface}};
+ }
+ if ( $mm_def->{modifier} ) {
+ warn join '', "Modifiers: \n", map {
+ " $_: " . _describe_value($mm_def->{modifier}{$_}) . "\n"
+ } keys %{$mm_def->{modifier}};
+ }
+}
+
+sub _describe_value {
+ my $value = $_[0];
+ ref($value) eq 'ARRAY' ? join(', ', @$value) :
+ ref($value) eq 'HASH' ? join(', ', %$value) :
+ "$value";
+}
+
+########################################################################
+### METHOD GENERATION: make_methods()
+########################################################################
+
+sub make_methods {
+ my $mm_def = shift;
+
+ return unless ( scalar @_ );
+
+ # Select default interface and initial method parameters
+ my $defaults = { %{ ( $mm_def->{'params'} ||= {} ) } };
+ $defaults->{'interface'} ||= $mm_def->{'interface'}{'-default'} || 'default';
+ $defaults->{'target_class'} = $mm_def->_context('TargetClass');
+ $defaults->{'template_class'} = $mm_def->{'template_class'};
+ $defaults->{'template_name'} = $mm_def->{'template_name'};
+
+ my %interface_cache;
+
+ # Our return value is the accumulated list of method-name => method-sub pairs
+ my @methods;
+
+ while (scalar @_) {
+
+ ### PARSING ### Requires: $mm_def, $defaults, @_
+
+ my $m_name = shift @_;
+ _diagnostic('make_empty') unless ( defined $m_name and length $m_name );
+
+ # Normalize: If we've got an array of names, replace it with those names
+ if ( ref $m_name eq 'ARRAY' ) {
+ my @items = @{ $m_name };
+ # If array is followed by a params hash, each one gets the same params
+ if ( scalar @_ and ref $_[0] eq 'HASH' and ! exists $_[0]->{'name'} ) {
+ my $params = shift;
+ @items = map { $_, $params } @items
+ }
+ unshift @_, @items;
+ next;
+ }
+
+ # Parse interfaces, modifiers and parameters
+ if ( $m_name =~ s/^-// ) {
+ if ( $m_name !~ s/^-// ) {
+ # -param => value
+ $defaults->{$m_name} = shift @_;
+ } else {
+ if ( $m_name eq '' ) {
+ # '--' => { param => value ... }
+ %$defaults = ( %$defaults, %{ shift @_ } );
+
+ } elsif ( exists $mm_def->{'interface'}{$m_name} ) {
+ # --interface
+ $defaults->{'interface'} = $m_name;
+
+ } elsif ( exists $mm_def->{'modifier'}{$m_name} ) {
+ # --modifier
+ $defaults->{'modifier'} .=
+ ( $defaults->{'modifier'} ? ' ' : '' ) . "-$m_name";
+
+ } elsif ( exists $mm_def->{'behavior'}{$m_name} ) {
+ # --behavior as shortcut for single-method interface
+ $defaults->{'interface'} = $m_name;
+
+ } else {
+ _diagnostic('make_bad_modifier', $mm_def->{'name'}, "--$m_name");
+ }
+ }
+ next;
+ }
+
+ # Make a new meta-method hash
+ my $m_info;
+
+ # Parse string, string-then-hash, and hash-only meta-method parameters
+ if ( ! ref $m_name ) {
+ if ( scalar @_ and ref $_[0] eq 'HASH' and ! exists $_[0]->{'name'} ) {
+ %$m_info = ( 'name' => $m_name, %{ shift @_ } );
+ } else {
+ $m_info = { 'name' => $m_name };
+ }
+
+ } elsif ( ref $m_name eq 'HASH' ) {
+ unless ( exists $m_name->{'name'} and length $m_name->{'name'} ) {
+ _diagnostic('make_noname');
+ }
+ $m_info = { %$m_name };
+
+ } else {
+ _diagnostic('make_unsupported', $m_name);
+ }
+ _diagnostic('debug_declaration', join(', ', map { defined $_ ? $_ : '(undef)' } %$m_info) );
+
+ ### INITIALIZATION ### Requires: $mm_def, $defaults, $m_info
+
+ my $interface = (
+ $interface_cache{ $m_info->{'interface'} || $defaults->{'interface'} }
+ ||= _interpret_interface( $mm_def, $m_info->{'interface'} || $defaults->{'interface'} )
+ );
+ %$m_info = (
+ %$defaults,
+ ( $interface->{-params} ? %{$interface->{-params}} : () ),
+ %$m_info
+ );
+
+
+ # warn "Actual: " . Dumper( $m_info );
+
+
+ # Expand * and *{...} strings.
+ foreach (grep defined $m_info->{$_}, keys %$m_info) {
+ $m_info->{$_} =~ s/\*(?:\{([^\}]+)?\})?/ $m_info->{ $1 || 'name' } /ge
+ }
+ if ( $m_info->{'modifier'} and $mm_def->{modifier}{-folding} ) {
+ $m_info->{'modifier'} = _fold_modifiers( $m_info->{'modifier'},
+ $mm_def->{modifier}{-folding} )
+ }
+
+ ### METHOD GENERATION ### Requires: $mm_def, $interface, $m_info
+
+ # If the MM def provides an initialization "-init" call, run it.
+ if ( local $_ = $mm_def->{'behavior'}->{'-init'} ) {
+ push @methods, map $_->( $m_info ), (ref($_) eq 'ARRAY') ? @$_ : $_;
+ }
+ # Build Methods
+ for ( grep { /^[^-]/ } keys %$interface ) {
+ my $function_name = $_;
+ $function_name =~ s/\*/$m_info->{'name'}/g;
+
+ my $behavior = $interface->{$_};
+
+ # Fold in additional modifiers
+ if ( $m_info->{'modifier'} ) {
+ if ( $behavior =~ /^\-/ and $mm_def->{modifier}{-folding} ) {
+ $behavior = $m_info->{'modifier'} =
+ _fold_modifiers( "$m_info->{'modifier'} $behavior",
+ $mm_def->{modifier}{-folding} )
+ } else {
+ $behavior = "$m_info->{'modifier'} $behavior";
+ }
+ }
+
+ my $builder =
+ ( $mm_def->{'-behavior_cache'}{$behavior} ) ?
+ $mm_def->{'-behavior_cache'}{$behavior} :
+ ( ref($mm_def->{'behavior'}{$behavior}) eq 'CODE' ) ?
+ $mm_def->{'behavior'}{$behavior} :
+_behavior_builder( $mm_def, $behavior, $m_info );
+
+ my $method = &$builder( $m_info );
+
+ _diagnostic('debug_make_behave', $behavior, $function_name, $method);
+ push @methods, ($function_name => $method) if ($method);
+ }
+
+ # If the MM def provides a "-subs" call, for forwarding and other
+ # miscelaneous "subsidiary" or "contained" methods, run it.
+ if ( my $subs = $mm_def->{'behavior'}->{'-subs'} ) {
+ my @subs = (ref($subs) eq 'ARRAY') ? @$subs : $subs;
+ foreach my $sub ( @subs ) {
+ my @results = $sub->($m_info);
+ if ( scalar @results == 1 and ref($results[0]) eq 'HASH' ) {
+ # If it returns a hash of helper method types, check the method info
+ # for any matching names and call the corresponding method generator.
+ my $types = shift @results;
+ foreach my $type ( keys %$types ) {
+ my $names = $m_info->{$type} or next;
+ my @names = ref($names) eq 'ARRAY' ? @$names : split(' ', $names);
+ my $generator = $types->{$type};
+ push @results, map { $_ => &$generator($m_info, $_) } @names;
+ }
+ }
+ push @methods, @results;
+ }
+ }
+
+ # If the MM def provides a "-register" call, for registering meta-method
+ # information for run-time access, run it.
+ if ( local $_ = $mm_def->{'behavior'}->{'-register'} ) {
+ push @methods, map $_->( $m_info ), (ref($_) eq 'ARRAY') ? @$_ : $_;
+ }
+ }
+
+ return @methods;
+}
+
+# I'd like for the make_methods() sub to be simpler, and to take advantage
+# of the standard _get_declarations parsing provided by the superclass.
+# Sadly the below doesn't work, due to a few order-of-operations peculiarities
+# of parsing interfaces and modifiers, and their associated default paramters.
+# Perhaps it might work if the processing of --options could be overridden with
+# a callback sub, so that interfaces and their params can be parsed in order.
+sub _x_get_declarations {
+ my $mm_def = shift;
+
+ my @declarations = $mm_def::SUPER->_get_declarations( @_ );
+
+ # use Data::Dumper;
+ # warn "In: " . Dumper( \@_ );
+ # warn "Auto: " . Dumper( \@declarations );
+
+ my %interface_cache;
+
+ while (scalar @declarations) {
+
+ my $m_info = shift @declarations;
+
+ # Parse interfaces and modifiers
+ my @specials = grep $_, split '--', ( delete $m_info->{'--'} || '' );
+ foreach my $special ( @specials ) {
+ if ( exists $mm_def->{'interface'}{$special} ) {
+ # --interface
+ $m_info->{'interface'} = $special;
+
+ } elsif ( exists $mm_def->{'modifier'}{$special} ) {
+ # --modifier
+ $m_info->{'modifier'} .=
+ ( $m_info->{'modifier'} ? ' ' : '' ) . "-$special";
+
+ } elsif ( exists $mm_def->{'behavior'}{$special} ) {
+ # --behavior as shortcut for single-method interface
+ $m_info->{'interface'} = $special;
+
+ } else {
+ _diagnostic('make_bad_modifier', $mm_def->{'name'}, "--$special");
+ }
+ }
+
+ my $interface = (
+ $interface_cache{ $m_info->{'interface'} }
+ ||= _interpret_interface( $mm_def, $m_info->{'interface'} )
+ );
+ $m_info = { %$m_info, %{$interface->{-params}} } if $interface->{-params};
+
+ _diagnostic('debug_declaration', join(', ', map { defined $_ ? $_ : '(undef)' } %$m_info) );
+
+ # warn "Updated: " . Dumper( $m_info );
+ }
+}
+
+########################################################################
+### TEMPLATES: _interpret_interface()
+########################################################################
+
+sub _interpret_interface {
+ my ($mm_def, $interface) = @_;
+
+ if ( ref $interface eq 'HASH' ) {
+ return $interface if exists $interface->{'-parsed'};
+ }
+ elsif ( ! defined $interface or ! length $interface ) {
+ _diagnostic('tmpl_empty');
+
+ }
+ elsif ( ! ref $interface ) {
+ if ( exists $mm_def->{'interface'}{ $interface } ) {
+ if ( ! ref $mm_def->{'interface'}{ $interface } ) {
+ $mm_def->{'interface'}{ $interface } =
+ { '*' => $mm_def->{'interface'}{ $interface } };
+ }
+ } elsif ( exists $mm_def->{'behavior'}{ $interface } ) {
+ $mm_def->{'interface'}{ $interface } = { '*' => $interface };
+ } else {
+ _diagnostic('tmpl_unkown', $interface);
+ }
+ $interface = $mm_def->{'interface'}{ $interface };
+
+ return $interface if exists $interface->{'-parsed'};
+ }
+ elsif ( ref $interface ne 'HASH' ) {
+ _diagnostic('tmpl_unsupported', $interface);
+ }
+
+ $interface->{'-parsed'} = "$_[1]";
+
+ # Allow interface inheritance via -base specification
+ if ( $interface->{'-base'} ) {
+ for ( split ' ', $interface->{'-base'} ) {
+ my $base = _interpret_interface( $mm_def, $_ );
+ %$interface = ( %$base, %$interface );
+ }
+ delete $interface->{'-base'};
+ }
+
+ for (keys %$interface) {
+ # Remove empty/undefined items.
+ unless ( defined $interface->{$_} and length $interface->{$_} ) {
+ delete $interface->{$_};
+ next;
+ }
+ }
+ # _diagnostic('debug_interface', $_[1], join(', ', %$interface ));
+
+ return $interface;
+}
+
+########################################################################
+### BEHAVIORS AND MODIFIERS: _fold_modifiers(), _behavior_builder()
+########################################################################
+
+sub _fold_modifiers {
+ my $spec = shift;
+ my $rules = shift;
+ my %rules = @$rules;
+
+ # Longest first, to prevent over-eager matching.
+ my $rule = join '|', map "\Q$_\E",
+ sort { length($b) <=> length($a) } keys %rules;
+ # Match repeatedly from the front.
+ 1 while ( $spec =~ s/($rule)/$rules{$1}/ );
+ $spec =~ s/(^|\s)\s/$1/g;
+ return $spec;
+}
+
+sub _behavior_builder {
+ my ( $mm_def, $behavior, $m_info ) = @_;
+
+ # We're going to have to do some extra work here, so we'll cache the result
+ my $builder;
+
+ # Separate the modifiers
+ my $core_behavior = $behavior;
+ my @modifiers;
+ while ( $core_behavior =~ s/\-(\w+)\s// ) { push @modifiers, $1 }
+
+ # Find either the built-in or universal behavior template
+ if ( $mm_def->{'behavior'}{$core_behavior} ) {
+ $builder = $mm_def->{'behavior'}{$core_behavior};
+ } else {
+ my $universal = _definition('Class::MakeMethods::Template::Universal','generic');
+ $builder = $universal->{'behavior'}{$core_behavior}
+ }
+
+ # Otherwise we're hosed.
+ $builder or _diagnostic('make_bad_behavior', $m_info->{'name'}, $behavior);
+
+ if ( ! ref $builder ) {
+ # If we've got a text template, pass it off for interpretation.
+ my $code = ( ! $Class::MakeMethods::Utility::DiskCache::DiskCacheDir ) ?
+ _interpret_text_builder($mm_def, $core_behavior, $builder, @modifiers)
+ : _disk_cache_builder($mm_def, $core_behavior, $builder, @modifiers);
+
+ # _diagnostic('debug_eval_builder', $name, $code);
+ local $^W unless $Class::MakeMethods::CONTEXT{Debug};
+ $builder = eval $code;
+ if ( $@ ) { _diagnostic('behavior_eval', $@, $code) }
+ unless (ref $builder eq 'CODE') { _diagnostic('behavior_eval', $@, $code) }
+
+ } elsif ( scalar @modifiers ) {
+ # Can't modify code subs
+ _diagnostic('make_behavior_mod', join(', ', @modifiers), $core_behavior);
+ }
+
+ $mm_def->{'-behavior_cache'}{$behavior} = $builder;
+
+ return $builder;
+}
+
+########################################################################
+### CODE EXPRESSIONS: _interpret_text_builder(), _disk_cache_builder()
+########################################################################
+
+sub _interpret_text_builder {
+ require Class::MakeMethods::Utility::TextBuilder;
+
+ my ( $mm_def, $name, $code, @modifiers ) = @_;
+
+ foreach ( @modifiers ) {
+ exists $mm_def->{'modifier'}{$_}
+ or _diagnostic('behavior_mod_unknown', $name, $_);
+ }
+
+ my @exprs = grep { $_ } map {
+ $mm_def->{'modifier'}{ $_ },
+ $mm_def->{'modifier'}{ "$_ $name" } || $mm_def->{'modifier'}{ "$_ *" }
+ } ( '-all', ( scalar(@modifiers) ? @modifiers : '-default' ) );
+
+ # Generic method template
+ push @exprs, "return sub _SUB_ATTRIBS_ { \n my \$self = shift;\n * }";
+
+ # Closure-generator
+ push @exprs, "sub { my \$m_info = \$_[0]; * }";
+
+ my $exprs = $mm_def->{code_expr};
+ unshift @exprs, {
+ ( map { $_=>$exprs->{$_} } grep /^[^-]/, keys %$exprs ),
+ '_BEHAVIOR_{}' => $mm_def->{'behavior'},
+ '_SUB_ATTRIBS_' => '',
+ };
+
+ my $result = Class::MakeMethods::Utility::TextBuilder::text_builder($code,
+ @exprs);
+
+ my $modifier_string = join(' ', map "-$_", @modifiers);
+ my $full_name = "$name ($mm_def->{template_class} $mm_def->{template_name}" .
+ ( $modifier_string ? " $modifier_string" : '' ) . ")";
+
+ _diagnostic('debug_template_builder', $full_name, $code, $result);
+
+ return $result;
+}
+
+sub _disk_cache_builder {
+ require Class::MakeMethods::Utility::DiskCache;
+ my ( $mm_def, $core_behavior, $builder, @modifiers ) = @_;
+
+ Class::MakeMethods::Utility::DiskCache::disk_cache(
+ "$mm_def->{template_class}::$mm_def->{template_name}",
+ join('.', $core_behavior, @modifiers),
+ \&_interpret_text_builder, ($mm_def, $core_behavior, $builder, @modifiers)
+ );
+}
+
+1;
+
+__END__
+
+
+=head1 NAME
+
+Class::MakeMethods::Template - Extensible code templates
+
+
+=head1 SYNOPSIS
+
+ package MyObject;
+ use Class::MakeMethods::Template::Hash (
+ 'new' => 'new',
+ 'string' => 'foo',
+ 'number' => 'bar',
+ );
+
+ my $obj = MyObject->new( foo => "Foozle", bar => 23 );
+ print $obj->foo();
+ $obj->bar(42);
+
+
+=head1 MOTIVATION
+
+If you compare the source code of some of the closure-generating
+methods provided by other subclasses of Class::MakeMethods,
+such as the C<hash> accessors provided by the various Standard::*
+subclasses, you will notice a fair amount of duplication. This
+module provides a way of assembling common pieces of code to
+facilitate support the maintenance of much larger libraries of
+generated methods.
+
+
+=head1 DESCRIPTION
+
+This module extends the Class::MakeMethods framework by providing
+an abstract superclass for extensible code-templating method
+generators.
+
+Common types of methods are generalized into B<template definitions>.
+For example, C<Template::Generic>'s C<new> provides a template for
+methods that create object instances, while C<Template::Generic>'s
+C<scalar> is a template for methods that allow you to get and set
+individual scalar values.
+
+Thse definitions are then re-used and modified by various B<template
+subclasses>. For example, the C<Template::Hash> subclass supports
+blessed-hash objects, while the C<Template::Global> subclass supports
+shared data; each of them includes an appropriate version of the
+C<scalar> accessor template for those object types.
+
+Each template defines one or more B<behaviors>, individual methods
+which can be installed in a calling package, and B<interfaces>,
+which select from those behaviours and indicate the names to install
+the methods under.
+
+Each individual meta-method defined by a calling package requires
+a B<method name>, and may optionally include other key-value
+B<parameters>, which can control the operation of some meta-methods.
+
+
+=head1 USAGE
+
+=head2 Class::MakeMethods Calling Conventions
+
+When you C<use> this package, the method declarations you provide
+as arguments cause subroutines to be generated and installed in
+your module.
+
+You can also omit the arguments to C<use> and instead make methods
+at runtime by passing the declarations to a subsequent call to
+C<make()>.
+
+You may include any number of declarations in each call to C<use>
+or C<make()>. If methods with the same name already exist, earlier
+calls to C<use> or C<make()> win over later ones, but within each
+call, later declarations superceed earlier ones.
+
+You can install methods in a different package by passing C<-TargetClass =E<gt> I<package>> as your first arguments to C<use> or C<make>.
+
+See L<Class::MakeMethods> for more details.
+
+=head2 Passing Parameters
+
+The following types of Basic declarations are supported:
+
+=over 4
+
+=item *
+
+I<generator_type> => "I<method_name>"
+
+=item *
+
+I<generator_type> => "I<name_1> I<name_2>..."
+
+=item *
+
+I<generator_type> => [ "I<name_1>", "I<name_2>", ...]
+
+=back
+
+See L<Class::MakeMethods::Docs::Catalog/"TEMPLATE CLASSES"> for a list of the supported values of I<generator_type>.
+
+For each method name you provide, a subroutine of the indicated
+type will be generated and installed under that name in your module.
+
+Method names should start with a letter, followed by zero or more
+letters, numbers, or underscores.
+
+=head2 Standard Declaration Syntax
+
+The Standard syntax provides several ways to optionally associate
+a hash of additional parameters with a given method name.
+
+=over 4
+
+=item *
+
+I<generator_type> => [ "I<name_1>" => { I<param>=>I<value>... }, ... ]
+
+A hash of parameters to use just for this method name.
+
+(Note: to prevent confusion with self-contained definition hashes,
+described below, parameter hashes following a method name must not
+contain the key 'name'.)
+
+=item *
+
+I<generator_type> => [ [ "I<name_1>", "I<name_2>", ... ] => { I<param>=>I<value>... } ]
+
+Each of these method names gets a copy of the same set of parameters.
+
+=item *
+
+I<generator_type> => [ { "name"=>"I<name_1>", I<param>=>I<value>... }, ... ]
+
+By including the reserved parameter C<name>, you create a self
+contained declaration with that name and any associated hash values.
+
+=back
+
+Basic declarations, as described above, are treated as having an empty parameter hash.
+
+=head2 Default Parameters
+
+A set of default parameters to be used for several declarations
+may be specified using any of the following types of arguments to
+a Template method generator call:
+
+=over 4
+
+=item *
+
+'-I<param>' => 'I<value>'
+
+Set a default value for the specified parameter.
+
+=item *
+
+'--' => { 'I<param>' => 'I<value>', ... }
+
+Set default values for one or more parameters. Equivalent to a series of '-I<param>' => 'I<value>' pairs for each pair in the referenced hash.
+
+=item *
+
+'--I<special_param_value>'
+
+Specifies a value for special parameter; the two supported parameter types are:
+
+=over 4
+
+=item -
+
+'--I<interface_name>'
+
+Select a predefined interface; equivalent to '-interface'=> 'I<interface_name>'.
+
+For more information about interfaces, see L<"Selecting Interfaces"> below.
+
+=item -
+
+'--I<modifier_name>'
+
+Select a global behavior modifier, such as '--private' or '--protected'.
+
+For more information about modifiers, see L<"Selecting Modifiers"> below.
+
+=back
+
+=back
+
+Parameters set in these ways are passed to each declaration that
+follows it until the end of the method-generator argument array,
+or until overridden by another declaration. Parameters specified
+in a hash for a specific method name, as discussed above, will
+override the defaults of the same name for that particular method.
+
+
+=head1 PARAMETER REFERENCE
+
+Each meta-method is allocated a hash in which to store its parameters
+and optional information.
+
+(Note that you can not override parameters on a per-object level.)
+
+=head2 Special Parameters
+
+The following parameters are pre-defined or have a special meaning:
+
+=over 4
+
+=item *
+
+name
+
+The primary name of the meta-method. Note that the subroutines
+installed into the calling package may be given different names,
+depending on the rules specified by the interface.
+
+=item *
+
+interface
+
+The name of a predefined interface, or a reference to a custom
+interface, to use for this meta-method. See L</Selecting Interfaces>, below.
+
+=item *
+
+modifier
+
+The names of one or more predefined modifier flags. See L</Selecting Modifiers>, below.
+
+=back
+
+=head2 Informative Parameters
+
+The following parameters are set automatically when your meta-method is declared:
+
+=over 4
+
+=item *
+
+target_class
+
+The class that requested the meta-method, into which its subroutines
+will be installed.
+
+=item *
+
+template_name
+
+The Class::MakeMethods::Template method used for this declaration.
+
+=item *
+
+template_class
+
+The Class::MakeMethods::Template subclass used for this declaration.
+
+=back
+
+=head2 Other Parameters
+
+Specific subclasses and template types provide support for additional
+parameters.
+
+Note that you generally should not arbitrarily assign additional
+parameters to a meta-method unless you know that they do not conflict
+with any parameters already defined or used by that meta-method.
+
+
+=head2 Parameter Expansion
+
+If a parameter specification contains '*', it is replaced with
+the primary method name.
+
+Example: The following defines counter (*, *_incr, *_reset)
+meta-methods j and k, which use the hash keys j_index and k_index
+to fetch and store their values.
+
+ use Class::MakeMethods::Template::Hash
+ counter => [ '-hash_key' => '*_index', qw/ j k / ];
+
+(See L<Class::MakeMethods::Template::Hash> for information about the C<hash_key> parameter.)
+
+If a parameter specification contains '*{I<param>}', it is replaced
+with the value of that parameter.
+
+Example: The following defines a Hash scalar meta-method which will
+store its value in a hash key composed of the defining package's
+name and individual method name, such as
+C<$self-E<gt>{I<MyObject>-I<foo>}>:
+
+ use Class::MakeMethods::Template::Hash
+ 'scalar' => [ '-hash_key' => '*{target_class}-*{name}', qw/ l / ];
+
+
+=head2 Selecting Interfaces
+
+Each template provides one or more predefined interfaces, each of which specifies one or more methods to be installed in your package, and the method names to use. Check the documentation for specific templates for a list of
+which interfaces they define.
+
+An interface may be specified for a single method by providing an
+'interface' parameter:
+
+=over 4
+
+=item *
+
+'I<interface_name>'
+
+Select a predefined interface.
+
+Example: Instead of the normal Hash scalar method named x, the
+following creates methods with "Java-style" names and behaviors,
+getx and setx.
+
+ use Class::MakeMethods::Template::Hash
+ 'scalar' => [ 'x' => { interface=>'java' } ];
+
+(See L<Class::MakeMethods::Template::Generic/"scalar"> for a
+description of the C<java> interface.)
+
+=item *
+
+'I<behavior_name>'
+
+A simple interface consisting only of the named behavior.
+
+For example, the below declaration creates a read-only methods named q. (There
+are no set or clear methods, so any value would have to be placed
+in the hash by other means.)
+
+ use Class::MakeMethods::Template::Hash (
+ 'scalar' => [ 'q' => { interface=>'get' } ]
+ );
+
+=item *
+
+{ 'I<subroutine_name_pattern>' => 'I<behavior_name>', ... }
+
+A custom interface consists of a hash-ref that maps subroutine names to the associated behaviors. Any C<*> characters in I<subroutine_name_pattern> are replaced with the declared method name.
+
+For example, the below delcaration creates paired get_w and set_w methods:
+
+ use Class::MakeMethods::Template::Hash (
+ 'scalar' => [ 'w' => { interface=> { 'get_*'=>'get', 'set_*'=>'set' } } ]
+ );
+
+=back
+
+Some interfaces provide very different behaviors than the default
+interface.
+
+Example: The following defines a method g, which if called with an
+argument appends to, rather than overwriting, the current value:
+
+ use Class::MakeMethods::Template::Hash
+ 'string' => [ '--get_concat', 'g' ];
+
+A named interface may also be specified as a default in the argument
+list with a leading '--' followed by the interface's name.
+
+Example: Instead of the normal Hash scalar methods (named x and
+clear_x), the following creates methods with "Java-style" names
+and behaviors (getx, setx).
+
+ use Class::MakeMethods::Template::Hash
+ 'scalar' => [ '--java', 'x' ];
+
+An interface set in this way affects all meta-methods that follow it
+until another interface is selected or the end of the array is
+reached; to return to the original names request the 'default'
+interface.
+
+Example: The below creates "Java-style" methods for e and f, "normal
+scalar" methods for g, and "Eiffel-style" methods for h.
+
+ use Class::MakeMethods::Template::Hash
+ 'scalar' => [
+ '--java'=> 'e', 'f',
+ '--default'=> 'g',
+ '--eiffel'=> 'h',
+ ];
+
+
+=head2 Selecting Modifiers
+
+You may select modifiers, which will affect all behaviors.
+
+ use Class::MakeMethods::Template::Hash
+ 'scalar' => [ 'a', '--protected' => 'b', --private' => 'c' ];
+
+Method b croaks if it's called from outside of the current package
+or its subclasses.
+
+Method c croaks if it's called from outside of the current package.
+
+See the documentation for each template to learn which modifiers it supports.
+
+
+=head2 Runtime Parameter Access
+
+If the meta-method is defined using an interface which includes the
+attributes method, run-time access to meta-method parameters is
+available.
+
+Example: The following defines a counter meta-method named y, and
+then later changes the 'join' parameter for that method at runtime.
+
+ use Class::MakeMethods ( get_concat => 'y' );
+
+ y_attributes(undef, 'join', "\t" )
+ print y_attributes(undef, 'join')
+
+
+=head1 EXTENDING
+
+You can create your own method-generator templates by following the below outline.
+
+
+=head2 Mechanisms
+
+Dynamic generation of methods in Perl generally depends on one of two approaches: string evals, which can be as flexible as your string-manipulation functions allow, but are run-time resource intensive; or closures, which are limited by the number of subroutine constructors you write ahead of time but which are faster and smaller than evals.
+
+Class::MakeMethods::Template uses both of these approaches: To generate different types of subroutines, a simple text-substitution mechanism combines bits of Perl to produce the source code for a subroutine, and then evals those to produce code refs. Any differences which can be handled with only data changes are managed at the closure layer; once the subroutines are built, they are repeatedly bound as closures to hashes of parameter data.
+
+=head2 Code Generation
+
+A substitution-based "macro language" is used to assemble code strings. This happens only once per specific subclass/template/behavior combination used in your program. (If you have disk-caching enabled, the template interpretation is only done once, and then saved; see below.)
+
+There are numerous examples of this within the Generic interface and its subclasses; for examples, look at the following methods: Universal:generic, Generic:scalar, Hash:generic, and Hash:scalar.
+
+See L<Class::MakeMethods::Utility::TextBuilder> for more information.
+
+
+=head2 Template Definitions
+
+Template method generators are declared by creating a subroutine that returns a hash-ref of information about the template. When these subroutines are first called, the template information is filled in with imported and derived values, blessed as a Class::MakeMethods::Template object, and cached.
+
+Each C<use> of your subclass, or call to its C<make>, causes these objects to assemble the requested methods and return them to Class::MakeMethods for installation in the calling package.
+
+Method generators defined this way will have support for parameters, custom interfaces, and the other features discussed above.
+
+(Your module may also use the "Aliasing" and "Rewriting" functionality described in L<Class::MakeMethods/EXTENDING>.)
+
+Definition hashes contain several types of named resources in a second level of hash-refs under the following keys:
+
+=over 4
+
+=item *
+
+interface - Naming styles (see L<"Defining Interfaces">, below)
+
+=item *
+
+params - Default parameters for meta-methods declared with this template (see L<"Default Parameters">, below)
+
+=item *
+
+behavior - Method recipes (see L<"Defining Behaviors">, below)
+
+=item *
+
+code_expr - Bits of code used by the behaviors
+
+=back
+
+=head2 Minimum Template Definition
+
+You must at least specify one behavior; all other information is optional.
+
+Class::MakeMethods will automatically fill in the template name and class
+as 'template_name' and 'template_class' entries in the version of your
+template definition hash that it caches and uses for future execution.
+
+For example a simple sub-class that defines a method type
+upper_case_get_set might look like this:
+
+ package Class::MakeMethods::UpperCase;
+ use Class::MakeMethods '-isasubclass';
+
+ sub uc_scalar {
+ return {
+ 'behavior' => {
+ 'default' => sub {
+ my $m_info = $_[0];
+ return sub {
+ my $self = shift;
+ if ( scalar @_ ) {
+ $self->{ $m_info->{'name'} } = uc( shift )
+ } else {
+ $self->{ $m_info->{'name'} };
+ }
+ }
+ },
+ }
+ }
+ }
+
+And a caller could then use it to generate methods in their package by invoking:
+
+ Class::MakeMethods::UpperCase->make( 'uc_scalar' => [ 'foo' ] );
+
+=head2 Default Parameters
+
+Each template may include a set of default parameters for all declarations as C<params =E<gt> I<hash_ref>>.
+
+Template-default parameters can be overrridden by interface '-params', described below, and and method-specific parameters, described above.
+
+=head2 Defining Interfaces
+
+Template definitions may have one or more interfaces, including
+the default one, named 'default', which is automatically selected
+if another interface is not requested. (If no default interface is
+provided, one is constructed, which simply calls for a behavior
+named default.)
+
+Most commonly, an interface is specified as a hash which maps one or
+more subroutine names to the behavior to use for each. The interface
+subroutine names generally contain an asterisk character, '*', which
+will be replaced by the name of each meta-method.
+
+Example: The below defines methods e_get, e_set, and e_clear.
+
+ use Class::MakeMethods::Template::Hash
+ 'scalar' => [
+ -interface=>{ '*_clear'=>clear, '*_get'=>'get', '*_set'=>'set' }, 'e'
+ ];
+
+If the provided name does not contain an asterisk, it will not be
+modified for individual meta-methods; for examples, see the bit_fields
+method generated by Generic bits, and the DESTROY method generated
+by InsideOut meta-methods.
+
+In addition to the name-to-behavior correspondences described above,
+interfaces may also contain additional entries with keys begining
+with the '-' character which are interpreted as follows:
+
+=over 4
+
+=item *
+
+C<-params =E<gt> I<hash_ref>>
+
+Interfaces may include a '-params' key and associated reference
+to a hash of default parameters for that interface.
+
+=item *
+
+C<-base =E<gt> I<interface_name>>
+
+Interfaces can be based on previously existing ones by including
+a -base specification in the the hash. The base value should contain
+one or more space-separated names of the interfaces to be included.
+
+Example: The below defines methods getG, setG, and clearG.
+
+ use Class::MakeMethods::Template::Hash
+ 'scalar' => [
+ -interface => { -base=>'java', 'clear*'=>'clear' }, qw/ G /
+ ];
+
+If multiple interfaces are included in the -base specification and
+specify different behaviors for the same subroutine name, the later
+ones will override the earlier. Names which appear in the base
+interface can be overridden by providing a new value, or a name
+can be removed by mapping it to undef or the empty string.
+
+Example: The following defines a get-set meta-method h, but supresses
+the clear_h method:
+
+ use Class::MakeMethods::Template::Hash
+ 'scalar' => [
+ -interface => { -base=>'with_clear', 'clear_*'=>'' }, qw/ h /
+ ];
+
+=back
+
+
+=head2 Defining Behaviors
+
+Behaviors can be provided as text which is eval'd to form a
+closure-generating subroutine when it's first used; C<$self> is
+automatically defined and assigned the value of the first argument.
+
+ 'behavior' => {
+ 'default' => q{
+ if ( scalar @_ ) { $self->{ $m_info->{'name'} } = uc shift }
+ $self->{ $m_info->{'name'} };
+ },
+ }
+
+A simple substitution syntax provides for macro interpretation with
+definition strings. This functionality is currently undocumented;
+for additional details see the _interpret_text_builder function in
+Class::MakeMethods, and review the code_expr hashes defined in
+Class::MakeMethods::Generic.
+
+
+=head2 Importing
+
+You can copy values out of other template definitions by specifying
+an '-import' key and corresponding hash reference. You can specify
+an -import for inside any of the template definition sub-hashes.
+If no -import is specified for a subhash, and there is a top-level
+-import value, it is used instead.
+
+Inside an -import hash, provide C<I<TemplateClass>:I<type>> names
+for each source you wish to copy from, and the values to import,
+which can be a string, a reference to an array of strings, or '*'
+to import everything available. (The order of copying is not
+defined.)
+
+Example: The below definition creates a new template
+which is identical to an existing one.
+
+ package Class::MakeMethods::MyMethods;
+ sub scalarama {
+ { -import => { 'Template::Hash:scalar' => '*' } }
+ }
+
+Values that are already set are not modified, unless they're an
+array ref, in which case they're added to.
+
+Example:
+
+ package Class::MakeMethods::MyMethods;
+ sub foo_method {
+ { 'behavior' => {
+ '-init' => [ sub { warn "Defining foo_method $_[0]->{'name'}" } ],
+ 'default' => q{ warn "Calling foo_method behavior" }.
+ } }
+ }
+ sub bar_method {
+ { 'behavior' => {
+ -import => { 'MyMethods:foo_method' => '*' },
+ '-init' => [ sub { warn "Defining bar_method $_[0]->{'name'}" } ],
+ 'default' => q{ warn "Calling bar_method behavior" }.
+ } }
+ }
+
+In this case, the bar_method ends up with an array of two '-init'
+subroutines, its own and the imported one, but only its own default
+behavior.
+
+
+
+=head2 Modifying Existing Templates
+
+You can over-write information contained in template definitions
+to alter their subsequent behavior.
+
+Example: The following extends the Hash:scalar template definition
+by adding a new interface, and then uses it to create scalar accessor
+methods named access_p and access_q that get and set values for
+the hash keys 'p' and 'q':
+
+ Class::MakeMethods::Template::Hash->named_method('scalar')->
+ {'interface'}{'frozzle'} = { 'access_*'=>'get_set' };
+
+ package My::Object;
+ Class::MakeMethods::Template::Hash->make( 'scalar' => [ --frozzle => qw( p q ) ] );
+
+ $object->access_p('Potato'); # $object->{p} = 'Potato'
+ print $object->access_q(); # print $object->{q}
+
+
+Note that this constitutes "action at a distance" and will affect subsequent use by other packages; unless you are "fixing" the current behavior, you are urged to create your own template definition which imports the base behavior of the existing template and overrides the information in question.
+
+Example: The following safely declares a new version of Hash:scalar with the desired additional interface:
+
+ package My::Methods;
+
+ sub scalar {
+ {
+ -import => { 'Template::Hash:scalar' => '*' } ,
+ interface => { 'frozzle' => { 'access_*'=>'get_set' } },
+ }
+ }
+
+ package My::Object;
+ My::Methods->make( 'scalar' => [ --frozzle => qw( p q ) ] );
+
+
+=cut
+
+=head2 Disk Caching
+
+To enable disk caching of generated code, create an empty directory and pass it to the DiskCache package:
+
+ use Class::MakeMethods::Utility::DiskCache qw( /my/code/dir );
+
+This has a mixed effect on performance, but has the notable advantage of letting you view the subroutines that are being generated by your templates.
+
+See L<Class::MakeMethods::Utility::DiskCache> for more information.
+
+
+=head1 SEE ALSO
+
+See L<Class::MakeMethods> for general information about this distribution.
+
+See L<Class::MakeMethods::Examples> for some illustrations of what you can do with this package.
+
+For distribution, installation, support, copyright and license
+information, see L<Class::MakeMethods::Docs::ReadMe>.
+
+=cut
diff --git a/lib/Class/MakeMethods/Template/Array.pm b/lib/Class/MakeMethods/Template/Array.pm
new file mode 100644
index 0000000..0d2ab2d
--- /dev/null
+++ b/lib/Class/MakeMethods/Template/Array.pm
@@ -0,0 +1,102 @@
+package Class::MakeMethods::Template::Array;
+
+use Class::MakeMethods::Template::Generic '-isasubclass';
+
+$VERSION = 1.008;
+use strict;
+require 5.00;
+use Carp;
+
+=head1 NAME
+
+Class::MakeMethods::Template::Array - Methods for manipulating positional values in arrays
+
+=head1 SYNOPSIS
+
+
+=head1 DESCRIPTION
+
+=cut
+
+use vars qw( %ClassInfo );
+
+sub generic {
+ {
+ 'params' => {
+ 'array_index' => undef,
+ },
+ 'code_expr' => {
+ _VALUE_ => '_SELF_->[_STATIC_ATTR_{array_index}]',
+ '-import' => { 'Template::Generic:generic' => '*' },
+ _EMPTY_NEW_INSTANCE_ => 'bless [], _SELF_CLASS_',
+ _SET_VALUES_FROM_HASH_ => 'while ( scalar @_ ) { local $_ = shift(); $self->[ _BFP_FROM_NAME_{ $_ } ] = shift() }'
+ },
+ 'behavior' => {
+ '-init' => sub {
+ my $m_info = $_[0];
+
+ # If we're the first one,
+ if ( ! $ClassInfo{$m_info->{target_class}} ) {
+ # traverse inheritance hierarchy, looking for fields to inherit
+ my @results;
+ no strict 'refs';
+ my @sources = @{"$m_info->{target_class}\::ISA"};
+ while ( my $class = shift @sources ) {
+ next unless exists $ClassInfo{ $class };
+ push @sources, @{"$class\::ISA"};
+ if ( scalar @results ) {
+ Carp::croak "Too many inheritances of fields";
+ }
+ push @results, @{$ClassInfo{$class}};
+ }
+ $ClassInfo{$m_info->{target_class}} = \@sources;
+ }
+
+ my $class_info = $ClassInfo{$m_info->{target_class}};
+ if ( ! defined $m_info->{array_index} ) {
+ foreach ( 0..$#$class_info ) {
+ if ( $class_info->[$_] eq $m_info->{'name'} ) {
+ $m_info->{array_index} = $_; last }
+ }
+ if ( ! defined $m_info->{array_index} ) {
+ push @ $class_info, $m_info->{'name'};
+ $m_info->{array_index} = $#$class_info;
+ }
+ }
+
+ return;
+ },
+ },
+ }
+}
+
+########################################################################
+
+=head2 Standard Methods
+
+The following methods from Generic should be supported:
+
+ scalar
+ string
+ number
+ boolean
+ bits (?)
+ array
+ hash
+ tiedhash (?)
+ hash_of_arrays (?)
+ object
+ instance
+ array_of_objects (?)
+ code
+ code_or_scalar (?)
+
+See L<Class::MakeMethods::Template::Generic> for the interfaces and behaviors of these method types.
+
+The items marked with a ? above have not been tested sufficiently; please inform the author if they do not function as you would expect.
+
+=cut
+
+########################################################################
+
+1;
diff --git a/lib/Class/MakeMethods/Template/Class.pm b/lib/Class/MakeMethods/Template/Class.pm
new file mode 100644
index 0000000..c846709
--- /dev/null
+++ b/lib/Class/MakeMethods/Template/Class.pm
@@ -0,0 +1,103 @@
+package Class::MakeMethods::Template::Class;
+
+use Class::MakeMethods::Template::Generic '-isasubclass';
+
+$VERSION = 1.008;
+use strict;
+require 5.0;
+use Carp;
+
+=head1 NAME
+
+Class::MakeMethods::Template::Class - Associate information with a package
+
+=head1 SYNOPSIS
+
+ package MyObject;
+ use Class::MakeMethods::Template::Class (
+ scalar => [ 'foo' ]
+ );
+
+ package main;
+
+ MyObject->foo('bar')
+ print MyObject->foo();
+
+=head1 DESCRIPTION
+
+These meta-methods provide access to class-specific values. They are similar to Static, except that each subclass has separate values.
+
+=cut
+
+sub generic {
+ {
+ '-import' => {
+ 'Template::Generic:generic' => '*'
+ },
+ 'modifier' => {
+ },
+ 'code_expr' => {
+ '_VALUE_' => '_ATTR_{data}->{_SELF_CLASS_}',
+ },
+ }
+}
+
+########################################################################
+
+=head2 Class:scalar
+
+Creates methods to handle a scalar variable in the declaring package.
+
+See the documentation on C<Generic:scalar> for interfaces and behaviors.
+
+=cut
+
+########################################################################
+
+=head2 Class:array
+
+Creates methods to handle a array variable in the declaring package.
+
+See the documentation on C<Generic:array> for interfaces and behaviors.
+
+=cut
+
+sub array {
+ {
+ '-import' => {
+ 'Template::Generic:array' => '*',
+ },
+ 'modifier' => {
+ '-all' => q{ _REF_VALUE_ or @{_ATTR_{data}->{_SELF_CLASS_}} = (); * },
+ },
+ 'code_expr' => {
+ '_VALUE_' => '\@{_ATTR_{data}->{_SELF_CLASS_}}',
+ },
+ }
+}
+
+########################################################################
+
+=head2 Class:hash
+
+Creates methods to handle a hash variable in the declaring package.
+
+See the documentation on C<Generic:hash> for interfaces and behaviors.
+
+=cut
+
+sub hash {
+ {
+ '-import' => {
+ 'Template::Generic:hash' => '*',
+ },
+ 'modifier' => {
+ '-all' => q{ _REF_VALUE_ or %{_ATTR_{data}->{_SELF_CLASS_}} = (); * },
+ },
+ 'code_expr' => {
+ '_VALUE_' => '\%{_ATTR_{data}->{_SELF_CLASS_}}',
+ },
+ }
+}
+
+1;
diff --git a/lib/Class/MakeMethods/Template/ClassInherit.pm b/lib/Class/MakeMethods/Template/ClassInherit.pm
new file mode 100644
index 0000000..9c61393
--- /dev/null
+++ b/lib/Class/MakeMethods/Template/ClassInherit.pm
@@ -0,0 +1,144 @@
+=head1 NAME
+
+Class::MakeMethods::Template::ClassInherit - Overridable class data
+
+=head1 SYNOPSIS
+
+ package MyClass;
+
+ use Class::MakeMethods( 'Template::ClassInherit:scalar' => 'foo' );
+ # We now have an accessor method for an "inheritable" scalar value
+
+ package main;
+
+ MyClass->foo( 'Foozle' ); # Set a class-wide value
+ print MyClass->foo(); # Retrieve class-wide value
+ ...
+
+ package MySubClass;
+ @ISA = 'MyClass';
+
+ print MySubClass->foo(); # Intially same as superclass,
+ MySubClass->foo('Foobar'); # but overridable per subclass/
+
+=head1 DESCRIPTION
+
+The MakeMethods subclass provides accessor methods that search an inheritance tree to find a value. This allows you to set a shared or default value for a given class, and optionally override it in a subclass.
+
+=cut
+
+########################################################################
+
+package Class::MakeMethods::Template::ClassInherit;
+
+use Class::MakeMethods::Template::Generic '-isasubclass';
+
+$VERSION = 1.008;
+use strict;
+require 5.0;
+use Carp;
+
+sub generic {
+ {
+ '-import' => {
+ 'Template::Generic:generic' => '*'
+ },
+ 'modifier' => {
+ '-all' => [ q{
+ _INIT_VALUE_CLASS_
+ *
+ } ],
+ },
+ 'code_expr' => {
+ '_VALUE_CLASS_' => '$_value_class',
+ '_INIT_VALUE_CLASS_' => q{
+ my _VALUE_CLASS_;
+ for ( my @_INC_search = _SELF_CLASS_; scalar @_INC_search; ) {
+ _VALUE_CLASS_ = shift @_INC_search;
+ last if ( exists _ATTR_{data}->{_VALUE_CLASS_} );
+ no strict 'refs';
+ unshift @_INC_search, @{"_VALUE_CLASS_\::ISA"};
+ }
+ },
+ '_VALUE_' => '_ATTR_{data}->{_VALUE_CLASS_}',
+ '_GET_VALUE_' => q{ _ATTR_{data}->{_VALUE_CLASS_} },
+ '_SET_VALUE_{}' => q{ ( _VALUE_CLASS_ = _SELF_CLASS_ and _ATTR_{data}->{_VALUE_CLASS_} = * ) },
+ },
+ }
+}
+
+########################################################################
+
+=head2 Standard Methods
+
+The following methods from Generic should all be supported:
+
+ scalar
+ string
+ string_index (?)
+ number
+ boolean
+ bits (?)
+ array (*)
+ hash (*)
+ tiedhash (?)
+ hash_of_arrays (?)
+ object (?)
+ instance (?)
+ array_of_objects (?)
+ code (?)
+ code_or_scalar (?)
+
+See L<Class::MakeMethods::Template::Generic> for the interfaces and behaviors of these method types.
+
+The items marked with a * above are specifically defined in this package, whereas the others are formed automatically by the interaction of this package's generic settings with the code templates provided by the Generic superclass.
+
+The items marked with a ? above have not been tested sufficiently; please inform the author if they do not function as you would expect.
+
+=cut
+
+sub array {
+ {
+ '-import' => {
+ 'Template::Generic:array' => '*',
+ },
+ 'modifier' => {
+ '-all' => [ q{ _VALUE_ ||= []; * } ],
+ },
+ 'code_expr' => {
+ '_VALUE_' => '\@{_ATTR_{data}->{_SELF_CLASS_}}',
+ },
+ }
+}
+
+sub hash {
+ {
+ '-import' => {
+ 'Template::Generic:hash' => '*',
+ },
+ 'modifier' => {
+ '-all' => [ q{ _VALUE_ ||= {}; * } ],
+ },
+ 'code_expr' => {
+ '_VALUE_' => '\%{_ATTR_{data}->{_SELF_CLASS_}}',
+ },
+ }
+}
+
+########################################################################
+
+=head1 SEE ALSO
+
+See L<Class::MakeMethods> for general information about this distribution.
+
+See L<Class::MakeMethods::Template> for more about this family of subclasses.
+
+See L<Class::MakeMethods::Template::Generic> for information about the various accessor interfaces subclassed herein.
+
+If you just need scalar accessors, see L<Class::Data::Inheritable> for a very elegant and efficient implementation.
+
+=cut
+
+########################################################################
+
+1;
diff --git a/lib/Class/MakeMethods/Template/ClassName.pm b/lib/Class/MakeMethods/Template/ClassName.pm
new file mode 100644
index 0000000..c37433f
--- /dev/null
+++ b/lib/Class/MakeMethods/Template/ClassName.pm
@@ -0,0 +1,330 @@
+package Class::MakeMethods::Template::ClassName;
+
+use Class::MakeMethods::Template '-isasubclass';
+$VERSION = 1.008;
+
+sub _diagnostic { &Class::MakeMethods::_diagnostic }
+
+########################################################################
+###### CLASS NAME MANIPULATIONS
+########################################################################
+
+=head1 NAME
+
+Class::MakeMethods::Template::ClassName - Access object's class
+
+=head1 SYNOPSIS
+
+ package MyObject;
+ use Class::MakeMethods::Template::ClassName (
+ subclass_name => [ 'type' ]
+ );
+ ...
+ package main;
+ my $object = MyObject->new;
+
+ $object->type('Foo')
+ # reblesses object to MyObject::Foo subclass
+
+ print $object->type();
+ # prints "Foo".
+
+=head1 DESCRIPTION
+
+These method types access or change information about the class an object is associated with.
+
+=head2 class_name
+
+Called without arguments, returns the class name.
+
+If called with an argument, reblesses object into that class.
+If the class doesn't already exist, it will be created.
+
+=head2 subclass_name
+
+Called without arguments, returns the subclass name.
+
+If called with an argument, reblesses object into that subclass.
+If the subclass doesn't already exist, it will be created.
+
+The subclass name is written as follows:
+
+=over 4
+
+=item *
+
+if it's the original, defining class: empty
+
+=item *
+
+if its a a package within the namespace of the original: the distingushing name within that namespace, without leading C<::>
+
+=item *
+
+if it's a package elsewhere: the full name with leading C<::>
+
+=back
+
+=cut
+
+# $subclass = _pack_subclass( $base, $pckg );
+sub _pack_subclass {
+ my $base = shift;
+ my $pckg = shift;
+
+ ( $pckg eq $base ) ? '' :
+ ( $pckg =~ s/^\Q$base\E\:\:// ) ? $pckg :
+ "::$pckg";
+}
+
+# $pckg = _unpack_subclass( $base, $subclass );
+sub _unpack_subclass {
+ my $base = shift;
+ my $subclass = shift;
+
+ ! $subclass ? $base :
+ ( $subclass =~ s/^::// ) ? $subclass :
+ "$base\::$subclass";
+}
+
+# $pckg = _require_class( $package );
+sub _require_class {
+ my $package = shift;
+
+ no strict 'refs';
+ unless ( @{$package . '::ISA'} ) {
+ (my $file = $package . '.pm' ) =~ s|::|/|go;
+ local $SIG{__DIE__} = sub { die @_ };
+ # warn "Auto-requiring package $package \n";
+ eval { require $file };
+ if ( $@ ) { _diagnostic('mm_package_fail', $package, $@) }
+ }
+
+ return $package;
+}
+
+# $pckg = _provide_class( $base, $package );
+sub _provide_class {
+ my $base = shift;
+ my $package = shift;
+
+ # If the subclass hasn't been created yet, do so.
+ no strict 'refs';
+ unless ( scalar @{$package . '::ISA'} ) {
+ # warn "Auto-vivifying $base subclass $package\n";
+ @{$package . '::ISA'} = ( $base );
+ }
+
+ return $package;
+}
+
+sub class_name {
+ {
+ 'interface' => {
+ default => 'autocreate',
+ autocreate => { '*'=>'autocreate' },
+ require => { '*'=>'require' },
+ },
+ 'behavior' => {
+ 'autocreate' => q{
+ if ( ! scalar @_ ) {
+ _CLASS_GET_
+ } else {
+ _CLASS_PROVIDE_
+ }
+ },
+ 'require' => q{
+ if ( ! scalar @_ ) {
+ _CLASS_GET_
+ } else {
+ _CLASS_REQUIRE_
+ }
+ },
+ },
+ 'code_expr' => {
+ _CLASS_GET_ => q{
+ my $class = ref $self || $self;
+ },
+ _CLASS_REQUIRE_ => q{
+ my $class = Class::MakeMethods::Template::ClassName::_require_class( shift() );
+ _BLESS_AND_RETURN_
+ },
+ _CLASS_PROVIDE_ => q{
+ my $class = Class::MakeMethods::Template::ClassName::_provide_class(
+ $m_info->{'target_class'}, shift() );
+ _BLESS_AND_RETURN_
+ },
+ _BLESS_AND_RETURN_ => q{
+ bless $self, $class if ( ref $self );
+ return $class;
+ },
+ },
+ }
+}
+
+sub subclass_name {
+ {
+ '-import' => {
+ 'Template::ClassName:class_name' => '*',
+ },
+ 'code_expr' => {
+ _CLASS_GET_ => q{
+ my $class = ref $self || $self;
+ Class::MakeMethods::Template::ClassName::_pack_subclass( $m_info->{'target_class'}, $class )
+ },
+ _CLASS_REQUIRE_ => q{
+ my $subclass = Class::MakeMethods::Template::ClassName::_unpack_subclass(
+ $m_info->{'target_class'}, shift() );
+ my $class = Class::MakeMethods::Template::ClassName::_require_class($subclass);
+ _BLESS_AND_RETURN_
+ },
+ _CLASS_PROVIDE_ => q{
+ my $subclass = Class::MakeMethods::Template::ClassName::_unpack_subclass(
+ $m_info->{'target_class'}, shift() );
+ my $class = Class::MakeMethods::Template::ClassName::_provide_class(
+ $m_info->{'target_class'}, $subclass );
+ _BLESS_AND_RETURN_
+ },
+ },
+ }
+}
+
+
+########################################################################
+### CLASS_REGISTRY
+
+=head2 static_hash_classname
+
+Provides a shared hash mapping keys to class names.
+
+ class_registry => [ qw/ foo / ]
+
+Takes a single string or a reference to an array of strings as its argument.
+For each string, creates a new anonymous hash and associated accessor methods
+that will map scalar values to classes in the calling package's subclass
+hiearchy.
+
+The accessor methods provide an interface to the hash as illustrated below.
+Note that several of these functions operate quite differently depending on the
+number of arguments passed, or the context in which they are called.
+
+=over 4
+
+=item @indexes = $class_or_ref->x;
+
+Returns the scalar values that are indexes associated with this class, or the class of this object.
+
+=item $class = $class_or_ref->x( $index );
+
+Returns the class name associated with the provided index value.
+
+=item @classes = $class_or_ref->x( @indexes );
+
+Returns the associated classes for each index in order.
+
+=item @all_indexes = $class_or_ref->x_keys;
+
+Returns a list of the indexes defined for this registry.
+
+=item @all_classes = $class_or_ref->x_values;
+
+Returns a list of the classes associated with this registry.
+
+=item @all_classes = $class_or_ref->unique_x_values;
+
+Returns a list of the classes associated with this registry, with no more than one occurance of any value.
+
+=item %mapping = $class_or_ref->x_hash;
+
+Return the key-value pairs used to store this attribute
+
+=item $mapping_ref = $class_or_ref->x_hash;
+
+Returns a reference to the hash used for the mapping.
+
+=item $class_or_ref->add_x( @indexes );
+
+Adds an entry in the hash for each of the provided indexes, mapping it to this class, or the class of this object.
+
+=item $class_or_ref->clear_x;
+
+Removes those entries from the hash whose values are this class, or the class of this object.
+
+=item $class_or_ref->clear_xs( @indexes );
+
+Remove all entries from the hash.
+
+=back
+
+=cut
+
+sub static_hash_classname {
+ {
+ '-import' => {
+ 'Template::Static:hash' => '*',
+ },
+ 'params' => { 'instance' => {} },
+ 'interface' => {
+ default => {
+ '*'=>'get_classname',
+ 'add_*'=>'add_classname',
+ 'clear_*'=>'drop_classname',
+ '*_keys'=>'keys',
+ '*_hash'=>'get',
+ '*_values'=>'values',
+ 'clear_*s'=>'clear',
+ 'unique_*_values'=>'unique_values',
+ },
+ },
+ 'behavior' => {
+ 'get_classname' => sub { my $m_info = $_[0]; sub {
+ my $self = shift;
+ my $class = ( ref($self) || $self );
+
+ defined $m_info->{'instance'} or $m_info->{'instance'} = {};
+ my $hash = $m_info->{'instance'};
+
+ if ( ! scalar @_ ) {
+ my @keys = grep { $hash->{$_} eq $class } keys %$hash;
+ return wantarray ? @keys : $keys[0];
+ } elsif (scalar @_ == 1) {
+ return $hash->{ shift() };
+ } else {
+ return @{$hash}{ @_ };
+ }
+ }},
+ 'add_classname' => sub { my $m_info = $_[0]; sub {
+ my $self = shift;
+ my $class = ( ref($self) || $self );
+
+ defined $m_info->{'instance'} or $m_info->{'instance'} = {};
+ my $hash = $m_info->{'instance'};
+
+ foreach ( @_ ) { $hash->{$_} = $class }
+ }},
+ 'drop_classname' => sub { my $m_info = $_[0]; sub {
+ my $self = shift;
+ my $class = ( ref($self) || $self );
+
+ defined $m_info->{'instance'} or $m_info->{'instance'} = {};
+ my $hash = $m_info->{'instance'};
+
+ foreach ( grep { $hash->{$_} eq $class } keys %$hash ){
+ delete $hash{$_}
+ }
+ }},
+ },
+ }
+}
+
+########################################################################
+
+=head1 SEE ALSO
+
+See L<Class::MakeMethods> for general information about this distribution.
+
+See L<Class::MakeMethods::Template> for information about this family of subclasses.
+
+=cut
+
+1;
diff --git a/lib/Class/MakeMethods/Template/ClassVar.pm b/lib/Class/MakeMethods/Template/ClassVar.pm
new file mode 100644
index 0000000..a5a2478
--- /dev/null
+++ b/lib/Class/MakeMethods/Template/ClassVar.pm
@@ -0,0 +1,178 @@
+package Class::MakeMethods::Template::ClassVar;
+
+use Class::MakeMethods::Template::Generic '-isasubclass';
+
+$VERSION = 1.008;
+use strict;
+require 5.0;
+use Carp;
+
+=head1 NAME
+
+Class::MakeMethods::Template::ClassVar - Static methods with subclass variation
+
+=head1 SYNOPSIS
+
+ package MyObject;
+ use Class::MakeMethods::Template::ClassVar (
+ scalar => [ 'foo' ]
+ );
+
+ package main;
+
+ MyObject->foo('bar')
+ print MyObject->foo();
+
+ $MyObject::foo = 'bazillion';
+ print MyObject->foo();
+
+=head1 DESCRIPTION
+
+These meta-methods provide access to package (class global) variables,
+with the package determined at run-time.
+
+This is basically the same as the PackageVar meta-methods, except
+that PackageVar methods find the named variable in the package that
+defines the method, while ClassVar methods use the package the object
+is blessed into. As a result, subclasses will each store a distinct
+value for a ClassVar method, but will share the same value for a
+PackageVar or Static method.
+
+B<Common Parameters>: The following parameters are defined for ClassVar meta-methods.
+
+=over 4
+
+=item variable
+
+The name of the variable to store the value in. Defaults to the same name as the method.
+
+=back
+
+=cut
+
+sub generic {
+ {
+ '-import' => {
+ 'Template::Generic:generic' => '*'
+ },
+ 'params' => {
+ 'variable' => '*'
+ },
+ 'modifier' => {
+ '-all' => [ q{ no strict; * } ],
+ },
+ 'code_expr' => {
+ '_VALUE_' => '${_SELF_CLASS_."::"._ATTR_{variable}}',
+ },
+ }
+}
+
+########################################################################
+
+=head2 Standard Methods
+
+The following methods from Generic should all be supported:
+
+ scalar
+ string
+ string_index (?)
+ number
+ boolean
+ bits (?)
+ array (*)
+ hash (*)
+ tiedhash (?)
+ hash_of_arrays (?)
+ object (?)
+ instance (?)
+ array_of_objects (?)
+ code (?)
+ code_or_scalar (?)
+
+See L<Class::MakeMethods::Template::Generic> for the interfaces and behaviors of these method types.
+
+The items marked with a * above are specifically defined in this package, whereas the others are formed automatically by the interaction of this package's generic settings with the code templates provided by the Generic superclass.
+
+The items marked with a ? above have not been tested sufficiently; please inform the author if they do not function as you would expect.
+
+=cut
+
+########################################################################
+
+sub array {
+ {
+ '-import' => {
+ 'Template::Generic:array' => '*',
+ },
+ 'modifier' => {
+ '-all' => q{ no strict; _ENSURE_REF_VALUE_; * },
+ },
+ 'code_expr' => {
+ '_ENSURE_REF_VALUE_' => q{
+ _REF_VALUE_ or @{_SELF_CLASS_."::"._ATTR_{variable}} = ();
+ },
+ '_VALUE_' => '(\@{_SELF_CLASS_."::"._ATTR_{variable}})',
+ },
+ }
+}
+
+########################################################################
+
+sub hash {
+ {
+ '-import' => {
+ 'Template::Generic:hash' => '*',
+ },
+ 'modifier' => {
+ '-all' => q{ no strict; _ENSURE_REF_VALUE_; * },
+ },
+ 'code_expr' => {
+ '_ENSURE_REF_VALUE_' => q{
+ _REF_VALUE_ or %{_SELF_CLASS_."::"._ATTR_{variable}} = ();
+ },
+ '_VALUE_' => '(\%{_SELF_CLASS_."::"._ATTR_{variable}})',
+ },
+ }
+}
+
+########################################################################
+
+=head2 vars
+
+This rewrite rule converts package variable names into ClassVar methods of the equivalent data type.
+
+Here's an example declaration:
+
+ package MyClass;
+
+ use Class::MakeMethods::Template::ClassVar (
+ vars => '$VERSION @ISA'
+ );
+
+MyClass now has methods that get and set the contents of its $MyClass::VERSION and @MyClass::ISA package variables:
+
+ MyClass->VERSION( 2.4 );
+ MyClass->push_ISA( 'Exporter' );
+
+Subclasses can use these methods to adjust their own variables:
+
+ package MySubclass;
+ MySubclass->MyClass::push_ISA( 'MyClass' );
+ MySubclass->VERSION( 1.0 );
+
+=cut
+
+sub vars {
+ my $mm_class = shift;
+ my @rewrite = map [ "Template::ClassVar:$_" ], qw( scalar array hash );
+ my %rewrite = ( '$' => 0, '@' => 1, '%' => 2 );
+ while (@_) {
+ my $name = shift;
+ my $data = shift;
+ $data =~ s/\A(.)//;
+ push @{ $rewrite[ $rewrite{ $1 } ] }, { 'name'=>$name, 'variable'=>$data };
+ }
+ return @rewrite;
+}
+
+1;
diff --git a/lib/Class/MakeMethods/Template/Flyweight.pm b/lib/Class/MakeMethods/Template/Flyweight.pm
new file mode 100644
index 0000000..33f44ed
--- /dev/null
+++ b/lib/Class/MakeMethods/Template/Flyweight.pm
@@ -0,0 +1,43 @@
+package Class::MakeMethods::Template::Flyweight;
+
+use Class::MakeMethods::Template::InsideOut '-isasubclass';
+
+$VERSION = 1.008;
+
+sub new { { '-import' => { 'Template::Scalar:new' => '*' } } }
+
+1;
+
+__END__
+
+=head1 NAME
+
+Class::MakeMethods::Template::Flyweight - Deprecated name for InsideOut
+
+=head1 SYNOPSIS
+
+ package MyObject;
+ use Class::MakeMethods::Template::InsideOut (
+ new => [ 'new' ]
+ scalar => [ 'foo', 'bar' ]
+ );
+
+ package main;
+
+ my $obj = MyObject->new( foo => "Foozle", bar => "Bozzle" );
+ print $obj->foo(); # Prints Foozle
+ $obj->bar("Bamboozle"); # Sets $obj->{bar}
+
+=head1 DESCRIPTION
+
+Earlier versions of this package included a package named Class::MakeMethods::Template::Flyweight.
+
+However, in hindsight, this name was poorly chosen, as it suggests that the Flyweight object design pattern is being used, when the functionality is more akin to what's sometimes known as "inside-out objects."
+
+This functionality is now provided by Class::MakeMethods::Template::InsideOut, of which this is an almost-empty subclass retained to provide backwards compatibility.
+
+=head1 SEE ALSO
+
+L<Class::MakeMethods::Template::InsideOut>.
+
+=cut \ No newline at end of file
diff --git a/lib/Class/MakeMethods/Template/Generic.pm b/lib/Class/MakeMethods/Template/Generic.pm
new file mode 100644
index 0000000..368f21f
--- /dev/null
+++ b/lib/Class/MakeMethods/Template/Generic.pm
@@ -0,0 +1,2349 @@
+=head1 NAME
+
+Class::MakeMethods::Template::Generic - Templates for common meta-method types
+
+=head1 SYNOPSIS
+
+ package MyObject;
+ use Class::MakeMethods (
+ 'Template::Hash:new' => [ 'new' ],
+ 'Template::Hash:scalar' => [ 'foo' ]
+ 'Template::Static:scalar' => [ 'bar' ]
+ );
+
+ package main;
+
+ my $obj = MyObject->new( foo => "Foozle", bar => "Bozzle" );
+ print $obj->foo();
+ $obj->bar("Bamboozle");
+
+=head1 DESCRIPTION
+
+This package provides a variety of abstract interfaces for constructors
+and accessor methods, which form a common foundation for meta-methods
+provided by the Hash, Scalar, Flyweight, Static, PackageVar, and
+ClassVar implementations.
+
+Generally speaking, the Generic meta-methods define calling interfaces
+and behaviors which are bound to differently scoped data by each
+of those subclasses.
+
+=cut
+
+########################################################################
+
+package Class::MakeMethods::Template::Generic;
+
+use Class::MakeMethods::Template '-isasubclass';
+
+$VERSION = 1.008;
+use strict;
+use Carp;
+
+# use AutoLoader 'AUTOLOAD';
+
+########################################################################
+
+sub generic {
+ {
+ 'params' => {
+ },
+ 'modifier' => {
+ '-import' => { 'Template::Universal:generic' => '*' },
+ },
+ 'code_expr' => {
+ '-import' => { 'Template::Universal:generic' => '*' },
+ '_VALUE_' => undef,
+ '_REF_VALUE_' => q{ _VALUE_ },
+ '_GET_VALUE_' => q{ _VALUE_ },
+ '_SET_VALUE_{}' => q{ ( _VALUE_ = * ) },
+ '_PROTECTED_SET_VALUE_{}' => q{ (_ACCESS_PROTECTED_ and _SET_VALUE_{*}) },
+ '_PRIVATE_SET_VALUE_{}' => q{ ( _ACCESS_PRIVATE_ and _SET_VALUE_{*} ) },
+ },
+ }
+}
+
+# 1;
+
+# __END__
+
+########################################################################
+
+=head2 new Constructor
+
+There are several types of hash-based object constructors to choose from.
+
+Each of these methods creates and returns a reference to a new
+blessed instance. They differ in how their (optional) arguments
+are interpreted to set initial values, and in how they operate when
+called as class or instance methods.
+
+B<Interfaces>: The following interfaces are supported.
+
+=over 4
+
+=item -with_values,
+
+Provides the with_values behavior.
+
+=item -with_init
+
+Provides the with_init behavior.
+
+=item -with_methods
+
+Provides the with_methods behavior.
+
+=item -new_and_init
+
+Provides the with_init behavior for I<*>, and the general purpose method_init behavior as an init method.
+
+=item -copy_with_values
+
+Provides the copy behavior.
+
+=back
+
+B<Behaviors>: The following types of constructor methods are available.
+
+=over 4
+
+=item with_values
+
+Creates and blesses a new instance.
+
+If arguments are passed they are included in the instance, otherwise it will be empty.
+
+Returns the new instance.
+
+May be called as a class or instance method.
+
+=item with_methods
+
+Creates, blesses, and returns a new instance.
+
+The arguments are treated as a hash of method-name/argument-value
+pairs, with each such pair causing a call C<$self-E<gt>name($value)>.
+
+=item with_init
+
+Creates and blesses a new instance, then calls a method named C<init>,
+passing along any arguments that were initially given.
+
+Returns the new instance.
+
+The I<init>() method should be defined in the class declaring these methods.
+
+May be called as a class or instance method.
+
+=item and_then_init
+
+Creates a new instance using method-name/argument-value pairs, like C<with_methods>, but then calls a method named C<init> before returning the new object. The C<init> method does not receive any arguments.
+
+The I<init>() method should be defined in the class declaring these methods.
+
+=item instance_with_methods
+
+If called as a class method, creates, blesses, and returns a new
+instance. If called as an object method, operates on and returns
+the existing instance.
+
+Accepts name-value pair arguments, or a reference to hash of such
+pairs, and calls the named method for each with the supplied value
+as a single argument. (See the Universal method_init behavior for
+more discussion of this pattern.)
+
+=item copy_with values
+
+Produce a copy of an instance. Can not be called as a class method.
+
+The copy is a *shallow* copy; any references will be shared by the
+instance upon which the method is called and the returned newborn.
+
+If a list of key-value pairs is passed as arguments to the method,
+they are added to the copy, overwriting any values with the same
+key that may have been copied from the original.
+
+=item copy_with_methods
+
+Produce a copy of an instance. Can not be called as a class method.
+
+The copy is a *shallow* copy; any references will be shared by the
+instance upon which the method is called and the returned newborn.
+
+Accepts name-value pair arguments, or a reference to hash of such
+pairs, and calls the named method on the copy for each with the
+supplied value as a single argument before the copy is returned.
+
+=item copy_instance_with_values
+
+If called as a class method, creates, blesses, and returns a new
+instance. If called as an object method, produces and returns a
+copy of an instance.
+
+The copy is a *shallow* copy; any references will be shared by the
+instance upon which the method is called and the returned newborn.
+
+If a list of key-value pairs is passed as arguments to the method,
+they are added to the copy, overwriting any values with the same
+key that may have been copied from the original.
+
+=item copy_instance_with_methods
+
+If called as a class method, creates, blesses, and returns a new
+instance. If called as an object method, produces and returns a
+copy of an instance.
+
+The copy is a *shallow* copy; any references will be shared by the
+instance upon which the method is called and the returned newborn.
+
+Accepts name-value pair arguments, or a reference to hash of such
+pairs, and calls the named method on the copy for each with the supplied value as
+a single argument before the copy is returned.
+
+=back
+
+B<Parameters>: The following parameters are supported:
+
+=over 4
+
+=item init_method
+
+The name of the method to call after creating a new instance. Defaults to 'init'.
+
+=back
+
+=cut
+
+sub new {
+ {
+ '-import' => {
+ # 'Template::Generic:generic' => '*',
+ },
+ 'interface' => {
+ default => 'with_methods',
+ with_values => 'with_values',
+ with_methods => 'with_methods',
+ with_init => 'with_init',
+ and_then_init => 'and_then_init',
+ new_and_init => { '*'=>'new_with_init', 'init'=>'method_init'},
+ instance_with_methods => 'instance_with_methods',
+ copy => 'copy_with_values',
+ copy_with_values => 'copy_with_values',
+ copy_with_methods => 'copy_with_methods',
+ copy_instance_with_values => 'copy_instance_with_values',
+ copy_instance_with_methods => 'copy_instance_with_methods',
+ },
+ 'behavior' => {
+ 'with_methods' => q{
+ $self = _EMPTY_NEW_INSTANCE_;
+ _CALL_METHODS_FROM_HASH_
+ return $self;
+ },
+ 'with_values' => q{
+ $self = _EMPTY_NEW_INSTANCE_;
+ _SET_VALUES_FROM_HASH_
+ return $self;
+ },
+ 'with_init' => q{
+ $self = _EMPTY_NEW_INSTANCE_;
+ my $init_method = $m_info->{'init_method'} || 'init';
+ $self->$init_method( @_ );
+ return $self;
+ },
+ 'and_then_init' => q{
+ $self = _EMPTY_NEW_INSTANCE_;
+ _CALL_METHODS_FROM_HASH_
+ my $init_method = $m_info->{'init_method'} || 'init';
+ $self->$init_method();
+ return $self;
+ },
+ 'instance_with_methods' => q{
+ $self = ref ($self) ? $self : _EMPTY_NEW_INSTANCE_;
+ _CALL_METHODS_FROM_HASH_
+ return $self;
+ },
+ 'copy_with_values' => q{
+ @_ = ( %$self, @_ );
+ $self = _EMPTY_NEW_INSTANCE_;
+ _SET_VALUES_FROM_HASH_
+ return $self;
+ },
+ 'copy_with_methods' => q{
+ @_ = ( %$self, @_ );
+ $self = _EMPTY_NEW_INSTANCE_;
+ _CALL_METHODS_FROM_HASH_
+ return $self;
+ },
+ 'copy_instance_with_values' => q{
+ $self = bless { ( ref $self ? %$self : () ) }, _SELF_CLASS_;
+ _SET_VALUES_FROM_HASH_
+ return $self;
+ },
+ 'copy_instance_with_methods' => q{
+ $self = bless { ref $self ? %$self : () }, _SELF_CLASS_;
+ _CALL_METHODS_FROM_HASH_
+ return $self;
+ },
+ },
+ }
+}
+
+########################################################################
+
+=head2 scalar Accessor
+
+A generic scalar-value accessor meta-method which serves as an
+abstraction for basic "get_set" methods and numerous related
+interfaces
+
+ use Class::MakeMethods -MakerClass => "...",
+ scalar => [ 'foo', 'bar' ];
+ ...
+ $self->foo( 'my new foo value' );
+ print $self->foo();
+
+(Note that while you can use the scalar methods to store references to
+various data structures, there are other meta-methods defined below that
+may be more useful for managing references to arrays, hashes, and objects.)
+
+B<Interfaces>: The following calling interfaces are available.
+
+=over 4
+
+=item get_set (default)
+
+Provides get_set method for I<*>.
+
+Example: Create method foo, which sets the value of 'foo' for this
+instance if an argument is passed in, and then returns the value
+whether or not it's been changed:
+
+ use Class::MakeMethods -MakerClass => "...",
+ scalar => [ 'foo' ];
+
+=item get_protected_set
+
+Provides an get_set accessor for I<*> that croaks if a new value
+is passed in from a package that is not a subclass of the declaring
+one.
+
+=item get_private_set
+
+Provides an get_set accessor for I<*> that croaks if a new value
+is passed in from a package other than the declaring one.
+
+=item read_only
+
+Provides an accessor for I<*> that does not modify its value. (Its
+initial value would have to be set by some other means.)
+
+=item eiffel
+
+Provides get behavior as I<*>, and set behavior as set_I<*>.
+
+Example: Create methods bar which returns the value of 'bar' for
+this instance (takes no arguments), and set_bar, which sets the
+value of 'bar' (no return):
+
+ use Class::MakeMethods -MakerClass => "...",
+ scalar => [ --eiffel => 'bar' ];
+
+=item java
+
+Provides get behavior as getI<*>, and set behavior as setI<*>.
+
+Example: Create methods getBaz which returns the value of 'Baz'
+for this instance (takes no arguments), and setBaz, which sets the
+value for this instance (no return):
+
+ use Class::MakeMethods -MakerClass => "...",
+ scalar => [ --java => 'Baz' ];
+
+
+=item init_and_get
+
+Creates methods which cache their results in a hash key.
+
+Provides the get_init behavior for I<*>, and an delete behavior for clear_I<*>.
+Specifies default value for init_method parameter of init_I<*>.
+
+
+=item with_clear
+
+Provides get_set behavior for I<*>, and a clear_I<*> method.
+
+=back
+
+
+B<Behaviors>: The following types of accessor methods are available.
+
+=over 4
+
+=item get_set
+
+If no argument is provided, returns the value of the current instance. The value defaults to undef.
+
+If an argument is provided, it is stored as the value of the current
+instance (even if the argument is undef), and that value is returned.
+
+Also available as get_protected_set and get_private_set, which are
+available for public read-only access, but have access control
+limitations.
+
+=item get
+
+Returns the value from the current instance.
+
+=item set
+
+Sets the value for the current instance. If called with no arguments,
+the value is set to undef. Does not return a value.
+
+=item clear
+
+Sets value to undef.
+
+=item get_set_chain
+
+Like get_set, but if called with an argument, returns the object it was called on. This allows a series of mutators to be called as follows:
+
+ package MyObject;
+ use Class::MakeMethods (
+ 'Template::Hash:scalar --get_set_chain' => 'foo bar baz'
+ );
+ ...
+
+ my $obj = MyObject->new->foo('Foozle');
+ $obj->bar("none")->baz("Brazil");
+ print $obj->foo, $obj->bar, $obj->baz;
+
+=item get_set_prev
+
+Like get_set, but if called with an argument, returns the previous value before it was changed to the new one.
+
+=item get_init
+
+If the value is currently undefined, calls the init_method. Returns the value.
+
+=back
+
+B<Parameters>: The following parameters are supported:
+
+=over 4
+
+=item init_method
+
+The name of a method to be called to initialize this meta-method.
+
+Only used by the get_init behavior.
+
+=back
+
+=cut
+
+sub scalar {
+ {
+ '-import' => { 'Template::Generic:generic' => '*' },
+ 'interface' => {
+ default => 'get_set',
+ get_set => { '*'=>'get_set' },
+ noclear => { '*'=>'get_set' },
+ with_clear => { '*'=>'get_set', 'clear_*'=>'clear' },
+
+ read_only => { '*'=>'get' },
+ get_private_set => 'get_private_set',
+ get_protected_set => 'get_protected_set',
+
+ eiffel => { '*'=>'get', 'set_*'=>'set_return' },
+ java => { 'get*'=>'get', 'set*'=>'set_return' },
+
+ init_and_get => { '*'=>'get_init', -params=>{ init_method=>'init_*' } },
+
+ },
+ 'behavior' => {
+ 'get' => q{ _GET_VALUE_ },
+ 'set' => q{ _SET_VALUE_{ shift() } },
+ 'set_return' => q{ _BEHAVIOR_{set}; return },
+ 'clear' => q{ _SET_VALUE_{ undef } },
+ 'defined' => q{ defined _VALUE_ },
+
+ 'get_set' => q {
+ if ( scalar @_ ) {
+ _BEHAVIOR_{set}
+ } else {
+ _BEHAVIOR_{get}
+ }
+ },
+ 'get_set_chain' => q {
+ if ( scalar @_ ) {
+ _BEHAVIOR_{set};
+ return _SELF_
+ } else {
+ _BEHAVIOR_{get}
+ }
+ },
+ 'get_set_prev' => q {
+ my $value = _BEHAVIOR_{get};
+ if ( scalar @_ ) {
+ _BEHAVIOR_{set};
+ }
+ return $value;
+ },
+
+ 'get_private_set' => q{
+ if ( scalar @_ ) {
+ _PRIVATE_SET_VALUE_{ shift() }
+ } else {
+ _BEHAVIOR_{get}
+ }
+ },
+ 'get_protected_set' => q{
+ if ( scalar @_ ) {
+ _PROTECTED_SET_VALUE_{ shift() }
+ } else {
+ _BEHAVIOR_{get}
+ }
+ },
+ 'get_init' => q{
+ if ( ! defined _VALUE_ ) {
+ my $init_method = _ATTR_REQUIRED_{'init_method'};
+ _SET_VALUE_{ _SELF_->$init_method( @_ ) };
+ } else {
+ _BEHAVIOR_{get}
+ }
+ },
+
+ },
+ 'params' => {
+ new_method => 'new'
+ },
+ }
+}
+
+########################################################################
+
+=head2 string Accessor
+
+A generic scalar-value accessor meta-method which serves as an
+abstraction for basic "get_set" methods and numerous related
+interfaces
+
+ use Class::MakeMethods -MakerClass => "...",
+ string => [ 'foo', 'bar' ];
+ ...
+ $self->foo( 'my new foo value' );
+ print $self->foo();
+
+This meta-method extends the scalar meta-method, and supports the same interfaces and parameters.
+
+However, it generally treats values as strings, and can not be used to store references.
+
+B<Interfaces>: In addition to those provided by C<scalar>, the following calling interfaces are available.
+
+=over 4
+
+=item -get_concat
+
+Provides the get_concat behavior for I<*>, and a clear_I<*> method.
+
+Example:
+
+ use Class::MakeMethods
+ get_concat => { name => 'words', join => ", " };
+
+ $obj->words('foo');
+ $obj->words('bar');
+ $obj->words() eq 'foo, bar';
+
+=back
+
+B<Behaviors>: In addition to those provided by C<scalar>, the following types of accessor methods are available.
+
+=over 4
+
+=item concat
+
+Concatenates the argument value with the existing value.
+
+=item get_concat
+
+Like get_set except sets do not clear out the original value, but instead
+concatenate the new value to the existing one.
+
+=back
+
+B<Parameters>: In addition to those provided by C<scalar>, the following parameters are supported.
+
+=over 4
+
+=item join
+
+If the join parameter is defined, each time the get_concat behavior
+is invoked, it will glue its argument onto any existing value with
+the join string as the separator. The join field is applied I<between>
+values, not prior to the first or after the last. Defaults to undefined
+
+=back
+
+=cut
+
+sub string {
+ {
+ '-import' => { 'Template::Generic:scalar' => '*' },
+ 'interface' => {
+ get_concat => { '*'=>'get_concat', 'clear_*'=>'clear',
+ -params=>{ 'join' => '' }, },
+ },
+ 'params' => {
+ 'return_value_undefined' => '',
+ },
+ 'behavior' => {
+ 'get' => q{
+ if ( defined( my $value = _GET_VALUE_) ) {
+ _GET_VALUE_;
+ } else {
+ _STATIC_ATTR_{return_value_undefined};
+ }
+ },
+ 'set' => q{
+ my $new_value = shift();
+ _SET_VALUE_{ "$new_value" };
+ },
+ 'concat' => q{
+ my $new_value = shift();
+ if ( defined( my $value = _GET_VALUE_) ) {
+ _SET_VALUE_{join( _STATIC_ATTR_{join}, $value, $new_value)};
+ } else {
+ _SET_VALUE_{ "$new_value" };
+ }
+ },
+ 'get_concat' => q{
+ if ( scalar @_ ) {
+ _BEHAVIOR_{concat}
+ } else {
+ _BEHAVIOR_{get}
+ }
+ },
+ },
+ }
+}
+
+########################################################################
+
+=head2 string_index
+
+ string_index => [ qw / foo bar baz / ]
+
+Creates string accessor methods, like string above, but also
+maintains a static hash index in which each object is stored under
+the value of the field when the slot is set.
+
+This is a unique index, so only one object can have a given key.
+If an object has a slot set to a value which another object is
+already set to the object currently set to that value has that slot
+set to undef and the new object will be put into the hash under
+that value.
+
+Objects with undefined values are not stored in the index.
+
+Note that to free items from memory, you must clear these values!
+
+B<Methods>:
+
+=over 4
+
+=item *
+
+The method find_x is defined which if called with any arguments
+returns a list of the objects stored under those values in the
+hash. Called with no arguments, it returns a reference to the hash.
+
+=back
+
+B<Profiles>:
+
+=over 4
+
+=item *
+
+find_or_new
+
+ 'string_index -find_or_new' => [ qw / foo bar baz / ]
+
+Just like string_index except the find_x method is defined to call the new
+method to create an object if there is no object already stored under
+any of the keys you give as arguments.
+
+=back
+
+=cut
+
+sub string_index {
+ ( {
+ '-import' => { 'Template::Generic:generic' => '*' },
+ 'params' => {
+ 'new_method' => 'new',
+ },
+ 'interface' => {
+ default => { '*'=>'get_set', 'clear_*'=>'clear', 'find_*'=>'find' },
+ find_or_new=>{'*'=>'get_set', 'clear_*'=>'clear', 'find_*'=>'find_or_new'}
+ },
+ 'code_expr' => {
+ _REMOVE_FROM_INDEX_ => q{
+ if (defined ( my $old_v = _GET_VALUE_ ) ) {
+ delete _ATTR_{'index'}{ $old_v };
+ }
+ },
+ _ADD_TO_INDEX_ => q{
+ if (defined ( my $new_value = _GET_VALUE_ ) ) {
+ if ( my $old_item = _ATTR_{'index'}{$new_value} ) {
+ # There's already an object stored under that value so we
+ # need to unset it's value.
+ # And maybe issue a warning? Or croak?
+ my $m_name = _ATTR_{'name'};
+ $old_item->$m_name( undef );
+ }
+
+ # Put ourself in the index under that value
+ _ATTR_{'index'}{$new_value} = _SELF_;
+ }
+ },
+ _INDEX_HASH_ => '_ATTR_{index}',
+ },
+ 'behavior' => {
+ '-init' => [ sub {
+ my $m_info = $_[0];
+ defined $m_info->{'index'} or $m_info->{'index'} = {};
+ return;
+ } ],
+ 'get' => q{
+ return _GET_VALUE_;
+ },
+ 'set' => q{
+ my $new_value = shift;
+
+ _REMOVE_FROM_INDEX_
+
+ # Set our value to new
+ _SET_VALUE_{ $new_value };
+
+ _ADD_TO_INDEX_
+ },
+ 'get_set' => q{
+ if ( scalar @_ ) {
+ _BEHAVIOR_{set}
+ } else {
+ _BEHAVIOR_{get}
+ }
+ },
+ 'clear' => q{
+ _REMOVE_FROM_INDEX_
+ _SET_VALUE_{ undef };
+ },
+ 'find' => q{
+ if ( scalar @_ ) {
+ return @{ _ATTR_{'index'} }{ @_ };
+ } else {
+ return _INDEX_HASH_
+ }
+ },
+ 'find_or_new' => q{
+ if ( scalar @_ ) {
+ my $class = _SELF_CLASS_;
+ my $new_method = _ATTR_REQUIRED_{'new_method'};
+ my $m_name = _ATTR_{'name'};
+ foreach (@_) {
+ next if defined _ATTR_{'index'}{$_};
+ # create new instance and set its value; it'll add itself to index
+ $class->$new_method()->$m_name($_);
+ }
+ return @{ _ATTR_{'index'} }{ @_ };
+ } else {
+ return _INDEX_HASH_
+ }
+ },
+ },
+ } )
+}
+
+########################################################################
+
+=head2 number Accessor
+
+A generic scalar-value accessor meta-method which serves as an
+abstraction for basic "get_set" methods and numerous related
+interfaces
+
+ use Class::MakeMethods -MakerClass => "...",
+ string => [ 'foo', 'bar' ];
+ ...
+ $self->foo( 23 );
+ print $self->foo();
+
+This meta-method extends the scalar meta-method, and supports the same interfaces and parameters.
+
+However, it generally treats values as numbers, and can not be used to store strings or references.
+
+B<Interfaces>: In addition to those provided by C<scalar>, the following calling interfaces are available.
+
+=over 4
+
+=item -counter
+
+Provides the numeric get_set behavior for I<*>, and numeric I<*>_incr and I<*>_reset methods.
+
+=back
+
+B<Behaviors>: In addition to those provided by C<scalar>, the following types of accessor methods are available.
+
+=over 4
+
+=item get_set
+
+The get_set behavior is similar to the default scalar behavior except that empty values are treated as zero.
+
+=item increment
+
+If no argument is provided, increments the I<hash_key> value by 1.
+If an argument is provided, the value is incremented by that amount.
+Returns the increased value.
+
+=item clear
+
+Sets the value to zero.
+
+=back
+
+=cut
+
+sub number {
+ {
+ '-import' => { 'Template::Generic:scalar' => '*' },
+ 'interface' => {
+ counter => { '*'=>'get_set', '*_incr'=>'incr', '*_reset'=>'clear' },
+ },
+ 'params' => {
+ 'return_value_undefined' => 0,
+ },
+ 'behavior' => {
+ 'get_set' => q{
+ if ( scalar @_ ) {
+ local $_ = shift;
+ if ( defined $_ ) {
+ croak "Can't set _STATIC_ATTR_{name} to non-numeric value '$_'"
+ if ( /[^\+\-\,\d\.e]/ );
+ s/\,//g;
+ }
+ _SET_VALUE_{ $_ }
+ }
+ defined( _GET_VALUE_ ) ? _GET_VALUE_
+ : _STATIC_ATTR_{return_value_undefined}
+ },
+ 'incr' => q{
+ _VALUE_ ||= 0;
+ _VALUE_ += ( scalar @_ ? shift : 1 )
+ },
+ 'decr' => q{
+ _VALUE_ ||= 0;
+ _VALUE_ -= ( scalar @_ ? shift : 1 )
+ },
+ },
+ }
+}
+
+########################################################################
+
+=head2 boolean Accessor
+
+A generic scalar-value accessor meta-method which serves as an abstraction for basic "get_set" methods and numerous related interfaces
+
+ use Class::MakeMethods -MakerClass => "...",
+ string => [ 'foo', 'bar' ];
+ ...
+ $self->foo( 1 );
+ print $self->foo();
+ $self->clear_foo;
+
+This meta-method extends the scalar meta-method, and supports the
+same interfaces and parameters. However, it generally treats values
+as true-or-false flags, and can not be used to store strings,
+numbers, or references.
+
+B<Interfaces>:
+
+=over 4
+
+=item flag_set_clear (default)
+
+Provides the get_set behavior for I<*>, and set_I<*> and clear_I<*> methods to set the value to true or false.
+
+=back
+
+B<Behaviors>: In addition to those provided by C<scalar>, the following types of accessor methods are available.
+
+=over 4
+
+=item get_set
+
+The get_set behavior is similar to the get_set scalar behavior
+except that empty or false values are treated as zero, and true
+values are treated as zero.
+
+=item set_true
+
+Sets the value to one.
+
+=item set_false
+
+Sets the value to zero.
+=back
+
+=cut
+
+sub boolean {
+ {
+ '-import' => { 'Template::Generic:scalar' => '*' },
+ 'interface' => {
+ default => {'*'=>'get_set', 'clear_*'=>'set_false',
+ 'set_*'=>'set_true'},
+ flag_set_clear => {'*'=>'get_set', 'clear_*'=>'set_false',
+ 'set_*'=>'set_true'},
+ },
+ 'behavior' => {
+ 'get' => q{ _GET_VALUE_ || 0 },
+ 'set' => q{
+ if ( shift ) {
+ _BEHAVIOR_{set_true}
+ } else {
+ _BEHAVIOR_{set_false}
+ }
+ },
+ 'set_true' => q{ _SET_VALUE_{ 1 } },
+ 'set_false' => q{ _SET_VALUE_{ 0 } },
+ 'set_value' => q{
+ _SET_VALUE_{ scalar @_ ? shift : 1 }
+ },
+ },
+ }
+}
+
+########################################################################
+
+=head2 bits Accessor
+
+A generic accessor for bit-field values.
+
+The difference between 'Template::Generic:bits' and
+'Template::Generic:boolean' is that all flags created with this
+meta-method are stored in a single vector for space efficiency.
+
+B<Interfaces>: The following calling interfaces are available.
+
+=over 4
+
+=item default
+
+Provides get_set behavior for I<*>, a set_I<*> method which sets
+the value to true and a clear_I<*> method which sets the value to
+false.
+
+Also defines methods named bits, bit_fields, and bit_dump with the
+behaviors below. These methods are shared across all of the boolean
+meta-methods defined by a single class.
+
+=item class_methods
+
+.
+
+=back
+
+B<Basic Behaviors>: The following types of bit-level accessor methods are available.
+
+=over 4
+
+=item get_set
+
+Returns the value of the named flag. If called with an argument, it first
+sets the named flag to the truth-value of the argument.
+
+=item set_true
+
+Sets the value to true.
+
+=item set_false
+
+Sets the value to false.
+
+=back
+
+B<Group Methods>: The following types of methods manipulate the overall vector value.
+
+=over 4
+
+=item bits
+
+Returns the vector containing all of the bit fields (remember however
+that a vector containing all 0 bits is still true).
+
+=item bit_dump
+
+Returns a hash of the flag-name/flag-value pairs.
+
+=item bits_size
+
+Returns the number of bits that can fit into the current vector.
+
+=item bits_complement
+
+Returns the twos-complement of the vector.
+
+=item bit_pos_get
+
+Takes a single argument and returns the value of the bit stored in that position.
+
+=item bit_pos_set
+
+Takes two arguments and sets the bit stored in the position of the first argument to the value of the second argument.
+
+=back
+
+B<Class Methods>: The following types of class methods are available.
+
+=over 4
+
+=item bit_names
+
+Returns a list of all the flags by name.
+
+=back
+
+=cut
+
+sub bits {
+ {
+ '-import' => {
+ # 'Template::Generic:generic' => '*',
+ },
+ 'interface' => {
+ default => {
+ '*'=>'get_set', 'set_*'=>'set_true', 'clear_*'=>'set_false',
+ 'bit_fields'=>'bit_names', 'bit_string'=>'bit_string',
+ 'bit_list'=>'bit_list', 'bit_hash'=>'bit_hash',
+ },
+ class_methods => {
+ 'bit_fields'=>'bit_names', 'bit_string'=>'bit_string',
+ 'bit_list'=>'bit_list', 'bit_hash'=>'bit_hash',
+ },
+ },
+ 'code_expr' => {
+ '_VEC_POS_VALUE_{}' => 'vec(_VALUE_, *, 1)',
+ _VEC_VALUE_ => '_VEC_POS_VALUE_{ _ATTR_{bfp} }',
+ _CLASS_INFO_ => '$Class::MakeMethods::Template::Hash::bits{_STATIC_ATTR_{target_class}}',
+ },
+ 'modifier' => {
+ '-all' => [ q{
+ defined _VALUE_ or _VALUE_ = "";
+ *
+ } ],
+ },
+ 'behavior' => {
+ '-init' => sub {
+ my $m_info = $_[0];
+
+ $m_info->{bfp} ||= do {
+ my $array = ( $Class::MakeMethods::Template::Hash::bits{$m_info->{target_class}} ||= [] );
+ my $idx;
+ foreach ( 0..$#$array ) {
+ if ( $array->[$_] eq $m_info->{'name'} ) { $idx = $_; last }
+ }
+ unless ( $idx ) {
+ push @$array, $m_info->{'name'};
+ $idx = $#$array;
+ }
+ $idx;
+ };
+
+ return;
+ },
+ 'bit_names' => q{
+ @{ _CLASS_INFO_ };
+ },
+ 'bit_string' => q{
+ if ( @_ ) {
+ _SET_VALUE_{ shift @_ };
+ } else {
+ _VALUE_;
+ }
+ },
+ 'bits_size' => q{
+ 8 * length( _VALUE_ );
+ },
+ 'bits_complement' => q{
+ ~ _VALUE_;
+ },
+ 'bit_hash' => q{
+ my @bits = @{ _CLASS_INFO_ };
+ if ( @_ ) {
+ my %bits = @_;
+ _SET_VALUE_{ pack 'b*', join '', map { $_ ? 1 : 0 } @bits{ @bits } };
+ return @_;
+ } else {
+ map { $bits[$_], vec(_VALUE_, $_, 1) } 0 .. $#bits
+ }
+ },
+ 'bit_list' => q{
+ if ( @_ ) {
+ _SET_VALUE_{ pack 'b*', join( '', map { $_ ? 1 : 0 } @_ ) };
+ return map { $_ ? 1 : 0 } @_;
+ } else {
+ split //, unpack "b*", _VALUE_;
+ }
+ },
+ 'bit_pos_get' => q{
+ vec(_VALUE_, $_[0], 1)
+ },
+ 'bit_pos_set' => q{
+ vec(_VALUE_, $_[0], 1) = ( $_[1] ? 1 : 0 )
+ },
+
+ 'get_set' => q{
+ if ( @_ ) {
+ _VEC_VALUE_ = ( $_[0] ? 1 : 0 );
+ } else {
+ _VEC_VALUE_;
+ }
+ },
+ 'get' => q{
+ _VEC_VALUE_;
+ },
+ 'set' => q{
+ _VEC_VALUE_ = ( $_[0] ? 1 : 0 );
+ },
+ 'set_true' => q{
+ _VEC_VALUE_ = 1;
+ },
+ 'set_false' => q{
+ _VEC_VALUE_ = 0;
+ },
+
+ },
+ }
+}
+
+
+########################################################################
+
+=head2 array Accessor
+
+Creates accessor methods for manipulating arrays of values.
+
+B<Interfaces>: The following calling interfaces are available.
+
+=over 4
+
+=item default
+
+Provides get_set behavior for I<*>, and I<verb>_I<*> methods for the non-get behaviors below.
+
+=item minimal
+
+Provides get_set behavior for I<*>, and I<*>_I<verb> methods for clear behavior.
+
+=item get_set_items
+
+Provides the get_set_items for I<*>.
+
+=item x_verb
+
+Provides get_push behavior for I<*>, and I<*>_I<verb> methods for the non-get behaviors below.
+
+=item get_set_ref
+
+Provides the get_set_ref for I<*>.
+
+=item get_set_ref_help
+
+Provides the get_set_ref for I<*>, and I<verb>_I<*> methods for the non-get behaviors below.
+
+=back
+
+B<Behaviors>: The following types of accessor methods are available.
+
+=over 4
+
+=item get_set_items
+
+Called with no arguments returns a reference to the array stored in the slot.
+
+Called with one simple scalar argument it treats the argument as an index
+and returns the value stored under that index.
+
+Called with more than one argument, treats them as a series of index/value
+pairs and adds them to the array.
+
+=item get_push
+
+If arguments are passed, these values are pushed on to the list; if a single array ref is passed, its values are used as the arguments.
+
+This method returns the list of values stored in the slot. In an array
+context it returns them as an array and in a scalar context as a
+reference to the array.
+
+=item get_set_ref
+
+If arguments are passed, these values are placed on the list, replacing the current contents; if a single array ref is passed, its values are used as the arguments.
+
+This method returns the list of values stored in the slot. In an array
+context it returns them as an array and in a scalar context as a
+reference to the array.
+
+=item get_set
+
+If arguments are passed, these values are placed on the list, replacing the current contents.
+
+This method returns the list of values stored in the slot. In an array
+context it returns them as an array and in a scalar context as a
+reference to the array.
+
+
+=item push
+
+Append items to tail.
+
+=item pop
+
+Remove an item from the tail.
+
+=item shift
+
+Remove an item from the front.
+
+=item unshift
+
+Prepend items to front.
+
+=item splice
+
+Remove or replace items.
+
+=item clear
+
+Remove all items.
+
+=item count
+
+Returns the number of item in the list.
+
+=back
+
+=cut
+
+sub array {
+ {
+ '-import' => { 'Template::Generic:generic' => '*' },
+ 'interface' => {
+ default => {
+ '*'=>'get_set',
+ map( ($_.'_*' => $_ ), qw( pop push unshift shift splice clear count )),
+ map( ('*_'.$_ => $_ ), qw( ref index ) ),
+ },
+ minimal => { '*'=>'get_set', '*_clear'=>'clear' },
+ get_set_items => { '*'=>'get_set_items' },
+ x_verb => {
+ '*'=>'get_set',
+ map( ('*_'.$_ => $_ ), qw(pop push unshift shift splice clear count ref index )),
+ },
+ get_set_ref => { '*'=>'get_set_ref' },
+ get_set_ref_help => { '*'=>'get_set_ref', '-base'=>'default' },
+ },
+ 'modifier' => {
+ '-all' => [ q{ _ENSURE_REF_VALUE_; * } ],
+ },
+ 'code_expr' => {
+ '_ENSURE_REF_VALUE_' => q{ _REF_VALUE_ ||= []; },
+ },
+ 'behavior' => {
+ 'get_set' => q{
+ @{_REF_VALUE_} = @_ if ( scalar @_ );
+ return wantarray ? @{_GET_VALUE_} : _REF_VALUE_;
+ },
+ 'get_set_ref' => q{
+ @{_REF_VALUE_} = ( ( scalar(@_) == 1 and ref($_[0]) eq 'ARRAY' ) ? @{$_[0]} : @_ ) if ( scalar @_ );
+ return wantarray ? @{_GET_VALUE_} : _REF_VALUE_;
+ },
+ 'get_push' => q{
+ push @{_REF_VALUE_}, map { ref $_ eq 'ARRAY' ? @$_ : ($_) } @_;
+ return wantarray ? @{_GET_VALUE_} : _REF_VALUE_;
+ },
+ 'ref' => q{ _REF_VALUE_ },
+ 'get' => q{ return wantarray ? @{_GET_VALUE_} : _REF_VALUE_ },
+ 'set' => q{ @{_REF_VALUE_} = @_ },
+ 'pop' => q{ pop @{_REF_VALUE_} },
+ 'push' => q{ push @{_REF_VALUE_}, @_ },
+ 'shift' => q{ shift @{_REF_VALUE_} },
+ 'unshift' => q{ unshift @{_REF_VALUE_}, @_ },
+ 'slice' => q{ _GET_VALUE_->[ @_ ] },
+ 'splice' => q{ splice @{_REF_VALUE_}, shift, shift, @_ },
+ 'count' => q{ scalar @{_GET_VALUE_} },
+ 'clear' => q{ @{ _REF_VALUE_ } = () },
+ 'index' => q{
+ my $list = _REF_VALUE_;
+ ( scalar(@_) == 1 ) ? $list->[shift]
+ : wantarray ? (map $list->[$_], @_) : [map $list->[$_], @_]
+ },
+ 'get_set_items' => q{
+ if ( scalar @_ == 0 ) {
+ return _REF_VALUE_;
+ } elsif ( scalar @_ == 1 ) {
+ return _GET_VALUE_->[ shift() ];
+ } else {
+ _BEHAVIOR_{set_items}
+ }
+ },
+ 'set_items' => q{
+ ! (@_ % 2) or croak "Odd number of items in assigment to _STATIC_ATTR_{name}";
+ while ( scalar @_ ) {
+ my ($index, $value) = splice @_, 0, 2;
+ _REF_VALUE_->[ $index ] = $value;
+ }
+ return _REF_VALUE_;
+ },
+ }
+ }
+}
+
+########################################################################
+
+=head2 hash Accessor
+
+Creates accessor methods for manipulating hashes of key-value pairs.
+
+B<Interfaces>: The following calling interfaces are available.
+
+=over 4
+
+=item default
+
+Provides get_set behavior for I<*>, and I<*>_I<verb> methods for most of the other behaviors below.
+
+=item get_set_items
+
+Provides the get_set_items for I<*>.
+
+=back
+
+B<Behaviors>: The following types of accessor methods are available.
+
+=over 4
+
+=item get_set_items
+
+Called with no arguments returns a reference to the hash stored.
+
+Called with one simple scalar argument it treats the argument as a key
+and returns the value stored under that key.
+
+Called with more than one argument, treats them as a series of key/value
+pairs and adds them to the hash.
+
+=item get_push
+
+Called with no arguments returns the hash stored, as a hash
+in a list context or as a reference in a scalar context.
+
+Called with one simple scalar argument it treats the argument as a key
+and returns the value stored under that key.
+
+Called with one array reference argument, the array elements
+are considered to be be keys of the hash. x returns the list of values
+stored under those keys (also known as a I<hash slice>.)
+
+Called with one hash reference argument, the keys and values of the
+hash are added to the hash.
+
+Called with more than one argument, treats them as a series of key/value
+pairs and adds them to the hash.
+
+=item get_set
+
+Like get_push, except if called with more then one argument, empties
+the current hash items before adding those arguments to the hash.
+
+=item push
+
+Called with one hash reference argument, the keys and values of the
+hash are added to the hash.
+
+Called with more than one argument, treats them as a series of key/value
+pairs and adds them to the hash.
+
+=item keys
+
+Returns a list of the keys of the hash.
+
+=item values
+
+Returns a list of the values in the hash.
+
+=item tally
+
+Takes a list of arguments and for each scalar in the list increments the
+value stored in the hash and returns a list of the current (after the
+increment) values.
+
+=item exists
+
+Takes a single key, returns whether that key exists in the hash.
+
+=item delete
+
+Takes a list, deletes each key from the hash, and returns the corresponding values.
+
+=item clear
+
+Resets hash to empty.
+
+=back
+
+=cut
+
+sub hash {
+ {
+ '-import' => { 'Template::Generic:generic' => '*' },
+ 'interface' => {
+ 'default' => {
+ '*'=>'get_set',
+ map {'*_'.$_ => $_} qw(push set keys values delete exists tally clear),
+ },
+ get_set_items => { '*'=>'get_set_items' },
+ },
+ 'modifier' => {
+ '-all' => [ q{ _ENSURE_REF_VALUE_; * } ],
+ },
+ 'code_expr' => {
+ '_ENSURE_REF_VALUE_' => q{ _REF_VALUE_ ||= {}; },
+ _HASH_GET_ => q{
+ ( wantarray ? %{_GET_VALUE_} : _REF_VALUE_ )
+ },
+ _HASH_GET_VALUE_ => q{
+ ( ref $_[0] eq 'ARRAY' ? @{ _GET_VALUE_ }{ @{ $_[0] } }
+ : _REF_VALUE_->{ $_[0] } )
+ },
+ _HASH_SET_ => q{
+ ! (@_ % 2) or croak "Odd number of items in assigment to _STATIC_ATTR_{name}";
+ %{_REF_VALUE_} = @_
+ },
+ _HASH_PUSH_ => q{
+ ! (@_ % 2)
+ or croak "Odd number of items in assigment to _STATIC_ATTR_{name}";
+ my $count;
+ while ( scalar @_ ) {
+ local $_ = shift;
+ _REF_VALUE_->{ $_ } = shift();
+ ++ $count;
+ }
+ $count;
+ },
+ },
+ 'behavior' => {
+ 'get_set' => q {
+ # If called with no arguments, return hash contents
+ return _HASH_GET_ if (scalar @_ == 0);
+
+ # If called with a hash ref, act as if contents of hash were passed
+ # local @_ = %{ $_[0] } if ( scalar @_ == 1 and ref $_[0] eq 'HASH' );
+ @_ = %{ $_[0] } if ( scalar @_ == 1 and ref $_[0] eq 'HASH' );
+
+ # If called with an index, get that value, or a slice for array refs
+ return _HASH_GET_VALUE_ if (scalar @_ == 1 );
+
+ # Push on new values and return complete set
+ _HASH_SET_;
+ return _HASH_GET_;
+ },
+
+ 'get_push' => q{
+ # If called with no arguments, return hash contents
+ return _HASH_GET_ if (scalar @_ == 0);
+
+ # If called with a hash ref, act as if contents of hash were passed
+ # local @_ = %{ $_[0] } if ( scalar @_ == 1 and ref $_[0] eq 'HASH' );
+ @_ = %{ $_[0] } if ( scalar @_ == 1 and ref $_[0] eq 'HASH' );
+
+ # If called with an index, get that value, or a slice for array refs
+ return _HASH_GET_VALUE_ if (scalar @_ == 1 );
+
+ # Push on new values and return complete set
+ _HASH_PUSH_;
+ return _HASH_GET_;
+ },
+ 'get_set_items' => q{
+ if ( scalar @_ == 0 ) {
+ return _REF_VALUE_;
+ } elsif ( scalar @_ == 1 ) {
+ return _REF_VALUE_->{ shift() };
+ } else {
+ while ( scalar @_ ) {
+ my ($index, $value) = splice @_, 0, 2;
+ _REF_VALUE_->{ $index } = $value;
+ }
+ return _REF_VALUE_;
+ }
+ },
+ 'get' => q{ _HASH_GET_ },
+ 'set' => q{ _HASH_SET_ },
+ 'push' => q{
+ # If called with a hash ref, act as if contents of hash were passed
+ # local @_ = %{ $_[0] } if ( scalar @_ == 1 and ref $_[0] eq 'HASH' );
+ @_ = %{ $_[0] } if ( scalar @_ == 1 and ref $_[0] eq 'HASH' );
+
+ _HASH_PUSH_
+ },
+
+ 'keys' => q{ keys %{_GET_VALUE_} },
+ 'values' => q{ values %{_GET_VALUE_} },
+ 'unique_values' => q{
+ values %{ { map { $_=>$_ } values %{_GET_VALUE_} } }
+ },
+ 'delete' => q{ scalar @_ <= 1 ? delete @{ _REF_VALUE_ }{ $_[0] }
+ : map { delete @{ _REF_VALUE_ }{ $_ } } (@_) },
+ 'exists' => q{
+ return 0 unless defined _GET_VALUE_;
+ foreach (@_) { return 0 unless exists ( _REF_VALUE_->{$_} ) }
+ return 1;
+ },
+ 'tally' => q{ map { ++ _REF_VALUE_->{$_} } @_ },
+ 'clear' => q{ %{ _REF_VALUE_ } = () },
+ 'ref' => q{ _REF_VALUE_ },
+ },
+ }
+}
+
+########################################################################
+
+=head2 tiedhash Accessor
+
+A variant of Generic:hash which initializes the hash by tieing it to a caller-specified package.
+
+See the documentation on C<Generic:hash> for interfaces and behaviors.
+
+B<Parameters>: The following parameters I<must> be provided:
+
+=over 4
+
+=item tie
+
+I<Required>. The name of the class to tie to.
+I<Make sure you have C<use>d the required class>.
+
+=item args
+
+I<Required>. Additional arguments for the tie, as an array ref.
+
+=back
+
+Example:
+
+ use Class::MakeMethods
+ tie_hash => [ hits => { tie => q/Tie::RefHash/, args => [] } ];
+
+ use Class::MakeMethods
+ tie_hash => [ [qw(hits errors)] => { tie => q/Tie::RefHash/, args => [] } ];
+
+ use Class::MakeMethods
+ tie_hash => [ { name => hits, tie => q/Tie::RefHash/, args => [] } ];
+
+=cut
+
+sub tiedhash {
+ {
+ '-import' => { 'Template::Generic:hash' => '*' },
+ 'modifier' => {
+ '-all' => [ q{
+ if ( ! defined _GET_VALUE_ ) {
+ %{ _REF_VALUE_ } = ();
+ tie %{ _REF_VALUE_ }, _ATTR_REQUIRED_{tie}, @{ _ATTR_{args} };
+ }
+ *
+ } ],
+ },
+ }
+}
+
+########################################################################
+
+=head2 hash_of_arrays Accessor
+
+Creates accessor methods for manipulating hashes of array-refs.
+
+B<Interfaces>: The following calling interfaces are available.
+
+=over 4
+
+=item default
+
+Provides get behavior for I<*>, and I<*>_I<verb> methods for the other behaviors below.
+
+=back
+
+B<Behaviors>: The following types of accessor methods are available.
+
+=over 4
+
+=item get
+
+Returns all the values for all the given keys, in order. If no keys are
+given, returns all the values (in an unspecified key order).
+
+The result is returned as an arrayref in scalar context. This arrayref
+is I<not> part of the data structure; messing with it will not affect
+the contents directly (even if a single key was provided as argument.)
+
+If any argument is provided which is an arrayref, then the members of
+that array are used as keys. Thus, the trivial empty-key case may be
+utilized with an argument of [].
+
+=item keys
+
+Returns the keys of the hash. As an arrayref in scalar context.
+
+=item exists
+
+Takes a list of keys, and returns whether all of the key exists in the hash
+(i.e., the C<and> of whether the individual keys exist).
+
+=item delete
+
+Takes a list, deletes each key from the hash.
+
+=item push
+
+Takes a key, and some values. Pushes the values onto the list denoted
+by the key. If the first argument is an arrayref, then each element of
+that arrayref is treated as a key and the elements pushed onto each
+appropriate list.
+
+=item pop
+
+Takes a list of keys, and pops each one. Returns the list of popped
+elements. undef is returned in the list for each key that is has an
+empty list.
+
+=item unshift
+
+Like push, only the from the other end of the lists.
+
+=item shift
+
+Like pop, only the from the other end of the lists.
+
+=item splice
+
+Takes a key, offset, length, and a values list. Splices the list named
+by the key. Anything from the offset argument (inclusive) may be
+omitted. See L<perlfunc/splice>.
+
+=item clear
+
+Takes a list of keys. Resets each named list to empty (but does not
+delete the keys.)
+
+=item count
+
+Takes a list of keys. Returns the sum of the number of elements for
+each named list.
+
+=item index
+
+Takes a key, and a list of indices. Returns a list of each item at the
+corresponding index in the list of the given key. Uses undef for
+indices beyond range.
+
+=item remove
+
+Takes a key, and a list of indices. Removes each corresponding item
+from the named list. The indices are effectively looked up at the point
+of call -- thus removing indices 3, 1 from list (a, b, c, d) will
+remove (d) and (b).
+
+=item sift
+
+Takes a key, and a set of named arguments, which may be a list or a hash
+ref. Removes list members based on a grep-like approach.
+
+=over 4
+
+=item filter
+
+The filter function used (as a coderef). Is passed two arguments, the
+value compared against, and the value in the list that is potential for
+grepping out. If returns true, the value is removed. Default is C<sub { $_[0] == $_[1] }>.
+
+=item keys
+
+The list keys to sift through (as an arrayref). Unknown keys are
+ignored. Default: all the known keys.
+
+=item values
+
+The values to sift out (as an arrayref). Default: C<[undef]>
+
+=back
+
+=back
+
+=cut
+
+sub hash_of_arrays {
+ {
+ '-import' => { 'Template::Generic:hash' => '*' },
+ 'interface' => {
+ default => {
+ '*'=>'get',
+ map( ('*_'.$_ => $_ ), qw(keys exists delete pop push shift unshift splice clear count index remove sift last set )),
+ },
+ },
+ 'behavior' => {
+ 'get' => q{
+ my @Result;
+
+ if ( ! scalar @_ ) {
+ @Result = map @$_, values %{_VALUE_};
+ } elsif ( scalar @_ == 1 and ref ($_[0]) eq 'ARRAY' ) {
+ @Result = map @$_, @{_VALUE_}{@{$_[0]}};
+ } else {
+ my @keys = map { ref ($_) eq 'ARRAY' ? @$_ : $_ }
+ grep exists _VALUE_{$_}, @_;
+ @Result = map @$_, @{_VALUE_}{@keys};
+ }
+
+ return wantarray ? @Result : \@Result;
+ },
+ 'pop' => q{
+ map { pop @{_VALUE_->{$_}} } @_
+ },
+ 'last' => q{
+ map { _VALUE_->{$_}->[-1] } @_
+ },
+ 'push' => q{
+ for ( ( ref ($_[0]) eq 'ARRAY' ? @{shift()} : shift() ) ) {
+ push @{_VALUE_->{$_}}, @_;
+ }
+ },
+ 'shift' => q{
+ map { shift @{_VALUE_->{$_}} } @_
+ },
+ 'unshift' => q{
+ for ( ( ref ($_[0]) eq 'ARRAY' ? @{shift()} : shift() ) ) {
+ unshift @{_VALUE_->{$_}}, @_;
+ }
+ },
+ 'splice' => q{
+ my $key = shift;
+ splice @{ _VALUE_->{$key} }, shift, shift, @_;
+ },
+ 'clear' => q{
+ foreach (@_) { _VALUE_->{$_} = []; }
+ },
+ 'count' => q{
+ my $Result = 0;
+ foreach (@_) {
+ # Avoid autovivifying additional entries.
+ $Result += exists _VALUE_->{$_} ? scalar @{_VALUE_->{$_}} : 0;
+ }
+ return $Result;
+ },
+ 'index' => q{
+ my $key_r = shift;
+
+ my @Result;
+ my $key;
+ foreach $key ( ( ref ($key_r) eq 'ARRAY' ? @$key_r : $key_r ) ) {
+ my $ary = _VALUE_->{$key};
+ for (@_) {
+ push @Result, ( @{$ary} > $_ ) ? $ary->[$_] : undef;
+ }
+ }
+ return wantarray ? @Result : \@Result;
+ },
+ 'set' => q{
+ my $key_r = shift;
+
+ croak "_ATTR_{name} expects a key and then index => value pairs.\n"
+ if @_ % 2;
+ while ( scalar @_ ) {
+ my $pos = shift;
+ _VALUE_->{$key_r}->[ $pos ] = shift();
+ }
+ return;
+ },
+ 'remove' => q{
+ my $key_r = shift;
+
+ my $key;
+ foreach $key ( ( ref ($key_r) eq 'ARRAY' ? @$key_r : $key_r ) ) {
+ my $ary = _VALUE_->{$key};
+ foreach ( sort {$b<=>$a} grep $_ < @$ary, @_ ) {
+ splice (@$ary, $_, 1);
+ }
+ }
+ return;
+ },
+ 'sift' => q{
+ my %args = ( scalar @_ == 1 and ref $_[0] eq 'HASH' ) ? %{$_[0]} : @_;
+ my $hash = _VALUE_;
+ my $filter_sr = $args{'filter'} || sub { $_[0] == $_[1] };
+ my $keys_ar = $args{'keys'} || [ keys %$hash ];
+ my $values_ar = $args{'values'} || [undef];
+
+ # This is harder than it looks; reverse means we want to grep out only
+ # if *none* of the values matches. I guess an evaled block, or closure
+ # or somesuch is called for.
+ # my $reverse = $args{'reverse'} || 0;
+
+ my ($key, $i, $value);
+ KEY: foreach $key (@$keys_ar) {
+ next KEY unless exists $hash->{$key};
+ INDEX: for ($i = $#{$hash->{$key}}; $i >= 0; $i--) {
+ foreach $value (@$values_ar) {
+ if ( $filter_sr->($value, $hash->{$key}[$i]) ) {
+ splice @{$hash->{$key}}, $i, 1;
+ next INDEX;
+ }
+ }
+ }
+ }
+ return;
+ },
+ },
+ }
+}
+
+########################################################################
+
+=head2 object Accessor
+
+Creates accessor methods for manipulating references to objects.
+
+In addition to creating a method to get and set the object reference,
+the meta-method can also define forwarded methods that automatically
+pass calls onto the object stored in that slot; see the description of the 'delegate' parameter below.
+
+B<Interfaces>: The following calling interfaces are available.
+
+=over 4
+
+=item default
+
+Provides get_set behavior for I<*>, clear behavior for 'delete_*',
+and forwarding methods for any values in the method's 'delegate'
+or 'soft_delegate' parameters.
+
+=item get_and_set
+
+Provides named get method, set_I<x> and clear_I<x> methods.
+
+=item get_init_and_set
+
+Provides named get_init method, set_I<x> and clear_I<x> methods.
+
+=back
+
+B<Behaviors>: The following types of accessor methods are available.
+
+=over 4
+
+=item get_set
+
+The get_set method, if called with a reference to an object of the
+given class as the first argument, stores it.
+
+If called with any other arguments, creates and stores a new object, passing the arguemnts to the new() method for the object.
+
+If called without arguments, returns the current value, which may be undefined if one has not been stored yet.
+
+=item get_set_init
+
+The get_set_init method, if called with a reference to an object of the
+given class as the first argument, stores it.
+
+If the slot is not filled yet it creates an object by calling the given
+new method of the given class. Any arguments passed to the get_set_init
+method are passed on to new.
+
+In all cases the object now stored is returned.
+
+=item get_init
+
+If the instance is empty, creates and stores a new one. Returns the instance.
+
+=item get
+
+Returns the current value, which may be undefined if one has not been stored yet.
+
+=item set
+
+If called with a reference to an object of the given class as the first argument, stores it.
+
+If called with any other arguments, creates and stores a new object, passing the arguments to the new() method.
+
+If called without arguments, creates and stores a new object, without any arguments to the new() method.
+
+=item clear
+
+Removes the reference value.
+
+=item I<forwarding>
+
+If a 'delegate' or 'soft_delegate' parameter is provided, methods
+with those names are created that are forwarded directly to the
+object in the slot, as described below.
+
+=back
+
+B<Parameters>: The following parameters are supported:
+
+=over 4
+
+=item class
+
+I<Required>. The type of object that will be stored.
+
+=item new_method
+
+The name of the method to call on the above class to create a new instance. Defaults to 'new'.
+
+=item delegate
+
+The methods to forward to the object. Can contain a method name,
+a string of space-spearated method names, or an array of method
+names. This type of method will croak if it is called when the
+target object is not defined.
+
+=item soft_delegate
+
+The methods to forward to the object, if it is present. Can contain
+a method name, a string of space-spearated method names, or an
+array of method names. This type of method will return nothing if
+it is called when the target object is not defined.
+
+=back
+
+=cut
+
+sub object {
+ {
+ '-import' => {
+ # 'Template::Generic:generic' => '*',
+ },
+ 'interface' => {
+ default => { '*'=>'get_set', 'clear_*'=>'clear' },
+ get_set_init => { '*'=>'get_set_init', 'clear_*'=>'clear' },
+ get_and_set => {'*'=>'get', 'set_*'=>'set', 'clear_*'=>'clear' },
+ get_init_and_set => { '*'=>'get_init','set_*'=>'set','clear_*'=>'clear' },
+ init_and_get => { '*'=>'init_and_get', -params=>{ init_method=>'init_*' } },
+ },
+ 'params' => {
+ new_method => 'new'
+ },
+ 'code_expr' => {
+ '_CALL_NEW_AND_STORE_' => q{
+ my $new_method = _ATTR_REQUIRED_{new_method};
+ my $class = _ATTR_REQUIRED_{'class'};
+ _SET_VALUE_{ $class->$new_method(@_) };
+ },
+ },
+ 'behavior' => {
+ '-import' => {
+ 'Template::Generic:scalar' => [ qw( get clear ) ],
+ },
+ 'get_set' => q{
+ if ( scalar @_ ) {
+ if (ref $_[0] and UNIVERSAL::isa($_[0], _ATTR_REQUIRED_{'class'})) {
+ _SET_VALUE_{ shift };
+ } else {
+ _CALL_NEW_AND_STORE_
+ }
+ } else {
+ _VALUE_;
+ }
+ },
+ 'set' => q{
+ if ( ! defined $_[0] ) {
+ _SET_VALUE_{ undef };
+ } elsif (ref $_[0] and UNIVERSAL::isa($_[0], _ATTR_REQUIRED_{'class'})) {
+ _SET_VALUE_{ shift };
+ } else {
+ _CALL_NEW_AND_STORE_
+ }
+ },
+ 'get_init' => q{
+ if ( ! defined _VALUE_ ) {
+ _CALL_NEW_AND_STORE_
+ }
+ _VALUE_;
+ },
+ 'init_and_get' => q{
+ if ( ! defined _VALUE_ ) {
+ my $init_method = _ATTR_REQUIRED_{'init_method'};
+ _SET_VALUE_{ _SELF_->$init_method( @_ ) };
+ } else {
+ _BEHAVIOR_{get}
+ }
+ },
+ 'get_set_init' => q{
+ if (ref $_[0] and UNIVERSAL::isa($_[0], _ATTR_REQUIRED_{'class'})) {
+ _SET_VALUE_{ shift };
+ } elsif ( ! defined _VALUE_ ) {
+ _CALL_NEW_AND_STORE_
+ }
+ _VALUE_;
+ },
+ '-subs' => sub {
+ {
+ 'delegate' => sub { my($m_info, $name) = @_; sub {
+ my $m_name = $m_info->{'name'};
+ my $obj = (shift)->$m_name()
+ or Carp::croak("Can't forward $name because $m_name is empty");
+ $obj->$name(@_)
+ } },
+ 'soft_delegate' => sub { my($m_info, $name) = @_; sub {
+ my $m_name = $m_info->{'name'};
+ my $obj = (shift)->$m_name() or return;
+ $obj->$name(@_)
+ } },
+ }
+ },
+ },
+ }
+}
+
+########################################################################
+
+=head2 instance Accessor
+
+Creates methods to handle an instance of the calling class.
+
+PROFILES
+
+=over 4
+
+=item default
+
+Provides named get method, and I<verb>_I<x> set, new, and clear methods.
+
+=item -implicit_new
+
+Provides named get_init method, and I<verb>_I<x> set, and clear methods.
+
+=item -x_verb
+
+Provides named get method, and I<x>_I<verb> set, new, and clear methods.
+
+=back
+
+B<Behaviors>: The following types of accessor methods are available.
+
+=over 4
+
+=item get
+
+Returns the value of the instance parameter, which may be undefined if one has not been stored yet.
+
+=item get_init
+
+If the instance is empty, creates and stores a new one. Returns the instance.
+
+=item set
+
+Takes a single argument and sets the instance to that value.
+
+=item new
+
+Creates and stores a new instance.
+
+=item clear
+
+Sets the instance parameter to undef.
+
+=back
+
+B<Parameters>: The following parameters are supported:
+
+=over 4
+
+=item instance
+
+Holds the instance reference. Defaults to undef
+
+=item new_method
+
+The name of the method to call when creating a new instance. Defaults to 'new'.
+
+=back
+
+=cut
+
+sub instance {
+ {
+ '-import' => {
+ 'Template::Generic:object' => '*',
+ },
+ 'interface' => {
+ default => 'get_set',
+ },
+ 'code_expr' => {
+ '_CALL_NEW_AND_STORE_' => q{
+ my $new_method = _ATTR_REQUIRED_{new_method};
+ _SET_VALUE_{ (_SELF_)->$new_method(@_) };
+ },
+ },
+ }
+}
+
+########################################################################
+
+=head2 array_of_objects Accessor
+
+Creates accessor methods for manipulating references to arrays of object references.
+
+Operates like C<Generic:array>, but prior to adding any item to
+the array, it first checks to see if it is an instance of the
+designated class, and if not passes it as an argument to that
+class's new method and stores the result instead.
+
+Forwarded methods return a list of the results returned
+by C<map>ing the method over each object in the array.
+
+See the documentation on C<Generic:array> for interfaces and behaviors.
+
+B<Parameters>: The following parameters are supported:
+
+=over 4
+
+=item class
+
+I<Required>. The type of object that will be stored.
+
+=item delegate
+
+The methods to forward to the object. Can contain a method name, a string of space-spearated method names, or an array of method names.
+
+=item new_method
+
+The name of the method to call on the above class to create a new instance. Defaults to 'new'.
+
+=back
+
+=cut
+
+sub array_of_objects {
+ {
+ '-import' => {
+ 'Template::Generic:array' => '*',
+ },
+ 'params' => {
+ new_method => 'new',
+ },
+ 'modifier' => {
+ '-all get_set' => q{ _BLESS_ARGS_ * },
+ '-all get_push' => q{ _BLESS_ARGS_ * },
+ '-all set' => q{ _BLESS_ARGS_ * },
+ '-all push' => q{ _BLESS_ARGS_ * },
+ '-all unshift' => q{ _BLESS_ARGS_ * },
+ # The below two methods are kinda broken, because the new values
+ # don't get auto-blessed properly...
+ '-all splice' => q{ * },
+ '-all set_items' => q{ * },
+ },
+ 'code_expr' => {
+ '_BLESS_ARGS_' => q{
+ my $new_method = _ATTR_REQUIRED_{'new_method'};
+ @_ = map {
+ (ref $_ and UNIVERSAL::isa($_, _ATTR_REQUIRED_{class})) ? $_
+ : _ATTR_{'class'}->$new_method($_)
+ } @_;
+ },
+ },
+ 'behavior' => {
+ '-subs' => sub {
+ {
+ 'delegate' => sub { my($m_info, $name) = @_; sub {
+ my $m_name = $m_info->{'name'};
+ map { $_->$name(@_) } (shift)->$m_name()
+ } },
+ }
+ },
+ },
+ }
+}
+
+########################################################################
+
+=head2 code Accessor
+
+Creates accessor methods for manipulating references to subroutines.
+
+B<Interfaces>: The following calling interfaces are available.
+
+=over 4
+
+=item default
+
+Provides the call_set functionality.
+
+=item method
+
+Provides the call_method functionality.
+
+=back
+
+B<Behaviors>: The following types of accessor methods are available.
+
+=over 4
+
+=item call_set
+
+If called with one argument which is a CODE reference, it installs that
+code in the slot. Otherwise it runs the code stored in the slot with
+whatever arguments (including none) were passed in.
+
+=item call_method
+
+Just like B<call_set>, except the code is called like a method, with $self
+as its first argument. Basically, you are creating a method which can be
+different for each object.
+
+=back
+
+=cut
+
+sub code {
+ {
+ '-import' => {
+ # 'Template::Generic:generic' => '*',
+ },
+ 'interface' => {
+ default => 'call_set',
+ call_set => 'call_set',
+ method => 'call_method',
+ },
+ 'behavior' => {
+ '-import' => {
+ 'Template::Generic:scalar' => [ qw( get_set get set clear ) ],
+ },
+ 'call_set' => q{
+ if ( scalar @_ == 1 and ref($_[0]) eq 'CODE') {
+ _SET_VALUE_{ shift }; # Set the subroutine reference
+ } else {
+ &{ _VALUE_ }( @_ ); # Run the subroutine on the given arguments
+ }
+ },
+ 'call_method' => q{
+ if ( scalar @_ == 1 and ref($_[0]) eq 'CODE') {
+ _SET_VALUE_{ shift }; # Set the subroutine reference
+ } else {
+ &{ _VALUE_ }( _SELF_, @_ ); # Run the subroutine on self and args
+ }
+ },
+ },
+ }
+}
+
+
+########################################################################
+
+=head2 code_or_scalar Accessor
+
+Creates accessor methods for manipulating either strings or references to subroutines.
+
+You can store any scalar value; code refs are executed when you retrieve the value, while other scalars are returned as-is.
+
+B<Interfaces>: The following calling interfaces are available.
+
+=over 4
+
+=item default
+
+Provides the call_set functionality.
+
+=item method
+
+Provides the call_method functionality.
+
+=item eiffel
+
+Provides the named get_method, and a helper set_* method.
+
+=back
+
+B<Behaviors>: The following types of accessor methods are available.
+
+=over 4
+
+=item get_set_call
+
+If called with an argument, either a CODE reference or some other scalar, it installs that code in the slot. Otherwise, if the current value runs the code stored in the slot with
+whatever arguments (including none) were passed in.
+
+=item get_set_method
+
+Just like B<call_set>, except the code is called like a method, with $self
+as its first argument. Basically, you are creating a method which can be
+different for each object.
+
+=back
+
+=cut
+
+sub code_or_scalar {
+ {
+ '-import' => { 'Template::Generic:scalar' => '*' },
+ 'interface' => {
+ default => 'get_set_call',
+ get_set => 'get_set_call',
+ eiffel => { '*'=>'get_method', 'set_*'=>'set' },
+ method => 'get_set_method',
+ },
+ 'params' => {
+ },
+ 'behavior' => {
+ 'get_call' => q{
+ my $value = _GET_VALUE_;
+ ( ref($value) eq 'CODE' ) ? &$value( @_ ) : $value
+ },
+ 'get_method' => q{
+ my $value = _GET_VALUE_;
+ ( ref($value) eq 'CODE' ) ? &$value( _SELF_, @_ ) : $value
+ },
+ 'get_set_call' => q{
+ if ( scalar @_ == 1 ) {
+ _BEHAVIOR_{set}
+ } else {
+ _BEHAVIOR_{get_call}
+ }
+ },
+ 'get_set_method' => q{
+ if ( scalar @_ == 1 ) {
+ _BEHAVIOR_{set}
+ } else {
+ _BEHAVIOR_{get_call}
+ }
+ },
+ },
+ }
+}
+
+
+########################################################################
+
+=head1 SEE ALSO
+
+See L<Class::MakeMethods> for general information about this distribution.
+
+See L<Class::MakeMethods::Template> for information about this family of subclasses.
+
+=cut
+
+1;
diff --git a/lib/Class/MakeMethods/Template/Global.pm b/lib/Class/MakeMethods/Template/Global.pm
new file mode 100644
index 0000000..0e4c79e
--- /dev/null
+++ b/lib/Class/MakeMethods/Template/Global.pm
@@ -0,0 +1,97 @@
+package Class::MakeMethods::Template::Global;
+
+use Class::MakeMethods::Template::Generic '-isasubclass';
+
+$VERSION = 1.008;
+use strict;
+require 5.0;
+
+=head1 NAME
+
+Class::MakeMethods::Template::Global - Method that are not instance-dependent
+
+=head1 SYNOPSIS
+
+ package MyObject;
+ use Class::MakeMethods::Template::Global (
+ scalar => [ 'foo' ]
+ );
+
+ package main;
+
+ MyObject->foo('bar')
+ print MyObject->foo();
+ ...
+ print $my_instance->foo(); # same thing
+
+=head1 DESCRIPTION
+
+These meta-methods access values that are shared across all instances
+of your object in your process. For example, a hash_scalar meta-method
+will be able to store a different value for each hash instance you
+call it on, but a static_scalar meta-method will return the same
+value for any instance it's called on, and setting it from any
+instance will change the value that all other instances see.
+
+B<Common Parameters>: The following parameters are defined for Static meta-methods.
+
+=over 4
+
+=item data
+
+The shared value.
+
+=back
+
+=cut
+
+sub generic {
+ {
+ '-import' => {
+ 'Template::Generic:generic' => '*'
+ },
+ 'code_expr' => {
+ _VALUE_ => '_ATTR_{data}',
+ },
+ 'params' => {
+ 'data' => undef,
+ }
+ }
+}
+
+########################################################################
+
+=head2 Standard Methods
+
+The following methods from Generic should be supported:
+
+ scalar
+ string
+ number
+ boolean
+ bits (?)
+ array
+ hash
+ tiedhash (?)
+ hash_of_arrays (?)
+ object
+ instance
+ array_of_objects (?)
+ code
+ code_or_scalar (?)
+
+See L<Class::MakeMethods::Template::Generic> for the interfaces and behaviors of these method types.
+
+The items marked with a ? above have not been tested sufficiently; please inform the author if they do not function as you would expect.
+
+=head1 SEE ALSO
+
+See L<Class::MakeMethods> for general information about this distribution.
+
+See L<Class::MakeMethods::Template> for more about this family of subclasses.
+
+See L<Class::MakeMethods::Template::Generic> for information about the various accessor interfaces subclassed herein.
+
+=cut
+
+1;
diff --git a/lib/Class/MakeMethods/Template/Hash.pm b/lib/Class/MakeMethods/Template/Hash.pm
new file mode 100644
index 0000000..9163178
--- /dev/null
+++ b/lib/Class/MakeMethods/Template/Hash.pm
@@ -0,0 +1,229 @@
+package Class::MakeMethods::Template::Hash;
+
+use Class::MakeMethods::Template::Generic '-isasubclass';
+
+$VERSION = 1.008;
+use strict;
+require 5.0;
+
+sub generic {
+ {
+ 'params' => {
+ 'hash_key' => '*',
+ },
+ 'code_expr' => {
+ _VALUE_ => '_SELF_->{_STATIC_ATTR_{hash_key}}',
+ '-import' => { 'Template::Generic:generic' => '*' },
+ _EMPTY_NEW_INSTANCE_ => 'bless {}, _SELF_CLASS_',
+ _SET_VALUES_FROM_HASH_ => 'while ( scalar @_ ) { local $_ = shift(); $self->{ $_ } = shift() }'
+ },
+ 'behavior' => {
+ 'hash_delete' => q{ delete _VALUE_ },
+ 'hash_exists' => q{ exists _VALUE_ },
+ },
+ 'modifier' => {
+ # XXX the below doesn't work because modifiers can't have params,
+ # although interfaces can... Either add support for default params
+ # in modifiers, or else move this to another class.
+ # X Should there be a version which uses caller() instead of target_class?
+ 'class_keys' => { 'hash_key' => '"*{target_class}::*{name}"' },
+ }
+ }
+}
+
+########################################################################
+
+=head1 NAME
+
+Class::MakeMethods::Template::Hash - Method interfaces for hash-based objects
+
+=head1 SYNOPSIS
+
+ package MyObject;
+ use Class::MakeMethods::Template::Hash (
+ new => [ 'new' ],
+ scalar => [ 'foo', 'bar' ]
+ );
+
+ package main;
+
+ my $obj = MyObject->new( foo => "Foozle", bar => "Bozzle" );
+ print $obj->foo();
+ $obj->bar("Bamboozle");
+
+=head1 DESCRIPTION
+
+These meta-methods create and access values within blessed hash objects.
+
+B<Common Parameters>: The following parameters are defined for Hash meta-methods.
+
+=over 4
+
+=item hash_key
+
+The hash key to use when retrieving values from each hash instance. Defaults to '*', the name of the meta-method.
+
+Changing this allows you to change an accessor method name to something other than the name of the hash key used to retrieve its value.
+
+Note that this parameter is not portable to the other implementations, such as Global or InsideOut.
+
+You can take advantage of parameter expansion to define methods whose hash key is composed of the defining package's name and the individual method name, such as C<$self-E<gt>{I<MyObject>-I<foo>}>:
+
+ 'hash_key' => '*{target_class}-*{name}'
+
+=back
+
+B<Common Behaviors>
+
+=over 4
+
+=item Behavior: delete
+
+Deletes the named key and associated value from the current hash instance.
+
+=back
+
+=head2 Standard Methods
+
+The following methods from Generic are all supported:
+
+ new
+ scalar
+ string
+ string_index
+ number
+ boolean
+ bits (*)
+ array
+ hash
+ tiedhash
+ hash_of_arrays
+ object
+ instance
+ array_of_objects
+ code
+ code_or_scalar
+
+See L<Class::MakeMethods::Template::Generic> for the interfaces and behaviors of these method types.
+
+The items marked with a * above are specifically defined in this package, whereas the others are formed automatically by the interaction of this package's generic settings with the code templates provided by the Generic superclass.
+
+=cut
+
+# This is the only one that needs to be specifically defined.
+sub bits {
+ {
+ '-import' => { 'Template::Generic:bits' => '*' },
+ 'params' => {
+ 'hash_key' => '*{target_class}__*{template_name}',
+ },
+ }
+}
+
+########################################################################
+
+=head2 struct
+
+ struct => [ qw / foo bar baz / ];
+
+Creates methods for setting, checking and clearing values which
+are stored by position in an array. All the slots created with this
+meta-method are stored in a single array.
+
+The argument to struct should be a string or a reference to an
+array of strings. For each string meta-method x, it defines two
+methods: I<x> and I<clear_x>. x returns the value of the x-slot.
+If called with an argument, it first sets the x-slot to the argument.
+clear_x sets the slot to undef.
+
+Additionally, struct defines three class method: I<struct>, which returns
+a list of all of the struct values, I<struct_fields>, which returns
+a list of all the slots by name, and I<struct_dump>, which returns a hash of
+the slot-name/slot-value pairs.
+
+=cut
+
+sub struct {
+ ( {
+ 'interface' => {
+ default => {
+ '*'=>'get_set', 'clear_*'=>'clear',
+ 'struct_fields'=>'struct_fields',
+ 'struct'=>'struct', 'struct_dump'=>'struct_dump'
+ },
+ },
+ 'params' => {
+ 'hash_key' => '*{target_class}__*{template_name}',
+ },
+ 'behavior' => {
+ '-init' => sub {
+ my $m_info = $_[0];
+
+ $m_info->{class} ||= $m_info->{target_class};
+
+ my $class_info =
+ ($Class::MakeMethods::Template::Hash::struct{$m_info->{class}} ||= []);
+ if ( ! defined $m_info->{sfp} ) {
+ foreach ( 0..$#$class_info ) {
+ if ( $class_info->[$_] eq $m_info->{'name'} ) {
+ $m_info->{sfp} = $_;
+ last
+ }
+ }
+ if ( ! defined $m_info->{sfp} ) {
+ push @$class_info, $m_info->{'name'};
+ $m_info->{sfp} = $#$class_info;
+ }
+ }
+ return;
+ },
+
+ 'struct_fields' => sub { my $m_info = $_[0]; sub {
+ my $class_info =
+ ( $Class::MakeMethods::Template::Hash::struct{$m_info->{class}} ||= [] );
+ @$class_info;
+ }},
+ 'struct' => sub { my $m_info = $_[0]; sub {
+ my $self = shift;
+ $self->{$m_info->{hash_key}} ||= [];
+ if ( @_ ) { @{$self->{$m_info->{hash_key}}} = @_ }
+ @{$self->{$m_info->{hash_key}}};
+ }},
+ 'struct_dump' => sub { my $m_info = $_[0]; sub {
+ my $self = shift;
+ my $class_info =
+ ( $Class::MakeMethods::Template::Hash::struct{$m_info->{class}} ||= [] );
+ map { ($_, $self->$_()) } @$class_info;
+ }},
+
+ 'get_set' => sub { my $m_info = $_[0]; sub {
+ my $self = shift;
+ $self->{$m_info->{hash_key}} ||= [];
+
+ if ( @_ ) {
+ $self->{$m_info->{hash_key}}->[ $m_info->{sfp} ] = shift;
+ }
+ $self->{$m_info->{hash_key}}->[ $m_info->{sfp} ];
+ }},
+ 'clear' => sub { my $m_info = $_[0]; sub {
+ my $self = shift;
+ $self->{$m_info->{hash_key}} ||= [];
+ $self->{$m_info->{hash_key}}->[ $m_info->{sfp} ] = undef;
+ }},
+ },
+ } )
+}
+
+########################################################################
+
+=head1 SEE ALSO
+
+See L<Class::MakeMethods> for general information about this distribution.
+
+See L<Class::MakeMethods::Template> for more about this family of subclasses.
+
+See L<Class::MakeMethods::Template::Generic> for information about the various accessor interfaces subclassed herein.
+
+=cut
+
+1;
diff --git a/lib/Class/MakeMethods/Template/Inheritable.pm b/lib/Class/MakeMethods/Template/Inheritable.pm
new file mode 100644
index 0000000..ac6e7c0
--- /dev/null
+++ b/lib/Class/MakeMethods/Template/Inheritable.pm
@@ -0,0 +1,154 @@
+=head1 NAME
+
+Class::MakeMethods::Template::Inheritable - Overridable data
+
+=head1 SYNOPSIS
+
+ package MyClass;
+
+ use Class::MakeMethods( 'Template::Inheritable:scalar' => 'foo' );
+ # We now have an accessor method for an "inheritable" scalar value
+
+ MyClass->foo( 'Foozle' ); # Set a class-wide value
+ print MyClass->foo(); # Retrieve class-wide value
+
+ my $obj = MyClass->new(...);
+ print $obj->foo(); # All instances "inherit" that value...
+
+ $obj->foo( 'Foible' ); # until you set a value for an instance.
+ print $obj->foo(); # This now finds object-specific value.
+ ...
+
+ package MySubClass;
+ @ISA = 'MyClass';
+
+ print MySubClass->foo(); # Intially same as superclass,
+ MySubClass->foo('Foobar'); # but overridable per subclass,
+ print $subclass_obj->foo(); # and shared by its instances
+ $subclass_obj->foo('Fosil');# until you override them...
+ ...
+
+=head1 DESCRIPTION
+
+The MakeMethods subclass provides accessor methods that search an inheritance tree to find a value. This allows you to set a shared or default value for a given class, and optionally override it in a subclass.
+
+=cut
+
+########################################################################
+
+package Class::MakeMethods::Template::Inheritable;
+
+use Class::MakeMethods::Template::Generic '-isasubclass';
+
+$VERSION = 1.008;
+use strict;
+require 5.0;
+use Carp;
+
+sub generic {
+ {
+ '-import' => {
+ 'Template::Generic:generic' => '*'
+ },
+ 'modifier' => {
+ '-all' => [ q{
+ _INIT_VALUE_CLASS_
+ *
+ } ],
+ },
+ 'code_expr' => {
+ '_VALUE_CLASS_' => '$_value_class',
+ '_INIT_VALUE_CLASS_' => q{
+ my _VALUE_CLASS_;
+ my @_INC_search = ( _SELF_, _SELF_CLASS_ );
+ while ( scalar @_INC_search ) {
+ _VALUE_CLASS_ = shift @_INC_search;
+ last if ( exists _ATTR_{data}->{_VALUE_CLASS_} );
+ no strict 'refs';
+ unshift @_INC_search, @{"_VALUE_CLASS_\::ISA"} if ! ref _VALUE_CLASS_;
+ }
+ },
+ '_VALUE_' => '_ATTR_{data}->{_VALUE_CLASS_}',
+ '_GET_VALUE_' => q{ _ATTR_{data}->{_VALUE_CLASS_} },
+ '_SET_VALUE_{}' => q{ do { my $data = *; defined($data) ? ( _VALUE_CLASS_ = _SELF_ and _ATTR_{data}->{_SELF_} = $data ) : ( delete _ATTR_{data}->{_SELF_} and undef ) } },
+ },
+ }
+}
+
+########################################################################
+
+=head2 Standard Methods
+
+The following methods from Generic should be supported:
+
+ scalar
+ string
+ string_index (?)
+ number
+ boolean (?)
+ bits (?)
+ array (?)
+ hash (?)
+ tiedhash (?)
+ hash_of_arrays (?)
+ object (?)
+ instance (?)
+ array_of_objects (?)
+ code (?)
+ code_or_scalar (?)
+
+See L<Class::MakeMethods::Template::Generic> for the interfaces and behaviors of these method types.
+
+The items marked with a * above are specifically defined in this package, whereas the others are formed automatically by the interaction of this package's generic settings with the code templates provided by the Generic superclass.
+
+The items marked with a ? above have not been tested sufficiently; please inform the author if they do not function as you would expect.
+
+=cut
+
+sub array {
+ {
+ '-import' => {
+ 'Template::Generic:array' => '*',
+ },
+ 'modifier' => {
+ '-all' => q{ _INIT_VALUE_CLASS_; _ENSURE_REF_VALUE_; * },
+ },
+ 'code_expr' => {
+ '_ENSURE_REF_VALUE_' => q{ _VALUE_ ||= []; },
+ '_REF_VALUE_' => '(\@{_ATTR_{data}->{_VALUE_CLASS_}})',
+ },
+ }
+}
+
+sub hash {
+ {
+ '-import' => {
+ 'Template::Generic:hash' => '*',
+ },
+ 'modifier' => {
+ '-all' => q{ _INIT_VALUE_CLASS_; _ENSURE_REF_VALUE_; * },
+ },
+ 'code_expr' => {
+ '_ENSURE_REF_VALUE_' => q{ _VALUE_ ||= {}; },
+ '_REF_VALUE_' => '(\%{_ATTR_{data}->{_VALUE_CLASS_}})',
+ },
+ }
+}
+
+########################################################################
+
+=head1 SEE ALSO
+
+See L<Class::MakeMethods> for general information about this distribution.
+
+See L<Class::MakeMethods::Template> for more about this family of subclasses.
+
+See L<Class::MakeMethods::Template::Generic> for information about the various accessor interfaces subclassed herein.
+
+If you just need scalar accessors, see L<Class::Data::Inheritable> for a very elegant and efficient implementation.
+
+=cut
+
+########################################################################
+
+1;
diff --git a/lib/Class/MakeMethods/Template/InsideOut.pm b/lib/Class/MakeMethods/Template/InsideOut.pm
new file mode 100644
index 0000000..964856c
--- /dev/null
+++ b/lib/Class/MakeMethods/Template/InsideOut.pm
@@ -0,0 +1,218 @@
+package Class::MakeMethods::Template::InsideOut;
+
+use Class::MakeMethods::Template::Generic '-isasubclass';
+
+$VERSION = 1.008;
+use strict;
+require 5.0;
+
+my %ClassInfo;
+my %Data;
+
+sub generic {
+ {
+ '-import' => {
+ 'Template::Generic:generic' => '*'
+ },
+ 'code_expr' => {
+ '_VALUE_' => '_ATTR_{data}->{_SELF_}',
+ },
+ 'behavior' => {
+ -register => [ sub {
+ my $m_info = shift;
+ my $class_info = ( $ClassInfo{$m_info->{target_class}} ||= [] );
+ return (
+ 'DESTROY' => sub {
+ my $self = shift;
+ foreach ( @$class_info ) { delete $self->{data}->{$self} }
+ # $self->SUPER::DESTROY( @_ )
+ },
+ );
+ } ],
+ }
+ }
+}
+
+########################################################################
+
+=head1 NAME
+
+Class::MakeMethods::Template::InsideOut - External data
+
+=head1 SYNOPSIS
+
+ package MyObject;
+ use Class::MakeMethods::Template::InsideOut (
+ scalar => [ 'foo', 'bar' ]
+ );
+ sub new { ... }
+
+ package main;
+
+ my $obj = MyObject->new( foo => "Foozle", bar => "Bozzle" );
+ print $obj->foo(); # Prints Foozle
+ $obj->bar("Bamboozle"); # Sets $obj's bar value
+
+=head1 DESCRIPTION
+
+Supports the Generic object constructor and accessors meta-method
+types, but accepts any object as the underlying implementation type,
+with member data stored in external indices.
+
+Each method stores the values associated with various objects in
+an hash keyed by the object's stringified identity. Since that hash
+is accessible only from the generated closures, it is impossible
+for foreign code to manipulate those values except through the
+method interface.
+
+A DESTROY method is installed to remove data for expired objects
+from the various hashes. (If the DESTROY method is not called, your
+program will not release this data and memory will be wasted.)
+
+B<Common Parameters>: The following parameters are defined for
+InsideOut meta-methods.
+
+=over 4
+
+=item data
+
+An auto-vivified reference to a hash to be used to store the values
+for each object.
+
+=back
+
+Note that using InsideOut meta-methods causes the installation of
+a DESTROY method in the calling class, which deallocates data for
+each instance when it is discarded.
+
+NOTE: This needs some more work to properly handle inheritance.
+
+=head2 Standard Methods
+
+The following methods from Generic are all supported:
+
+ scalar
+ string
+ string_index *
+ number
+ boolean
+ bits
+ array
+ hash
+ tiedhash
+ hash_of_arrays
+ object
+ instance
+ array_of_objects
+ code
+ code_or_scalar
+
+See L<Class::MakeMethods::Template::Generic> for the interfaces and behaviors of these method types.
+
+The items marked with a * above are specifically defined in this package, whereas the others are formed automatically by the interaction of this package's generic settings with the code templates provided by the Generic superclass.
+
+=cut
+
+########################################################################
+
+=head2 boolean_index
+
+ boolean_index => [ qw / foo bar baz / ]
+
+Like InsideOut:boolean, boolean_index creates x, set_x, and clear_x
+methods. However, it also defines a class method find_x which returns
+a list of the objects which presently have the x-flag set to
+true.
+
+Note that to free items from memory, you must clear these bits!
+
+=cut
+
+sub boolean_index {
+ {
+ '-import' => {
+ 'Template::Generic:boolean' => '*',
+ },
+ 'interface' => {
+ default => {
+ '*'=>'get_set', 'set_*'=>'set_true', 'clear_*'=>'set_false',
+ 'find_*'=>'find_true',
+ },
+ },
+ 'behavior' => {
+ '-init' => [ sub {
+ my $m_info = $_[0];
+ defined $m_info->{data} or $m_info->{data} = {};
+ return;
+ } ],
+ 'set_true' => q{ _SET_VALUE_{ _SELF_ } },
+ 'set_false' => q{ delete _VALUE_; 0 },
+ 'find_true' => q{
+ values %{ _ATTR_{data} };
+ },
+ },
+ }
+}
+
+sub string_index {
+ {
+ '-import' => {
+ 'Template::Generic:string_index' => '*',
+ },
+ 'interface' => {
+ default => {
+ '*'=>'get_set', 'set_*'=>'set_true', 'clear_*'=>'set_false',
+ 'find_*'=>'find_true',
+ },
+ },
+ 'code_expr' => {
+ _INDEX_HASH_ => '_ATTR_{data}',
+ _GET_FROM_INDEX_ => q{
+ if (defined ( my $old_v = _GET_VALUE_ ) ) {
+ delete _ATTR_{'data'}{ $old_v };
+ }
+ },
+ _REMOVE_FROM_INDEX_ => q{
+ if (defined ( my $old_v = _GET_FROM_INDEX_ ) ) {
+ delete _ATTR_{'data'}{ $old_v };
+ }
+ },
+ _ADD_TO_INDEX_{} => q{
+ if (defined ( my $new_value = _GET_VALUE_ ) ) {
+ if ( my $old_item = _ATTR_{'data'}{$new_value} ) {
+ # There's already an object stored under that value so we
+ # need to unset it's value.
+ # And maybe issue a warning? Or croak?
+ my $m_name = _ATTR_{'name'};
+ $old_item->$m_name( undef );
+ }
+
+ # Put ourself in the index under that value
+ _ATTR_{'data'}{ * } = _SELF_;
+ }
+ },
+ },
+ 'behavior' => {
+ '-init' => [ sub {
+ my $m_info = $_[0];
+ defined $m_info->{data} or $m_info->{data} = {};
+ return;
+ } ],
+ 'get' => q{
+ return _GET_FROM_INDEX_;
+ },
+ 'set' => q{
+ my $new_value = shift;
+ _REMOVE_FROM_INDEX_
+ _ADD_TO_INDEX_{ $new_value }
+ },
+ 'clear' => q{
+ _REMOVE_FROM_INDEX_
+ },
+ },
+ }
+}
+
+########################################################################
+
+1;
diff --git a/lib/Class/MakeMethods/Template/PackageVar.pm b/lib/Class/MakeMethods/Template/PackageVar.pm
new file mode 100644
index 0000000..da0f7be
--- /dev/null
+++ b/lib/Class/MakeMethods/Template/PackageVar.pm
@@ -0,0 +1,168 @@
+package Class::MakeMethods::Template::PackageVar;
+
+use Class::MakeMethods::Template::Generic '-isasubclass';
+
+$VERSION = 1.008;
+use strict;
+require 5.0;
+use Carp;
+
+=head1 NAME
+
+Class::MakeMethods::Template::PackageVar - Static methods with global variables
+
+=head1 SYNOPSIS
+
+ package MyObject;
+ use Class::MakeMethods::Template::PackageVar (
+ scalar => [ 'foo' ]
+ );
+
+ package main;
+
+ MyObject->foo('bar')
+ print MyObject->foo();
+
+ $MyObject::foo = 'bazillion';
+ print MyObject->foo();
+
+=head1 DESCRIPTION
+
+These meta-methods provide access to package (class global) variables.
+These are essentially the same as the Static meta-methods, except
+that they use a global variable in the declaring package to store
+their values.
+
+B<Common Parameters>: The following parameters are defined for PackageVar meta-methods.
+
+=over 4
+
+=item variable
+
+The name of the variable to store the value in. Defaults to the same name as the method.
+
+=back
+
+=cut
+
+sub generic {
+ {
+ '-import' => {
+ 'Template::Generic:generic' => '*'
+ },
+ 'params' => {
+ 'variable' => '*'
+ },
+ 'modifier' => {
+ '-all' => [ q{ no strict; * } ],
+ },
+ 'code_expr' => {
+ '_VALUE_' => '${_ATTR_{target_class}."::"._ATTR_{variable}}',
+ },
+ }
+}
+
+########################################################################
+
+=head2 Standard Methods
+
+The following methods from Generic should all be supported:
+
+ scalar
+ string
+ string_index (?)
+ number
+ boolean
+ bits (?)
+ array (*)
+ hash (*)
+ tiedhash (?)
+ hash_of_arrays (?)
+ object (?)
+ instance (?)
+ array_of_objects (?)
+ code (?)
+ code_or_scalar (?)
+
+See L<Class::MakeMethods::Template::Generic> for the interfaces and behaviors of these method types.
+
+The items marked with a * above are specifically defined in this package, whereas the others are formed automatically by the interaction of this package's generic settings with the code templates provided by the Generic superclass.
+
+The items marked with a ? above have not been tested sufficiently; please inform the author if they do not function as you would expect.
+
+=cut
+
+########################################################################
+
+sub array {
+ {
+ '-import' => {
+ 'Template::Generic:array' => '*',
+ },
+ 'modifier' => {
+ '-all' => q{ no strict; _ENSURE_REF_VALUE_; * },
+ },
+ 'code_expr' => {
+ '_ENSURE_REF_VALUE_' => q{
+ _REF_VALUE_ or @{_ATTR_{target_class}."::"._ATTR_{variable}} = ();
+ },
+ '_VALUE_' => '\@{_ATTR_{target_class}."::"._ATTR_{variable}}',
+ },
+ }
+}
+
+########################################################################
+
+sub hash {
+ {
+ '-import' => {
+ 'Template::Generic:hash' => '*',
+ },
+ 'modifier' => {
+ '-all' => q{ no strict; _ENSURE_REF_VALUE_; * },
+ },
+ 'code_expr' => {
+ '_ENSURE_REF_VALUE_' => q{
+ _REF_VALUE_ or %{_ATTR_{target_class}."::"._ATTR_{variable}} = ();
+ },
+ '_VALUE_' => '\%{_ATTR_{target_class}."::"._ATTR_{variable}}',
+ },
+ }
+}
+
+########################################################################
+
+=head2 PackageVar:vars
+
+This rewrite rule converts package variable names into PackageVar methods of the equivalent data type.
+
+Here's an example declaration:
+
+ package MyClass;
+
+ use Class::MakeMethods::Template::PackageVar (
+ vars => '$DEBUG %Index'
+ );
+
+MyClass now has methods that get and set the contents of its $MyClass::DEBUG and %MyClass::Index package variables:
+
+ MyClass->DEBUG( 1 );
+ MyClass->Index( 'foo' => 'bar' );
+
+=cut
+
+sub vars {
+ my $mm_class = shift;
+ my @rewrite = map [ "Template::PackageVar:$_" ], qw( scalar array hash );
+ my %rewrite = ( '$' => 0, '@' => 1, '%' => 2 );
+ while (@_) {
+ my $name = shift;
+ my $data = shift;
+ $data =~ s/\A(.)//;
+ push @{ $rewrite[ $rewrite{ $1 } ] }, { 'name'=>$name, 'variable'=>$data };
+ }
+ return @rewrite;
+}
+
+
+1;
diff --git a/lib/Class/MakeMethods/Template/Ref.pm b/lib/Class/MakeMethods/Template/Ref.pm
new file mode 100644
index 0000000..d97bafa
--- /dev/null
+++ b/lib/Class/MakeMethods/Template/Ref.pm
@@ -0,0 +1,207 @@
+=head1 NAME
+
+Class::MakeMethods::Template::Ref - Universal copy and compare methods
+
+=head1 SYNOPSIS
+
+ package MyObject;
+ use Class::MakeMethods::Template::Ref (
+ 'Hash:new' => [ 'new' ],
+ clone => [ 'clone' ]
+ );
+
+ package main;
+
+ my $obj = MyObject->new( foo => ["Foozle", "Bozzle"] );
+ my $clone = $obj->clone();
+ print $obj->{'foo'}[1];
+
+=cut
+
+package Class::MakeMethods::Template::Ref;
+
+$VERSION = 1.008;
+use strict;
+require 5.00;
+use Carp;
+
+use Class::MakeMethods::Template '-isasubclass';
+use Class::MakeMethods::Utility::Ref qw( ref_clone ref_compare );
+
+######################################################################
+
+=head1 DESCRIPTION
+
+The following types of methods are provided via the Class::MakeMethods interface:
+
+=head2 clone
+
+Produce a deep copy of an instance of almost any underlying datatype.
+
+Parameters:
+
+init_method
+
+If defined, this method is called on the new object with any arguments passed in.
+
+=cut
+
+sub clone {
+ {
+ 'params' => { 'init_method' => '' },
+ 'interface' => {
+ default => 'clone',
+ clone => { '*'=>'clone', },
+ },
+ 'behavior' => {
+ 'clone' => sub { my $m_info = $_[0]; sub {
+ my $callee = shift;
+ ref $callee or croak "Can only copy instances, not a class.\n";
+
+ my $self = ref_clone( $callee );
+
+ my $init_method = $m_info->{'init_method'};
+ if ( $init_method ) {
+ $self->$init_method( @_ );
+ } elsif ( scalar @_ ) {
+ croak "No init_method";
+ }
+ return $self;
+ }},
+ },
+ }
+}
+
+######################################################################
+
+=head2 prototype
+
+Create new instances by making a deep copy of a static prototypical instance.
+
+Parameters:
+
+init_method
+
+If defined, this method is called on the new object with any arguments passed in.
+=cut
+
+sub prototype {
+ ( {
+ 'interface' => {
+ default => { '*'=>'set_or_new', },
+ },
+ 'behavior' => {
+ 'set_or_new' => sub { my $m_info = $_[0]; sub {
+ my $class = shift;
+
+ if ( scalar @_ == 1 and UNIVERSAL::isa( $_[0], $class ) ) {
+ # set
+ $m_info->{'instance'} = shift
+
+ } else {
+ # get
+ croak "Prototype is not defined" unless $m_info->{'instance'};
+ my $self = ref_clone($m_info->{'instance'});
+
+ my $init_method = $m_info->{'init_method'};
+ if ( $init_method ) {
+ $self->$init_method( @_ );
+ } elsif ( scalar @_ ) {
+ croak "No init_method";
+ }
+ return $self;
+ }
+ }},
+ 'set' => sub { my $m_info = $_[0]; sub {
+ my $class = shift;
+ $m_info->{'instance'} = shift
+ }},
+ 'new' => sub { my $m_info = $_[0]; sub {
+ my $class = shift;
+
+ croak "Prototype is not defined" unless $m_info->{'instance'};
+ my $self = ref_clone($m_info->{'instance'});
+
+ my $init_method = $m_info->{'init_method'};
+ if ( $init_method ) {
+ $self->$init_method( @_ );
+ } elsif ( scalar @_ ) {
+ croak "No init_method";
+ }
+ return $self;
+ }},
+ },
+ } )
+}
+
+######################################################################
+
+=head2 compare
+
+Compare one object to another.
+
+B<Templates>
+
+=over 4
+
+=item *
+
+default
+
+Three-way (sorting-style) comparison.
+
+=item *
+
+equals
+
+Are these two objects equivalent?
+
+=item *
+
+identity
+
+Are these two references to the exact same object?
+
+=back
+
+=cut
+
+sub compare {
+ {
+ 'params' => { 'init_method' => '' },
+ 'interface' => {
+ default => { '*'=>'compare', },
+ equals => { '*'=>'equals', },
+ identity => { '*'=>'identity', },
+ },
+ 'behavior' => {
+ 'compare' => sub { my $m_info = $_[0]; sub {
+ my $callee = shift;
+ ref_compare( $callee, shift );
+ }},
+ 'equals' => sub { my $m_info = $_[0]; sub {
+ my $callee = shift;
+ ref_compare( $callee, shift ) == 0;
+ }},
+ 'identity' => sub { my $m_info = $_[0]; sub {
+ $_[0] eq $_[1]
+ }},
+ },
+ }
+}
+
+######################################################################
+
+=head1 SEE ALSO
+
+See L<Class::MakeMethods> for general information about this distribution.
+
+See L<Class::MakeMethods::Template> for more about this family of subclasses.
+
+See L<Class::MakeMethods::Utility::Ref> for the clone and compare functions used above.
+
+=cut
+
+######################################################################
+
+1;
diff --git a/lib/Class/MakeMethods/Template/Scalar.pm b/lib/Class/MakeMethods/Template/Scalar.pm
new file mode 100644
index 0000000..705f007
--- /dev/null
+++ b/lib/Class/MakeMethods/Template/Scalar.pm
@@ -0,0 +1,80 @@
+package Class::MakeMethods::Template::Scalar;
+
+use Class::MakeMethods::Template::Generic '-isasubclass';
+
+$VERSION = 1.008;
+use strict;
+require 5.00;
+use Carp;
+
+=head1 NAME
+
+Class::MakeMethods::Template::Scalar - Methods for blessed scalars
+
+=head1 SYNOPSIS
+
+ package MyObject;
+ use Class::MakeMethods::Template::ExternalData (
+ new => 'new',
+ scalar => 'foo',
+ );
+
+ package main;
+
+ my $obj = MyObject->new( foo => "Foozle" );
+ print $obj->foo(); # Prints Foozle
+ $obj->foo("Bamboozle"); # Sets $$obj
+ print $obj->foo(); # Prints Bamboozle
+
+=head1 DESCRIPTION
+
+Supports the Generic object constructor and accessors meta-method
+types, but uses scalar refs as the underlying implementation type,
+so only one accessor method can be used effectively.
+
+=cut
+
+sub generic {
+ {
+ '-import' => {
+ 'Template::Generic:generic' => '*'
+ },
+ 'code_expr' => {
+ _VALUE_ => '(${_SELF_})',
+ _EMPTY_NEW_INSTANCE_ => 'bless \( my $scalar = undef ), _SELF_CLASS_',
+ },
+ 'params' => {
+ }
+ }
+}
+
+########################################################################
+
+=head2 Standard Methods
+
+The following methods from Generic are all supported:
+
+ new
+ scalar
+ string
+ string_index
+ number
+ boolean
+ bits
+ array
+ hash
+ tiedhash
+ hash_of_arrays
+ object
+ instance
+ array_of_objects
+ code
+ code_or_scalar
+
+See L<Class::MakeMethods::Template::Generic> for the interfaces and behaviors of these method types.
+
+However, note that due to special nature of this package, all accessor methods reference the same scalar value, so setting a value with one method will overwrite the value retrieved by another.
+
+=cut
+
+1;
diff --git a/lib/Class/MakeMethods/Template/Static.pm b/lib/Class/MakeMethods/Template/Static.pm
new file mode 100644
index 0000000..4dfccca
--- /dev/null
+++ b/lib/Class/MakeMethods/Template/Static.pm
@@ -0,0 +1,41 @@
+package Class::MakeMethods::Template::Static;
+
+use Class::MakeMethods::Template::Global '-isasubclass';
+
+$VERSION = 1.008;
+
+1;
+
+__END__
+
+=head1 NAME
+
+Class::MakeMethods::Template::Static - Deprecated name for Global
+
+=head1 SYNOPSIS
+
+ package MyObject;
+ use Class::MakeMethods::Template::Global (
+ scalar => [ 'foo' ]
+ );
+
+ package main;
+
+ MyObject->foo('bar')
+ print MyObject->foo();
+ ...
+ print $my_instance->foo(); # same thing
+
+=head1 DESCRIPTION
+
+Earlier versions of this package included a package named Class::MakeMethods::Template::Static.
+
+However, in hindsight, this name was poorly chosen, as it suggests a constant, unchanging value, whereas the actual functionality is akin to traditional "global" variables.
+
+This functionality is now provided by Class::MakeMethods::Template::Global, of which this is an empty subclass retained to provide backwards compatibility.
+
+=head1 SEE ALSO
+
+L<Class::MakeMethods::Template::Global>.
+
+=cut \ No newline at end of file
diff --git a/lib/Class/MakeMethods/Template/Struct.pm b/lib/Class/MakeMethods/Template/Struct.pm
new file mode 100644
index 0000000..7d9540b
--- /dev/null
+++ b/lib/Class/MakeMethods/Template/Struct.pm
@@ -0,0 +1,41 @@
+package Class::MakeMethods::Template::Struct;
+
+use Class::MakeMethods::Template::Array '-isasubclass';
+
+$VERSION = 1.008;
+
+1;
+
+__END__
+
+=head1 NAME
+
+Class::MakeMethods::Template::Struct - Deprecated name for Array
+
+=head1 SYNOPSIS
+
+ package MyObject;
+ use Class::MakeMethods::Template::Array (
+ new => [ 'new' ]
+ scalar => [ 'foo', 'bar' ]
+ );
+
+ package main;
+
+ my $obj = MyObject->new( foo => "Foozle", bar => "Bozzle" );
+ print $obj->foo(); # Prints Foozle
+ $obj->bar("Bamboozle"); # Sets $obj->[1]
+
+=head1 DESCRIPTION
+
+Earlier versions of this package included a package named Class::MakeMethods::Template::Struct.
+
+However, in hindsight, this name was poorly chosen, as it suggests some connection to C-style structs, where the behavior implemented more simply parallels the functionality of Template::Hash and the other Generic subclasses.
+
+This functionality is now provided by Class::MakeMethods::Template::Array, of which this is an empty subclass retained to provide backwards compatibility.
+
+=head1 SEE ALSO
+
+L<Class::MakeMethods::Template::Array>.
+
+=cut \ No newline at end of file
diff --git a/lib/Class/MakeMethods/Template/StructBuiltin.pm b/lib/Class/MakeMethods/Template/StructBuiltin.pm
new file mode 100644
index 0000000..b3ddc21
--- /dev/null
+++ b/lib/Class/MakeMethods/Template/StructBuiltin.pm
@@ -0,0 +1,148 @@
+package Class::MakeMethods::Template::StructBuiltin;
+
+use Class::MakeMethods::Template::Generic '-isasubclass';
+
+$VERSION = 1.008;
+use strict;
+require 5.00;
+use Carp;
+
+=head1 NAME
+
+Class::MakeMethods::Template::StructBuiltin
+
+=head1 SYNOPSIS
+
+ use Class::MakeMethods::Template::StructBuiltin (
+ -TargetClass => 'MyStat',
+ builtin_isa => [
+ '-{new_function}'=>'stat',
+ qw/ dev ino mode nlink /
+ ]
+ );
+
+
+=head1 DESCRIPTION
+
+This class generates a wrapper around some builtin function,
+storing the results in the object and providing a by-name interface.
+
+Takes a (core) function name, and a arrayref of return position names
+(we will call it pos_list). Creates:
+
+=over 4
+
+=item new
+
+Calls the core func with any given arguments, stores the result in the
+instance.
+
+=item x
+
+For each member of pos_list, creates a method of the same name which
+gets/sets the nth member of the returned list, where n is the position
+of x in pos_list.
+
+=item fields
+
+Returns pos_list, in the given order.
+
+=item dump
+
+Returns a list item name, item value, in order.
+
+=back
+
+Example Usage:
+
+ package Stat;
+
+ use Class::MakeMethods::Template::StructBuiltin
+ builtin_isa => [ '-{new_function}'=>'stat', qw/ dev ino mode nlink / ],
+
+ package main;
+
+ my $file = "$ENV{HOME}/.template";
+ my $s = Stat->new($file);
+ print "File $file has ", $s->nlink, " links\n";
+
+Note that (a) the new method does not check the return value of the
+function called (in the above example, if $file does not exist, you will
+silently get an empty object), and (b) if you really want the above
+example, see the core File::stat module. But you get the idea, I hope.
+
+=cut
+
+sub builtin_isa {
+ ( {
+ 'template' => {
+ default => {
+ '*'=>'get_set', 'dump'=>'dump', 'fields'=>'fields', 'new'=>'new_builtin'
+ },
+ },
+ 'behavior' => {
+ '-init' => sub {
+ my $m_info = $_[0];
+
+ $m_info->{class} ||= $m_info->{target_class};
+
+ my $class_info =
+ ( $Class::MakeMethods::Struct::builtin{$m_info->{class}} ||= [] );
+ if ( ! defined $m_info->{array_index} ) {
+ foreach ( 0..$#$class_info ) {
+ if ( $class_info->[$_] eq $m_info->{'name'} ) {
+ $m_info->{array_index} = $_; last }
+ }
+ if ( ! defined $m_info->{array_index} ) {
+ push @ $class_info, $m_info->{'name'};
+ $m_info->{array_index} = $#$class_info;
+ }
+ }
+
+ if (defined $m_info->{new_function} and ! ref $m_info->{new_function}) {
+ # NOTE Below comments found in original version of MethodMaker. -Simon
+ # Cuz neither \&{"CORE::$func"} or $CORE::{$func} work ... N.B. this
+ # only works for core functions that take only one arg. But I can't
+ # quite figure out how to pass in the list without it getting
+ # evaluated in a scalar context. Hmmm.
+ $m_info->{new_function} = eval "sub {
+ scalar \@_ ? CORE::$m_info->{new_function}(shift)
+ : CORE::$m_info->{new_function}
+ }";
+ }
+
+ return;
+ },
+
+ 'new_builtin' => sub { my $m_info = $_[0]; sub {
+ my $class = shift;
+ my $function = $m_info->{new_function};
+ my $self = [ &$function(@_) ];
+ bless $self, $class;
+ }},
+
+ 'fields' => sub { my $m_info = $_[0]; sub {
+ my $class_info =
+ ( $Class::MakeMethods::Struct::builtin{$m_info->{class}} ||= [] );
+ @$class_info;
+ }},
+ 'dump' => sub { my $m_info = $_[0]; sub {
+ my $self = shift;
+ my $class_info =
+ ( $Class::MakeMethods::Struct::builtin{$m_info->{class}} ||= [] );
+ my @keys = @$class_info;
+ map ($keys[$_], $self->[$_]), 0 .. $#keys;
+ }},
+
+ 'get_set' => sub { my $m_info = $_[0]; sub {
+ my $self = shift;
+ if ( @_ ) {
+ $self->[ $m_info->{array_index} ] = shift;
+ }
+ $self->[ $m_info->{array_index} ];
+ }},
+ },
+ } )
+}
+
+1;
diff --git a/lib/Class/MakeMethods/Template/Universal.pm b/lib/Class/MakeMethods/Template/Universal.pm
new file mode 100644
index 0000000..9535209
--- /dev/null
+++ b/lib/Class/MakeMethods/Template/Universal.pm
@@ -0,0 +1,415 @@
+package Class::MakeMethods::Template::Universal;
+
+use Class::MakeMethods::Template '-isasubclass';
+
+$VERSION = 1.008;
+use strict;
+require 5.00;
+require Carp;
+
+=head1 NAME
+
+Class::MakeMethods::Template::Universal - Meta-methods for any type of object
+
+=head1 SYNOPSIS
+
+ package MyObject;
+ use Class::MakeMethods::Template::Universal (
+ 'no_op' => [ 'twiddle' ],
+ 'croak' => [ 'fail', { croak_msg => 'Curses!' } ]
+ );
+
+ package main;
+
+ MyObject->twiddle; # Does nothing
+ if ( $foiled ) { MyObject->fail() } # Dies with croak_msg
+
+=head1 DESCRIPTION
+
+=head1 UNIVERSAL META-METHODS
+
+The following meta-methods and behaviors are applicable across
+multiple types of classes and objects.
+
+=head2 Universal:generic
+
+This is not a directly-invokable method type, but instead provides code expressions for use in other method-generators.
+
+You can use any of these features in your meta-method interfaces without explicitly importing them.
+
+B<Modifiers>
+
+=over 4
+
+=item *
+
+--private
+
+Causes the method to croak if it is called from outside of the package which originally declared it.
+
+Note that this protection can currently be circumvented if your class provides the method_init behavior, or another subroutine that calls methods by name.
+
+=item *
+
+--protected
+
+Causes the method to croak if it is called from a package other than the declaring package and its inheritors.
+
+Note that this protection can currently be circumvented if your class provides the method_init behavior, or another subroutine that calls methods by name.
+
+=item *
+
+--public
+
+Cancels any previous -private or -protected declaration.
+
+=item *
+
+--self_closure
+
+Causes the method to return a function reference which is bound to the arguments provided when it is first called.
+
+For examples of usage, see the test scripts in t/*closure.t.
+
+=item *
+
+--lvalue
+
+Adds the ":lvalue" attribute to the subroutine declaration.
+
+For examples of usage, see the test scripts in t/*lvalue.t.
+
+=item *
+
+--warn_calls
+
+For diagnostic purposes, call warn with the object reference, method name, and arguments before executing the body of the method.
+
+
+=back
+
+
+B<Behaviors>
+
+=over 4
+
+=item *
+
+attributes
+
+Runtime access to method parameters.
+
+=item *
+
+no_op -- See below.
+
+=item *
+
+croak -- See below.
+
+=item *
+
+method_init -- See below.
+
+=back
+
+=cut
+
+sub generic {
+ {
+ 'code_expr' => {
+ '_SELF_' => '$self',
+ '_SELF_CLASS_' => '(ref _SELF_ || _SELF_)',
+ '_SELF_INSTANCE_' => '(ref _SELF_ ? _SELF_ : undef)',
+ '_CLASS_FROM_INSTANCE_' => '(ref _SELF_ || croak "Can\'t invoke _STATIC_ATTR_{name} as a class method")',
+ '_ATTR_{}' => '$m_info->{*}',
+ '_STATIC_ATTR_{}' => '_ATTR_{*}',
+ '_ATTR_REQUIRED_{}' =>
+ '(_ATTR_{*} or Carp::croak("No * parameter defined for _ATTR_{name}"))',
+ '_ATTR_DEFAULT_{}' =>
+ sub { my @a = split(' ',$_[0],2); "(_ATTR_{$a[0]} || $a[1])" },
+
+ _ACCESS_PRIVATE_ => '( ( (caller)[0] eq _ATTR_{target_class} ) or croak "Attempted access to private method _ATTR_{name}")',
+ _ACCESS_PROTECTED_ => '( UNIVERSAL::isa((caller)[0], _ATTR_{target_class}) or croak "Attempted access to protected method _ATTR_{name}" )',
+
+ '_CALL_METHODS_FROM_HASH_' => q{
+ # Accept key-value attr list, or reference to unblessed hash of attrs
+ my @args = (scalar @_ == 1 and ref($_[0]) eq 'HASH') ? %{$_[0]} : @_;
+ while ( scalar @args ) { local $_ = shift(@args); $self->$_( shift(@args) ) }
+ },
+
+ },
+ 'modifier' => {
+ 'self_closure' => q{ my @args = @_; return sub { unshift @_, @args; * } },
+ 'warn_calls' => q{ warn $self."->_STATIC_ATTR_{name}(".join(', ',@_).")\n"; * },
+ 'public' => q{ * },
+ 'private' => q{ _ACCESS_PRIVATE_; * },
+ 'protected' => q{ _ACCESS_PROTECTED_; * },
+ '-folding' => [
+ # Public is the default; all three options are mutually exclusive.
+ '-public' => '',
+ '-private -public' => '-public',
+ '-protected -public' => '-public',
+ '-private -protected' => '-protected',
+ '-protected -private' => '-private',
+ ],
+ 'lvalue' => { _SUB_ATTRIBS_ => ': lvalue' },
+ },
+ 'behavior' => {
+ -import => {
+ 'Template::Universal:no_op' => 'no_op',
+ 'Template::Universal:croak' => 'croak',
+ 'Template::Universal:method_init' => 'method_init',
+ },
+ attributes => sub {
+ my $m_info = $_[0];
+ return sub {
+ my $self = shift;
+ if ( scalar @_ == 0 ) {
+ return $m_info;
+ } elsif ( scalar @_ == 1 ) {
+ return $m_info->{ shift() };
+ } else {
+ %$m_info = ( %$m_info, @_ );
+ }
+ }
+ },
+ },
+ }
+}
+
+########################################################################
+
+=head2 no_op
+
+For each meta-method, creates a method with an empty body.
+
+ use Class::MakeMethods::Template::Universal (
+ 'no_op' => [ 'foo bar baz' ],
+ );
+
+You might want to create and use such methods to provide hooks for
+subclass activity.
+
+No interfaces or parameters supported.
+
+=cut
+
+sub no_op {
+ {
+ 'interface' => {
+ default => 'no_op',
+ 'no_op' => 'no_op'
+ },
+ 'behavior' => {
+ no_op => sub { my $m_info = $_[0]; sub { } },
+ },
+ }
+}
+
+########################################################################
+
+=head2 croak
+
+For each meta-method, creates a method which will croak if called.
+
+ use Class::MakeMethods::Template::Universal (
+ 'croak' => [ 'foo bar baz' ],
+ );
+
+This is intended to support the use of abstract methods, that must
+be overidden in a useful subclass.
+
+If each subclass is expected to provide an implementation of a given method, using this abstract method will replace the generic error message below with the clearer, more explicit error message that follows it:
+
+ Can't locate object method "foo" via package "My::Subclass"
+ The "foo" method is abstract and can not be called on My::Subclass
+
+However, note that the existence of this method will be detected by UNIVERSAL::can(), so it is not suitable for use in optional interfaces, for which you may wish to be able to detect whether the method is supported or not.
+
+The -unsupported and -prohibited interfaces provide alternate error
+messages, or a custom error message can be provided using the
+'croak_msg' parameter.
+
+=cut
+
+sub abstract { 'croak --abstract' }
+
+sub croak {
+ {
+ 'interface' => {
+ default => 'croak',
+ 'croak' => 'croak',
+ 'abstract' => {
+ '*'=>'croak', -params=> { 'croak_msg' =>
+ q/Can't locate abstract method "*" declared in "*{target_class}", called from "CALLCLASS"./
+ }
+ },
+ 'abstract_minimal' => {
+ '*'=>'croak', -params=> { 'croak_msg' =>
+ "The * method is abstract and can not be called" }
+ },
+ 'unsupported' => {
+ '*'=>'croak', -params=> { 'croak_msg' =>
+ "The * method does not support this operation" }
+ },
+ 'prohibited' => {
+ '*'=>'croak', -params=> { 'croak_msg' =>
+ "The * method is not allowed to perform this activity" }
+ },
+ },
+ 'behavior' => {
+ croak => sub {
+ my $m_info = $_[0];
+ sub {
+ $m_info->{'croak_msg'} =~ s/CALLCLASS/ ref( $_[0] ) || $_[0] /ge
+ if $m_info->{'croak_msg'};
+ Carp::croak( $m_info->{'croak_msg'} );
+ }
+ },
+ },
+ }
+}
+
+########################################################################
+
+=head2 method_init
+
+Creates a method that accepts a hash of key-value pairs, or a
+reference to hash of such pairs. For each pair, the key is interpreted
+as the name of a method to call, and the value is the argument to
+be passed to that method.
+
+Sample declaration and usage:
+
+ package MyObject;
+ use Class::MakeMethods::Template::Universal (
+ method_init => 'init',
+ );
+ ...
+
+ my $object = MyObject->new()
+ $object->init( foo => 'Foozle', bar => 'Barbados' );
+
+ # Equivalent to:
+ $object->foo('Foozle');
+ $object->bar('Barbados');
+
+You might want to create and use such methods to allow easy initialization of multiple object or class parameters in a single call.
+
+B<Note>: including methods of this type will circumvent the protection of C<private> and C<protected> methods, because it an outside caller can cause an object to call specific methods on itself, bypassing the privacy protection.
+
+=cut
+
+sub method_init {
+ {
+ 'interface' => {
+ default => 'method_init',
+ 'method_init' => 'method_init'
+ },
+ 'code_expr' => {
+ '-import' => { 'Template::Universal:generic' => '*' },
+ },
+ 'behavior' => {
+ method_init => q{
+ _CALL_METHODS_FROM_HASH_
+ return $self;
+ }
+ },
+ }
+}
+
+########################################################################
+
+=head2 forward_methods
+
+Creates a method which delegates to an object provided by another method.
+
+Example:
+
+ use Class::MakeMethods::Template::Universal
+ forward_methods => [
+ --target=> 'whistle', w,
+ [ 'x', 'y' ], { target=> 'xylophone' },
+ { name=>'z', target=>'zither', target_args=>[123], method_name=>do_zed },
+ ];
+
+Example: The above defines that method C<w> will be handled by the
+calling C<w> on the object returned by C<whistle>, whilst methods C<x>
+and C<y> will be handled by C<xylophone>, and method C<z> will be handled
+by calling C<do_zed> on the object returned by calling C<zither(123)>.
+
+B<Interfaces>:
+
+=over 4
+
+=item forward (default)
+
+Calls the method on the target object. If the target object is missing, croaks at runtime with a message saying "Can't forward bar because bar is empty."
+
+=item delegate
+
+Calls the method on the target object, if present. If the target object is missing, returns nothing.
+
+=back
+
+B<Parameters>: The following additional parameters are supported:
+
+=over 4
+
+=item target
+
+I<Required>. The name of the method that will provide the object that will handle the operation.
+
+=item target_args
+
+Optional ref to an array of arguments to be passed to the target method.
+
+=item method_name
+
+The name of the method to call on the handling object. Defaults to the name of the meta-method being created.
+
+=back
+
+=cut
+
+sub forward_methods {
+ {
+ 'interface' => {
+ default => 'forward',
+ 'forward' => 'forward'
+ },
+ 'params' => { 'method_name' => '*' },
+ 'behavior' => {
+ 'forward' => sub { my $m_info = $_[0]; sub {
+ my $target = $m_info->{'target'};
+ my @args = $m_info->{'target_args'} ? @{$m_info->{'target_args'}} : ();
+ my $obj = (shift)->$target(@args)
+ or Carp::croak("Can't forward $m_info->{name} because $m_info->{target} is empty");
+ my $method = $m_info->{'method_name'};
+ $obj->$method(@_);
+ }},
+ 'delegate' => sub { my $m_info = $_[0]; sub {
+ my $target = $m_info->{'target'};
+ my @args = $m_info->{'target_args'} ? @{$m_info->{'target_args'}} : ();
+ my $obj = (shift)->$target(@args)
+ or return;
+ my $method = $m_info->{'method_name'};
+ $obj->$method(@_);
+ }},
+ },
+ }
+}
+
+
+########################################################################
+
+=head1 SEE ALSO
+
+See L<Class::MakeMethods> for general information about this distribution.
+
+See L<Class::MakeMethods::Template> for information about this family of subclasses.
+
+=cut
+
+1;
diff --git a/lib/Class/MakeMethods/Utility/ArraySplicer.pm b/lib/Class/MakeMethods/Utility/ArraySplicer.pm
new file mode 100644
index 0000000..e07a796
--- /dev/null
+++ b/lib/Class/MakeMethods/Utility/ArraySplicer.pm
@@ -0,0 +1,243 @@
+=head1 NAME
+
+Class::MakeMethods::Utility::ArraySplicer - Common array ops
+
+=head1 SYNOPSIS
+
+ use Class::MakeMethods::Utility::ArraySplicer;
+
+ # Get one or more values
+ $value = array_splicer( $array_ref, $index );
+ @values = array_splicer( $array_ref, $index_array_ref );
+
+ # Set one or more values
+ array_splicer( $array_ref, $index => $new_value, ... );
+
+ # Splice selected values in or out
+ array_splicer( $array_ref, [ $start_index, $end_index], [ @values ]);
+
+=head1 DESCRIPTION
+
+This module provides a utility function and several associated constants which support a general purpose array-splicer interface, used by several of the Standard and Composite method generators.
+
+=cut
+
+########################################################################
+
+package Class::MakeMethods::Utility::ArraySplicer;
+
+$VERSION = 1.000;
+
+@EXPORT_OK = qw(
+ array_splicer
+ array_set array_clear array_push array_pop array_unshift array_shift
+);
+sub import { require Exporter and goto &Exporter::import } # lazy Exporter
+
+use strict;
+
+########################################################################
+
+=head2 array_splicer
+
+This is a general-purpose array accessor function. Depending on the arguments passed to it, it will get, set, slice, splice, or otherwise modify your array.
+
+=over 4
+
+=item *
+
+If called without any arguments, returns the contents of the array in list context, or an array reference in scalar context (or undef).
+
+ # Get all values
+ $value_ref = array_splicer( $array_ref );
+ @values = array_splicer( $array_ref );
+
+=item *
+
+If called with a single numeric argument, uses that argument as an index to retrieve from the referenced array, and returns that value (or undef).
+
+ # Get one value
+ $value = array_splicer( $array_ref, $index );
+
+=item *
+
+If called with a single array ref argument, sets the contents of the array to match the contents of the provided one.
+
+ # Set contents of array
+ array_splicer( $array_ref, [ $value1, $value2, ... ] );
+
+ # Reset the array contents to empty
+ array_splicer( $array_ref, [] );
+
+=item *
+
+If called with a two arguments, the first undefined and the second an array ref argument, uses that array's contents as a list of indexes to return a slice of the referenced array.
+
+ # Get slice of values
+ @values = array_splicer( $array_ref, undef, [ $index1, $index2, ... ] );
+
+=item *
+
+If called with a list of argument pairs, each with a numeric index and an associated value, stores the value at the given index in the referenced array. The current value in each position will be overwritten, and later arguments with the same index will override earlier ones. Returns the current array-ref value.
+
+ # Set one or more values by index
+ array_splicer( $array_ref, $index1 => $value1, $index2 => $value2, ... );
+
+=item *
+
+If called with a list of argument pairs, each with the first item being a reference to an array of up to two numbers, loops over each pair and uses those numbers to splice the value array.
+
+ # Splice selected values in or out
+ array_splicer( $array_ref, [ $start_index, $count], [ @values ]);
+
+The first controlling number is the position at which the splice will begin. Zero will start before the first item in the list. Negative numbers count backwards from the end of the array.
+
+The second number is the number of items to be removed from the list. If it is omitted, or undefined, or zero, no items are removed. If it is a positive integer, that many items will be returned.
+
+If both numbers are omitted, or are both undefined, they default to containing the entire value array.
+
+If the second argument is undef, no values will be inserted; if it is a non-reference value, that one value will be inserted; if it is an array-ref, its values will be copied.
+
+The method returns the items that removed from the array, if any.
+
+Here are some examples of common splicing operations.
+
+ # Insert an item at position in the array
+ $obj->bar([3], 'Potatoes' );
+
+ # Remove 1 item from position 3 in the array
+ $obj->bar([3, 1], undef );
+
+ # Set a new value at position 2, and return the old value
+ print $obj->bar([2, 1], 'Froth' );
+
+ # Unshift an item onto the front of the list
+ array_splicer( $array_ref, [0], 'Bubbles' );
+
+ # Shift the first item off of the front of the list
+ print array_splicer( $array_ref, [0, 1], undef );
+
+ # Push an item onto the end of the list
+ array_splicer( $array_ref, [undef], 'Bubbles' );
+
+ # Pop the last item off of the end of the list
+ print array_splicer( $array_ref, [undef, 1], undef );
+
+=back
+
+=cut
+
+sub array_splicer {
+ my $value_ref = shift;
+
+ # RETRIEVE VALUES
+ if ( scalar(@_) == 0 ) {
+ return wantarray ? @$value_ref : $value_ref;
+
+ # FETCH BY INDEX
+ } elsif ( scalar(@_) == 1 and length($_[0]) and ! ref($_[0]) and $_[0] !~ /\D/) {
+ $value_ref->[ $_[0] ]
+
+ # SET CONTENTS
+ } elsif ( scalar(@_) == 1 and ref $_[0] eq 'ARRAY' ) {
+ @$value_ref = @{ $_[0] };
+ return wantarray ? @$value_ref : $value_ref;
+
+ # ASSIGN BY INDEX
+ } elsif ( ! ( scalar(@_) % 2 ) and ! grep { ! ( length($_) and ! ref($_) and $_ !~ /\D/ ) } map { $_[$_] } grep { ! ( $_ % 2 ) } ( 0 .. $#_ ) ) {
+ while ( scalar(@_) ) {
+ my $key = shift();
+ $value_ref->[ $key ] = shift();
+ }
+ $value_ref;
+
+ # SLICE
+ } elsif ( ! scalar(@_) == 2 and ! defined $_[0] and ref $_[1] eq 'ARRAY' ) {
+ @{$value_ref}[ @{ $_[1] } ]
+
+ # SPLICE
+ } elsif ( ! scalar(@_) % 2 and ref $_[0] eq 'ARRAY' ) {
+ my @results;
+ while ( scalar(@_) ) {
+ my $key = shift();
+ my $value = shift();
+ my @values = ! ( $value ) ? () : ! ref ( $value ) ? $value : @$value;
+ my $key_v = $key->[0];
+ my $key_c = $key->[1];
+ if ( defined $key_v ) {
+ if ( $key_c ) {
+ # straightforward two-value splice
+ } else {
+ # insert at position
+ $key_c = 0;
+ }
+ } else {
+ if ( ! defined $key_c ) {
+ # target the entire list
+ $key_v = 0;
+ $key_c = scalar @$value_ref;
+ } elsif ( $key_c ) {
+ # take count items off the end
+ $key_v = - $key_c
+ } else {
+ # insert at the end
+ $key_v = scalar @$value_ref;
+ $key_c = 0;
+ }
+ }
+ push @results, splice @$value_ref, $key_v, $key_c, @values
+ }
+ ( ! wantarray and scalar @results == 1 ) ? $results[0] : @results;
+
+ } else {
+ Carp::confess 'Unexpected arguments to array accessor: ' . join(', ', map "'$_'", @_ );
+ }
+}
+
+########################################################################
+
+=head2 Constants
+
+There are also constants symbols to facilitate some common combinations of splicing arguments:
+
+ # Reset the array contents to empty
+ array_splicer( $array_ref, array_clear );
+
+ # Set the array contents to provided values
+ array_splicer( $array_ref, array_splice, [ 2, 3 ] );
+
+ # Unshift an item onto the front of the list
+ array_splicer( $array_ref, array_unshift, 'Bubbles' );
+
+ # Shift it back off again
+ print array_splicer( $array_ref, array_shift );
+
+ # Push an item onto the end of the list
+ array_splicer( $array_ref, array_push, 'Bubbles' );
+
+ # Pop it back off again
+ print array_splicer( $array_ref, array_pop );
+
+=cut
+
+use constant array_splice => undef;
+use constant array_clear => ( [] );
+
+use constant array_push => [undef];
+use constant array_pop => ( [undef, 1], undef );
+
+use constant array_unshift => [0];
+use constant array_shift => ( [0, 1], undef );
+
+########################################################################
+
+=head1 SEE ALSO
+
+See L<Class::MakeMethods> for general information about this distribution.
+
+See L<Class::MakeMethods::Standard::Hash> and numerous other classes for
+examples of usage.
+
+=cut
+
+1;
diff --git a/lib/Class/MakeMethods/Utility/DiskCache.pm b/lib/Class/MakeMethods/Utility/DiskCache.pm
new file mode 100644
index 0000000..653303c
--- /dev/null
+++ b/lib/Class/MakeMethods/Utility/DiskCache.pm
@@ -0,0 +1,165 @@
+package Class::MakeMethods::Utility::DiskCache;
+
+$VERSION = 1.008;
+
+@EXPORT_OK = qw( disk_cache );
+sub import { require Exporter and goto &Exporter::import } # lazy Exporter
+
+use strict;
+use Carp;
+use File::Spec;
+use File::Path;
+
+########################################################################
+
+use vars qw( $DiskCacheDir );
+
+my $IndexFile = "methods.ix"; # file also serves as timestamp
+my $FileEnding = ".mm";
+
+sub import {
+ my $package = shift;
+ if ( scalar @_ ) {
+ $DiskCacheDir = shift;
+ }
+}
+
+########################################################################
+
+my %HaveCheckedFreshness;
+
+# $result = disk_cache( $package, $file, $sub, @args );
+sub disk_cache {
+ my ( $full_funct, $args_string, $function, @args ) = @_;
+
+ unless ( $DiskCacheDir and -e $DiskCacheDir ) {
+ return &$function( @args );
+ }
+
+ my ($package, $func_name) = ( $full_funct =~ /^(.+)::(\w+)$/ );
+
+ my $pack_dir = File::Spec->catdir( $DiskCacheDir, split /::/, $package );
+ if ( ! -e $pack_dir and -w $DiskCacheDir ) {
+ mkpath($pack_dir, 0, 07777);
+ }
+
+ unless ( defined $HaveCheckedFreshness{$package} ) {
+
+ my $idx = File::Spec->catfile( $pack_dir, $IndexFile );
+
+ my $signature = dependency_signature($package);
+
+ if ( -e $idx and read_file( $idx ) eq $signature ) {
+ $HaveCheckedFreshness{$package} = 1;
+ } else {
+ if ( ! -w $pack_dir ) {
+ # The index is out of date, but not writable -- abandon it
+ $HaveCheckedFreshness{ $package } = 0;
+ } else {
+ rmtree($pack_dir, 0, 1);
+ mkpath($pack_dir, 0, 07777);
+
+ write_file( $idx, $signature );
+ $HaveCheckedFreshness{$package} = 1;
+ }
+ }
+ }
+
+ unless ( $HaveCheckedFreshness{$package} ) {
+ return &$function( @args );
+ }
+
+ my $func_dir = File::Spec->catdir( $pack_dir, $func_name );
+
+ if ( ! -e $func_dir and -w $pack_dir ) {
+ mkpath($func_dir, 0, 07777);
+ }
+ my $file = File::Spec->catfile( $func_dir, $args_string . $FileEnding );
+
+ if ( -e $file ) {
+ return read_file( $file );
+ }
+
+ my $value = ( &$function( @args ) );
+
+ if ( -e $func_dir and -w $func_dir ) {
+ write_file( $file, $value );
+ } else {
+ warn "Can't cache: $file\n";
+ }
+
+ return $value;
+}
+
+########################################################################
+
+sub dependency_signature {
+ my @sources = shift;
+ my @results;
+ no strict 'refs';
+ while ( my $class = shift @sources ) {
+ push @sources, @{"$class\::ISA"};
+ push @results, $class unless ( grep { $_ eq $class } @results );
+ }
+
+ foreach ( @results ) {
+ s!::!/!g;
+ $_ .= '.pm';
+ }
+ return join "\n", map { $_ . ' '. (stat($::INC{ $_ }))[9] } @results;
+}
+
+########################################################################
+
+sub read_file {
+ my $file = shift;
+ # warn "Reading file: $file\n";
+ local *FILE;
+ open FILE, "$file" or die "Can't open $file: $!";
+ local $/ = undef;
+ return <FILE>;
+}
+
+sub write_file {
+ my $file = shift;
+ # warn "Writing file: $file \n";
+ local *FILE;
+ open FILE, ">$file" or die "Can't write to $file: $!";
+ print FILE shift();
+}
+
+sub read_dir {
+ my $dir = shift;
+ local *DIR;
+ opendir(DIR, $dir);
+ readdir(DIR);
+}
+
+########################################################################
+
+1;
+
+__END__
+
+=head1 NAME
+
+Class::MakeMethods::Utility::DiskCache - Optional Template feature
+
+=head1 SYNOPSIS
+
+ use Class::MakeMethods::Utility::DiskCache qw( /my/code/dir );
+
+=head1 DESCRIPTION
+
+To enable disk caching of Class::MakeMethods::Template generated
+code, create an empty directory and pass it to the DiskCache package:
+
+ use Class::MakeMethods::Utility::DiskCache qw( /my/code/dir );
+
+This has a mixed effect on performance, but has the notable advantage of letting you view the subroutines that are being generated by your templates.
+
+=head1 SEE ALSO
+
+See L<Class::MakeMethods::Template> for more information.
+
+=cut \ No newline at end of file
diff --git a/lib/Class/MakeMethods/Utility/Inheritable.pm b/lib/Class/MakeMethods/Utility/Inheritable.pm
new file mode 100644
index 0000000..e1ec9ae
--- /dev/null
+++ b/lib/Class/MakeMethods/Utility/Inheritable.pm
@@ -0,0 +1,126 @@
+=head1 NAME
+
+Class::MakeMethods::Utility::Inheritable - "Inheritable" data
+
+
+=head1 SYNOPSIS
+
+ package MyClass;
+ sub new { ... }
+
+ package MySubclass;
+ @ISA = 'MyClass';
+ ...
+ my $obj = MyClass->new(...);
+ my $subobj = MySubclass->new(...);
+
+ use Class::MakeMethods::Utility::Inheritable qw(get_vvalue set_vvalue );
+
+ my $dataset = {};
+ set_vvalue($dataset, 'MyClass', 'Foobar'); # Set value for class
+ get_vvalue($dataset, 'MyClass'); # Gets value "Foobar"
+
+ get_vvalue($dataset, $obj); # Objects "inherit"
+ set_vvalue($dataset, $obj, 'Foible'); # Until you override
+ get_vvalue($dataset, $obj); # Now finds "Foible"
+
+ get_vvalue($dataset, 'MySubclass'); # Subclass "inherits"
+ get_vvalue($dataset, $subobj); # As do its objects
+ set_vvalue($dataset, 'MySubclass', 'Foozle'); # Until we override it
+ get_vvalue($dataset, 'MySubclass'); # Now finds "Foozle"
+
+ get_vvalue($dataset, $subobj); # Change cascades down
+ set_vvalue($dataset, $subobj, 'Foolish'); # Until we override again
+
+ get_vvalue($dataset, 'MyClass'); # Superclass is unchanged
+
+=head1 DESCRIPTION
+
+This module provides several functions which allow you to store values in a hash corresponding to both objects and classes, and to retrieve those values by searching a object's inheritance tree until it finds a matching entry.
+
+This functionality is used by Class::MakeMethods::Standard::Inheritable and Class::MakeMethods::Composite::Inheritable to construct methods that can both store class data and be overriden on a per-object level.
+
+=cut
+
+########################################################################
+
+package Class::MakeMethods::Utility::Inheritable;
+
+$VERSION = 1.000;
+
+@EXPORT_OK = qw( get_vvalue set_vvalue find_vself );
+sub import { require Exporter and goto &Exporter::import } # lazy Exporter
+
+use strict;
+
+########################################################################
+
+=head1 REFERENCE
+
+=head2 find_vself
+
+ $vself = find_vself( $dataset, $instance );
+
+Searches $instance's inheritance tree until it finds a matching entry in the dataset, and returns either the instance, the class that matched, or undef.
+
+=cut
+
+sub find_vself {
+ my $dataset = shift;
+ my $instance = shift;
+
+ return $instance if ( exists $dataset->{$instance} );
+
+ my $v_self;
+ my @isa_search = ( ref($instance) || $instance );
+ while ( scalar @isa_search ) {
+ $v_self = shift @isa_search;
+ return $v_self if ( exists $dataset->{$v_self} );
+ no strict 'refs';
+ unshift @isa_search, @{"$v_self\::ISA"};
+ }
+ return;
+}
+
+=head2 get_vvalue
+
+ $value = get_vvalue( $dataset, $instance );
+
+Searches $instance's inheritance tree until it finds a matching entry in the dataset, and returns that value
+
+=cut
+
+sub get_vvalue {
+ my $dataset = shift;
+ my $instance = shift;
+ my $v_self = find_vself($dataset, $instance);
+ # warn "Dataset: " . join( ', ', %$dataset );
+ # warn "Retrieving $dataset -> $instance ($v_self): '$dataset->{$v_self}'";
+ return $v_self ? $dataset->{$v_self} : ();
+}
+
+=head2 set_vvalue
+
+ $value = set_vvalue( $dataset, $instance, $value );
+
+Searches $instance's inheritance tree until it finds a matching entry in the dataset, and returns that value
+
+=cut
+
+sub set_vvalue {
+ my $dataset = shift;
+ my $instance = shift;
+ my $value = shift;
+ if ( defined $value ) {
+ # warn "Setting $dataset -> $instance = $value";
+ $dataset->{$instance} = $value;
+ } else {
+ # warn "Clearing $dataset -> $instance";
+ delete $dataset->{$instance};
+ undef;
+ }
+}
+
+########################################################################
+
+1;
diff --git a/lib/Class/MakeMethods/Utility/Ref.pm b/lib/Class/MakeMethods/Utility/Ref.pm
new file mode 100644
index 0000000..9c356f4
--- /dev/null
+++ b/lib/Class/MakeMethods/Utility/Ref.pm
@@ -0,0 +1,171 @@
+=head1 NAME
+
+Class::MakeMethods::Utility::Ref - Deep copying and comparison
+
+=head1 SYNOPSIS
+
+ use Class::MakeMethods::Utility::Ref qw( ref_clone ref_compare );
+
+ $deep_copy = ref_clone( $original );
+ $positive_zero_or_negative = ref_compare( $item_a, $item_b );
+
+=head1 DESCRIPTION
+
+This module provides utility functions to copy and compare arbitrary references, including full traversal of nested data structures.
+
+=cut
+
+########################################################################
+
+package Class::MakeMethods::Utility::Ref;
+
+$VERSION = 1.000;
+
+@EXPORT_OK = qw( ref_clone ref_compare );
+sub import { require Exporter and goto &Exporter::import } # lazy Exporter
+
+use strict;
+
+######################################################################
+
+=head2 REFERENCE
+
+The following functions are provided:
+
+=head2 ref_clone()
+
+Make a recursive copy of a reference.
+
+=cut
+
+use vars qw( %CopiedItems );
+
+# $deep_copy = ref_clone( $value_or_ref );
+sub ref_clone {
+ local %CopiedItems = ();
+ _clone( @_ );
+}
+
+# $copy = _clone( $value_or_ref );
+sub _clone {
+ my $source = shift;
+
+ my $ref_type = ref $source;
+ return $source if (! $ref_type);
+
+ return $CopiedItems{ $source } if ( exists $CopiedItems{ $source } );
+
+ my $class_name;
+ if ( "$source" =~ /^\Q$ref_type\E\=([A-Z]+)\(0x[0-9a-f]+\)$/ ) {
+ $class_name = $ref_type;
+ $ref_type = $1;
+ }
+
+ my $copy;
+ if ($ref_type eq 'SCALAR') {
+ $copy = \( $$source );
+ } elsif ($ref_type eq 'REF') {
+ $copy = \( _clone ($$source) );
+ } elsif ($ref_type eq 'HASH') {
+ $copy = { map { _clone ($_) } %$source };
+ } elsif ($ref_type eq 'ARRAY') {
+ $copy = [ map { _clone ($_) } @$source ];
+ } else {
+ $copy = $source;
+ }
+
+ bless $copy, $class_name if $class_name;
+
+ $CopiedItems{ $source } = $copy;
+
+ return $copy;
+}
+
+######################################################################
+
+=head2 ref_compare()
+
+Attempt to recursively compare two references.
+
+If they are not the same, try to be consistent about returning a
+positive or negative number so that it can be used for sorting.
+The sort order is kinda arbitrary.
+
+=cut
+
+use vars qw( %ComparedItems );
+
+# $positive_zero_or_negative = ref_compare( $A, $B );
+sub ref_compare {
+ local %ComparedItems = ();
+ _compare( @_ );
+}
+
+# $positive_zero_or_negative = _compare( $A, $B );
+sub _compare {
+ my($A, $B, $ignore_class) = @_;
+
+ # If they're both simple scalars, use string comparison
+ return $A cmp $B unless ( ref($A) or ref($B) );
+
+ # If either one's not a reference, put that one first
+ return 1 unless ( ref($A) );
+ return - 1 unless ( ref($B) );
+
+ # Check to see if we've got two references to the same structure
+ return 0 if ("$A" eq "$B");
+
+ # If we've already seen these items repeatedly, we may be running in circles
+ return undef if ($ComparedItems{ $A } ++ > 2 and $ComparedItems{ $B } ++ > 2);
+
+ # Check the ref values, which may be data types or class names
+ my $ref_A = ref($A);
+ my $ref_B = ref($B);
+ return $ref_A cmp $ref_B if ( ! $ignore_class and $ref_A ne $ref_B );
+
+ # Extract underlying data types
+ my $type_A = ("$A" =~ /^\Q$ref_A\E\=([A-Z]+)\(0x[0-9a-f]+\)$/) ? $1 : $ref_A;
+ my $type_B = ("$B" =~ /^\Q$ref_B\E\=([A-Z]+)\(0x[0-9a-f]+\)$/) ? $1 : $ref_B;
+ return $type_A cmp $type_B if ( $type_A ne $type_B );
+
+ if ($type_A eq 'HASH') {
+ my @kA = sort keys %$A;
+ my @kB = sort keys %$B;
+ return ( $#kA <=> $#kB ) if ( $#kA != $#kB );
+ foreach ( 0 .. $#kA ) {
+ return ( _compare($kA[$_], $kB[$_]) or
+ _compare($A->{$kA[$_]}, $B->{$kB[$_]}) or next );
+ }
+ return 0;
+ } elsif ($type_A eq 'ARRAY') {
+ return ( $#$A <=> $#$B ) if ( $#$A != $#$B );
+ foreach ( 0 .. $#$A ) {
+ return ( _compare($A->[$_], $B->[$_]) or next );
+ }
+ return 0;
+ } elsif ($type_A eq 'SCALAR' or $type_A eq 'REF') {
+ return _compare($$A, $$B);
+ } else {
+ return ("$A" cmp "$B")
+ }
+}
+
+########################################################################
+
+=head1 SEE ALSO
+
+See L<Class::MakeMethods> for general information about this distribution.
+
+See L<Ref> for the original version of the clone and compare functions used above.
+
+See L<Clone> (v0.09 on CPAN as of 2000-09-21) for a clone method with an XS implementation.
+
+The Perl6 RFP #67 proposes including clone functionality in the core.
+
+See L<Data::Compare> (v0.01 on CPAN as of 1999-04-24) for a Compare method which checks two references for similarity, but it does not provide positive/negative values for ordering purposes.
+
+=cut
+
+######################################################################
+
+1;
diff --git a/lib/Class/MakeMethods/Utility/TextBuilder.pm b/lib/Class/MakeMethods/Utility/TextBuilder.pm
new file mode 100644
index 0000000..3bc2767
--- /dev/null
+++ b/lib/Class/MakeMethods/Utility/TextBuilder.pm
@@ -0,0 +1,207 @@
+package Class::MakeMethods::Utility::TextBuilder;
+
+$VERSION = 1.008;
+
+@EXPORT_OK = qw( text_builder );
+sub import { require Exporter and goto &Exporter::import } # lazy Exporter
+
+use strict;
+use Carp;
+
+# $expanded_text = text_builder( $base_text, @exprs )
+sub text_builder {
+ my ( $text, @mod_exprs ) = @_;
+
+ my @code_exprs;
+ while ( scalar @mod_exprs ) {
+ my $mod_expr = shift @mod_exprs;
+ if ( ref $mod_expr eq 'HASH' ) {
+ push @code_exprs, %$mod_expr;
+ } elsif ( ref $mod_expr eq 'ARRAY' ) {
+ unshift @mod_exprs, @$mod_expr;
+ } elsif ( ref $mod_expr eq 'CODE' ) {
+ $text = &$mod_expr( $text );
+ } elsif ( ! ref $_ ) {
+ $mod_expr =~ s{\*}{$text}g;
+ $text = $mod_expr;
+ } else {
+ Carp::confess "Wierd contents of modifier array.";
+ }
+ }
+ my %rules = @code_exprs;
+
+ my @exprs;
+ my @blocks;
+ foreach ( sort { length($b) <=> length($a) } keys %rules ) {
+ if ( s/\{\}\Z// ) {
+ push @blocks, $_;
+ } else {
+ push @exprs, $_;
+ }
+ }
+ push @blocks, 'UNUSED_CONSTANT' if ( ! scalar @blocks );
+ push @exprs, 'UNUSED_CONSTANT' if ( ! scalar @exprs );
+
+ # There has *got* to be a better way to regex matched brackets... Right?
+ # Erm, well, no. It looks like Text::Balanced would do the trick, with the
+ # requirement that the below bit get re-written to not be regex-based.
+ my $expr_expr = '\b(' . join('|', map "\Q$_\E", @exprs ) . ')\b';
+ my $block_expr = '\b(' . join('|', map "\Q$_\E", @blocks ) . ') \{
+ ( [^\{\}]*
+ (?: \{
+ [^\{\}]*
+ (?: \{ [^\{\}]* \} [^\{\}]* )*?
+ \} [^\{\}]* )*?
+ )
+ \}';
+
+ 1 while (
+ length $text and $text =~ s/ $expr_expr /
+ my $substitute = $rules{ $1 };
+ if ( ! ref $substitute ) {
+ $substitute;
+ } elsif ( ref $substitute eq 'CODE' ) {
+ &{ $substitute }();
+ } else {
+ croak "Unknown type of substitution rule: '$substitute'";
+ }
+ /gesx or $text =~ s/ $block_expr /
+ my $substitute = $rules{ $1 . '{}' };
+ my $contents = $2;
+ if ( ! ref $substitute ) {
+ $substitute =~ s{\*}{$contents}g;
+ $substitute;
+ } elsif ( ref $substitute eq 'HASH' ) {
+ $substitute->{$contents};
+ } elsif ( ref $substitute eq 'CODE' ) {
+ &{ $substitute }( $contents );
+ } else {
+ croak "Unknown type of substitution rule: '$substitute'";
+ }
+ /gesx
+ );
+
+ return $text;
+}
+
+1;
+
+__END__
+
+=head1 NAME
+
+Class::MakeMethods::Utility::TextBuilder - Basic text substitutions
+
+=head1 SYNOPSIS
+
+ print text_builder( $base_text, @exprs )
+
+=head1 DESCRIPTION
+
+This module provides a single function, which implements a simple "text macro" mechanism for assembling templated text strings.
+
+ $expanded_text = text_builder( $base_text, @exprs )
+
+Returns a modified copy of $base_text using rules from the @exprs list.
+
+The @exprs list may contain any of the following:
+
+=over 4
+
+=item *
+
+A string, in which any '*' characters will be replaced by the base text. The interpolated string then replaces the base text.
+
+=item *
+
+A code-ref, which will be called with the base text as its only argument. The result of that call then replaces the base text.
+
+=item *
+
+A hash-ref, which will be added to the substitution hash used in the second pass, below.
+
+=item *
+
+An array-ref, containing additional expressions to be treated as above.
+
+=back
+
+After any initial string and code-ref rules have been applied, the hash of substitution rules are applied.
+
+The text will be searched for occurances of the keys of the substitution hash, which will be modified based on the corresponding value in the hash. If the substitution key ends with '{}', the search will also match a balanced block of braces, and that value will also be used in the substitution.
+
+The hash-ref may contain the following types of rules:
+
+=over 4
+
+=item *
+
+'string' => 'string'
+
+Occurances of the first string are to be replaced by the second.
+
+=item *
+
+'string' => I<code_ref>
+
+Occurances of the string are to be replaced by the results of calling the subroutine with no arguments.
+
+=item *
+
+'string{}' => 'string'
+
+Occurances of the first string and subsequent block of braces are replaced by a copy of the second string in which any '*' characters have first been replaced by the contents of the brace block.
+
+=item *
+
+'string{}' => I<code_ref>
+
+Occurances of the string and subsequent block of braces are replaced by the results of calling the subroutine with the contents of the brace block as its only argument.
+
+=item *
+
+'string{}' => I<hash_ref>
+
+Occurances of the string and subsequent block of braces are replaced by using the contents of the brace block as a key into the provided hash-ref.
+
+=back
+
+=head1 EXAMPLE
+
+The following text and modification rules provides a skeleton for a collection letter:
+
+ my $letter = "You owe us AMOUNT. Please pay up!\n\n" .
+ "THREAT{SEVERITY}";
+
+ my @exprs = (
+ "Dear NAMEm\n\n*",
+ "*\n\n-- The Management",
+
+ { 'THREAT{}' => { 'good'=>'Please?', 'bad'=>'Or else!' } },
+
+ "\t\t\t\tDATE\n*",
+ { 'DATE' => 'Tuesday, April 1, 2001' },
+ );
+
+One might invoke this template by providing additional data for a given instance and calling the text_builder function:
+
+ my $item = { 'NAME'=>'John', 'AMOUNT'=>'200 camels', 'SEVERITY'=>'bad' };
+
+ print text_builder( $letter, @exprs, $item );
+
+The resulting output is shown below:
+
+ Tuesday, April 1, 2001
+ Dear John,
+
+ You owe us 200 camels. Please pay up!
+
+ Or else!
+
+ -- The Management
+
+=head1 SEE ALSO
+
+See L<Class::MakeMethods> for general information about this distribution.
+
+=cut