2 package # hide the package from PAUSE
10 use base 'Class::MOP::Class';
12 InstanceCountingClass->meta->add_attribute('$:count' => (
13 reader => 'get_count',
17 InstanceCountingClass->meta->add_before_method_modifier('construct_instance' => sub {
19 $class->{'$:count'}++;
30 InstanceCountingClass - An example metaclass which counts instances
36 use metaclass 'InstanceCountingClass';
40 $class->meta->new_object(@_);
43 # ... meanwhile, somewhere in the code
46 print Foo->meta->get_count(); # prints 1
48 my $foo2 = Foo->new();
49 print Foo->meta->get_count(); # prints 2
55 This is a classic example of a metaclass which keeps a count of each
56 instance which is created.
60 Stevan Little E<lt>stevan@iinteractive.comE<gt>
62 =head1 COPYRIGHT AND LICENSE
64 Copyright 2006 by Infinity Interactive, Inc.
66 L<http://www.iinteractive.com>
68 This library is free software; you can redistribute it and/or modify
69 it under the same terms as Perl itself.