NAME

Class::SingletonMethod - Extend individual objects with additional methods

SYNOPSIS

my $a = Some::Class->new; 
my $b = Some::Class->new; 
 
$a->singleton_method( dump => sub { 
  my $self = shift; 
  require Data::Dumper; 
  print STDERR Date::Dumper::Dumper($self)  
}); 
 
$a->dump; # Prints a representation of the object. 
$b->dump; # Can't locate method "dump" 

DESCRIPTION

This module provides a Perl implementation of singleton methods. The Ruby FAQ defines singleton methods like so:

(Q)     What is a singleton method?

(A)     A singleton method is defined for the particular object but
        in the class. A singleton method allows appending or
        changing methods without making subclasses.

        msg = "Hello"
        def msg.print
          $>.print self, "\n"
        end
        msg.print   #=> Hello

That is, you can add or override methods on a per-object basis.

AUTHOR

Simon Cozens, simon@cpan.org

SEE ALSO

ruby(1)