Stevan Little > Class-MOP-0.26 > InstanceCountingClass

Download:
Class-MOP-0.26.tar.gz

Annotate this POD

CPAN RT

New  1
Open  2
View Bugs
Report a bug
Source   Latest Release: Class-MOP-0.37

NAME ^

InstanceCountingClass - An example metaclass which counts instances

SYNOPSIS ^

  package Foo;
  
  use metaclass 'InstanceCountingClass';
  
  sub new  {
      my $class = shift;
      $class->meta->new_object(@_);
  }

  # ... meanwhile, somewhere in the code

  my $foo = Foo->new();
  print Foo->meta->get_count(); # prints 1
  
  my $foo2 = Foo->new();
  print Foo->meta->get_count(); # prints 2  
  
  # ... etc etc etc

DESCRIPTION ^

This is a classic example of a metaclass which keeps a count of each instance which is created.

AUTHOR ^

Stevan Little <stevan@iinteractive.com>

COPYRIGHT AND LICENSE ^

Copyright 2006 by Infinity Interactive, Inc.

http://www.iinteractive.com

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.