-# This module is part of DA, Don Armstrong's Modules, and is released
-# under the terms of the GPL version 2, or any later version. See the
-# file README and COPYING for more information. Copyright 2003 by Don
-# Armstrong <don@donarmstrong.com>.
+# This file is part of Class::Modular and is released under the terms
+# of the GPL version 2, or any later version at your option. See the
+# file README and COPYING for more information.
+# Copyright 2003, 2004 by Don Armstrong <don@donarmstrong.com>.
# $Id$
package Class::Modular;
use base qw(Class::Modular);
-
=head1 DESCRIPTION
Class::Modular is a superclass for generating modular classes, where
without modifying the base classes. This allows for code to be more
modular, and reduces code duplication.
+It fills the middle ground between traditional class based OOP and
+classless OOP. L<Class::Mutator> and L<Sex> are similar to
+Class::Modular but less manic.
+
=head1 FUNCTIONS
=cut
=head2 new
- Title : new
- Usage : $obj = Foo::Bar->new();
- Function: Creates a new Foo::Bar object
- Returns : A new Foo::Bar object
- Args : none.
+=head3 Usage
+
+ $obj = Foo::Bar->new();
+
+=head3 Function
+
+Creates a new C<Foo::Bar> object.
- Aditional arguments can be passed to this creator, and they are
- stored in $self->{_creation_args}. You can also override the new
- method in your subclass. It's just provided here for completeness.
+Aditional arguments can be passed to this creator, and they are stored
+in C<$self->{_creation_args}>. You can also override the new method in
+your subclass. It's just provided here for completeness.
=cut
=head2 load
- Title : load
- Usage : $db->load('FOO::Subclass');
- Function: loads a Class::Modular subclass
- Returns : nothing
- Args : SCALAR subclass SCALAR options
+=head3 Usage
+
+ $db->load('FOO::Subclass');
- Loads the named subclass into this object if the named subclass has
- not been loaded.
+=head3 Function
+
+Loads the named subclass into this object if the named subclass has
+not been loaded.
- The options scalar is passed to $subclass::_methods when determining
- which methods should be added using _addmethods.
+The options scalar is passed to $subclass::_methods when determining
+which methods should be added using _addmethods.
- The subclasses _init method is called right after methods are loaded.
+The subclasses _init method is called right after methods are loaded.
- If debugging is enabled, will warn about loading already loaded
- subclasses.
+If debugging is enabled, will warn about loading already loaded
+subclasses.
=cut
eval {
no strict 'refs';
eval "require $subclass" or die $@;
+ # Use subclass::METHODS if it exists [use constants METHODS => qw(foo)]
$self->_addmethods($subclass,&{"${subclass}::_methods"}($self,$options));
&{"${subclass}::_init"}($self);
};
=head2 _addmethods
- Title : _addmethods
- Usage : $self->_addmethods()
- Function: Adds the passed methods into the function table
- Returns :
- Args : ARRAY of methods
+=head3 Usage
+
+ $self->_addmethods($subclass,&{"${subclass}::_methods"}($self,$options));
+
+=head3 Function
- Given an array of methods, adds the methods into the _methodhash
- calling table.
+Given an array of methods, adds the methods into the _methodhash
+calling table.
- Methods that have previously been overridden by override are _NOT_
- overridden again. This may need to be adjusted in load.
+Methods that have previously been overridden by override are _NOT_
+overridden again. This may need to be adjusted in load.
=cut
=head2 override
- Title : override
- Usage : $obj->override('methodname', $code_ref)
- Function: Overrides the method methodname and calls $code_ref instead.
- Returns : TRUE on success, FALSE on failure.
- Args : SCALAR method name
- CODEREF function reference
+=head3 Usage
+
+ $obj->override('methodname', $code_ref)
+
+=head3 Function
- Allows you to override utility functions that are called internally
- to provide a different default function.
+Allows you to override utility functions that are called internally to
+provide a different default function.
- It's superficially similar to _addmethods, which is called by load,
- but it deals with code references, and requires the method name to be
- known.
+It's superficially similar to _addmethods, which is called by load,
+but it deals with code references, and requires the method name to be
+known.
- Methods overridden here are _NOT_ overrideable in _addmethods. This
- may need to be changed.
+Methods overridden here are _NOT_ overrideable in _addmethods. This
+may need to be changed.
=cut
=head2 clone
- Title : clone
- Usage : my $clone = $obj->clone
- Function: Produces a clone of the Class::Modular object
- Returns :
- Args :
+=head3 Usage
+
+ my $clone = $obj->clone
- Produces a clone of the object with duplicates of all data and/or new
- connections as appropriate.
+=head3 Function
+
+Produces a clone of the object with duplicates of all data and/or new
+connections as appropriate.
- Calls _clone on all loaded subclasses.
+Calls _clone on all loaded subclasses.
- Warns if debugging is on for classes which don't have a _clone
- method. Dies on other errors.
+Warns if debugging is on for classes which don't have a _clone method.
+Dies on other errors.
=cut
=head2 AUTOLOAD
- Title : AUTOLOAD
- Usage : Called by perl
- Function: Calls child methods which have been installed into this handle
- Returns : N/A
- Args : N/A
+=head3 Function
The AUTOLOAD function is responsible for calling child methods which
have been installed into the current Class::Modular handle.