2 package # hide the package from PAUSE
10 our $VERSION = '0.01';
12 use base 'Class::MOP::Class';
14 __PACKAGE__->meta->add_attribute(
15 Class::MOP::Attribute->new('$:count' => (
16 reader => 'get_count',
21 sub construct_instance {
22 my ($class, %params) = @_;
23 $class->{'$:count'}++;
24 return $class->SUPER::construct_instance();
35 InstanceCountingClass - An example metaclass which counts instances
41 sub meta { InstanceCountingClass->initialize($_[0]) }
44 bless $class->meta->construct_instance() => $class;
47 # ... meanwhile, somewhere in the code
50 print Foo->meta->get_count(); # prints 1
52 my $foo2 = Foo->new();
53 print Foo->meta->get_count(); # prints 2
59 This is a classic example of a metaclass which keeps a count of each
60 instance which is created.
64 Stevan Little E<lt>stevan@iinteractive.comE<gt>
66 =head1 COPYRIGHT AND LICENSE
68 Copyright 2006 by Infinity Interactive, Inc.
70 L<http://www.iinteractive.com>
72 This library is free software; you can redistribute it and/or modify
73 it under the same terms as Perl itself.