Class::SingletonMethod - Extend individual objects with additional methods
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"
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.
Simon Cozens, simon@cpan.org
simon@cpan.org
ruby(1)
To install Class::SingletonMethod, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Class::SingletonMethod
CPAN shell
perl -MCPAN -e shell install Class::SingletonMethod
For more information on module installation, please visit the detailed CPAN module installation guide.