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 {
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 Yuval Kogman E<lt>nothingmuch@woobling.comE<gt>
64 =head1 COPYRIGHT AND LICENSE
66 Copyright 2006-2008 by Infinity Interactive, Inc.
68 L<http://www.iinteractive.com>
70 This library is free software; you can redistribute it and/or modify
71 it under the same terms as Perl itself.