]> git.donarmstrong.com Git - class_modular.git/.git/commitdiff
* Added can support
authorDon Armstrong <don@donarmstrong.com>
Sat, 25 Oct 2003 02:15:04 +0000 (02:15 +0000)
committerDon Armstrong <don@donarmstrong.com>
Sat, 25 Oct 2003 02:15:04 +0000 (02:15 +0000)
 * Document AUTOLOAD in subclasses

git-svn-id: file:///srv/don_svn/class_modular/trunk@5 96c6a18b-02ce-0310-9fca-9eb62c757ba6

Class/Modular/Modular.pm

index f7ca9f17e6e62038152c078f15bb12124514ff5e..18cf89e652ae1cf2c13bbe15a6edacddb59510e3 100644 (file)
@@ -2,7 +2,7 @@
 # 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>.
-# $Id: Modular.pm,v 1.4 2003/10/24 04:48:51 don Exp $
+# $Id: Modular.pm,v 1.5 2003/10/25 02:15:04 don Exp $
 
 package Class::Modular;
 
@@ -41,9 +41,7 @@ load is responsible for loading database plugins
 =back
 
 
-=head1 BUGS
-
-None known.
+=head1 FUNCTIONS
 
 =cut
 
@@ -55,7 +53,7 @@ use Carp;
 use Data::Copy qw(deep_copy); # Used for deep copying objects
 
 BEGIN{
-     ($VERSION) = q$Revision: 1.4 $ =~ /\$Revision:\s+([^\s+])/;
+     ($VERSION) = q$Revision: 1.5 $ =~ /\$Revision:\s+([^\s+])/;
      $DEBUG = 0 unless defined $DEBUG;
 }
 
@@ -233,6 +231,7 @@ sub clone {
          # Ignore no such function errors, but trap other types of
          # errors.
 
+         # XXX Switch to can instead.
          eval {
               no strict 'refs';
               &$subclass::_clone($self,$clone);
@@ -247,6 +246,43 @@ sub clone {
      }
 }
 
+=head2 can
+
+=head3 Usage
+
+     $obj->can('METHOD');
+     Class::Modular->can('METHOD');
+
+=head3 Function
+
+Replaces UNIVERSAL's can method so that handled methods are reported
+correctly. Calls UNIVERSAL::can in the places where 
+
+=head3 Returns
+
+A coderef to the method if the method is supported, undef otherwise.
+
+=head3 Args
+
+Scalar Method Name
+
+=cut
+
+sub can{
+     my ($self,$method,$vars) = @_;
+
+     if (ref $self and exists $self->{_methodhash}->{$method}) {
+         # If the method is defined, return a reference to the
+         # method.
+         return $self->{_methodhash}->{$method}->{reference};
+     }
+     else {
+         # Otherwise, let UNIVERSAL::can deal with the method
+         # appropriately.
+         return UNIVERSAL::can($self,$method);
+     }
+}
+
 
 =head2 DESTROY
 
@@ -291,8 +327,14 @@ sub DESTROY{
  Returns : N/A
  Args    : N/A
 
- The AUTOLOAD function is responsible for calling child methods which
- have been installed into the current Class::Modular handle.
+The AUTOLOAD function is responsible for calling child methods which
+have been installed into the current Class::Modular handle.
+
+Subclasses that have a new function as well as an AUTOLOAD function
+must call Class::Modular::AUTOLOAD and set $Class::Modular::AUTOLOAD
+
+     $Class::Modular::AUTOLOAD = $AUTOLOAD;
+     goto &Class::Modular::AUTOLOAD;
 
 =cut