The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.


Class::Methods - Object methods for working with classes


  use Class::Methods;
  my $container = bless [], Class::Methods->new(
    count => sub { return scalar @{$_[0]} },

  print $container->count; # prints 0

  $container->extend( push => sub { push @{$_[0]}, $_[1..$#_] } );

  $container->push( qw[apples oranges] );

  $container->remove( "push" );

  print $container->count; # prints 2

  # XXX: $container->base('ARRAY'); # import push(), pop(), splice(), etc.


After discussing Ruby with Simon, I wrote this module to implement OO in Perl via the builtin inheritance-based method system.

It seems to be pretty fun to work with. Kind of resesmbles ruby, though, and I suspect it might start enroaching on Perl 6.

This is the first release, to share the madness with y'all. I've planned serious uses of this module, so perhaps it'll find a good home. is the only code example right. The core's small, and fun to read.


Richard Soderberg,