Merge branch 'stable'
[gitmo/Class-MOP.git] / examples / InstanceCountingClass.pod
index 93ba4d5..b28fef8 100644 (file)
@@ -5,24 +5,19 @@ package # hide the package from PAUSE
 use strict;
 use warnings;
 
-use Class::MOP 'meta';
-
-our $VERSION = '0.01';
+our $VERSION = '0.03';
 
 use base 'Class::MOP::Class';
 
-__PACKAGE__->meta->add_attribute(
-    Class::MOP::Attribute->new('$:count' => (
-        reader  => 'get_count',
-        default => 0
-    ))
-);
+InstanceCountingClass->meta->add_attribute('count' => (
+    reader  => 'get_count',
+    default => 0
+));
 
-sub construct_instance {
-    my ($class, %params) = @_;
-    $class->{'$:count'}++;
-    return $class->SUPER::construct_instance();
-}
+InstanceCountingClass->meta->add_before_method_modifier('_construct_instance' => sub {
+    my ($class) = @_;
+    $class->{'count'}++;       
+});
 
 1;
 
@@ -38,10 +33,11 @@ InstanceCountingClass - An example metaclass which counts instances
 
   package Foo;
   
-  sub meta { InstanceCountingClass->initialize($_[0]) }
+  use metaclass 'InstanceCountingClass';
+  
   sub new  {
       my $class = shift;
-      bless $class->meta->construct_instance() => $class;
+      $class->meta->new_object(@_);
   }
 
   # ... meanwhile, somewhere in the code
@@ -59,13 +55,15 @@ InstanceCountingClass - An example metaclass which counts instances
 This is a classic example of a metaclass which keeps a count of each 
 instance which is created. 
 
-=head1 AUTHOR
+=head1 AUTHORS
 
 Stevan Little E<lt>stevan@iinteractive.comE<gt>
 
+Yuval Kogman E<lt>nothingmuch@woobling.comE<gt>
+
 =head1 COPYRIGHT AND LICENSE
 
-Copyright 2006 by Infinity Interactive, Inc.
+Copyright 2006-2008 by Infinity Interactive, Inc.
 
 L<http://www.iinteractive.com>