Include method name in immutable methods (fixes #49680)
[gitmo/Class-MOP.git] / t / 101_InstanceCountingClass_test.t
1 use strict;
2 use warnings;
3
4 use Test::More tests => 11;
5 use File::Spec;
6
7 BEGIN {use Class::MOP;    
8     require_ok(File::Spec->catfile('examples', 'InstanceCountingClass.pod'));
9 }
10
11 =pod
12
13 This is a trivial and contrived example of how to 
14 make a metaclass which will count all the instances
15 created. It is not meant to be anything more than 
16 a simple demonstration of how to make a metaclass.
17
18 =cut
19
20 {
21     package Foo;
22     
23     use metaclass 'InstanceCountingClass';
24     
25     sub new  {
26         my $class = shift;
27         $class->meta->new_object(@_);
28     }
29     
30     package Bar;
31     
32     our @ISA = ('Foo');
33 }
34
35 is(Foo->meta->get_count(), 0, '... our Foo count is 0');
36 is(Bar->meta->get_count(), 0, '... our Bar count is 0');
37
38 my $foo = Foo->new();
39 isa_ok($foo, 'Foo');
40
41 is(Foo->meta->get_count(), 1, '... our Foo count is now 1');
42 is(Bar->meta->get_count(), 0, '... our Bar count is still 0');
43
44 my $bar = Bar->new();
45 isa_ok($bar, 'Bar');
46
47 is(Foo->meta->get_count(), 1, '... our Foo count is still 1');
48 is(Bar->meta->get_count(), 1, '... our Bar count is now 1');
49
50 for (2 .. 10) {
51     Foo->new();
52 }
53
54 is(Foo->meta->get_count(), 10, '... our Foo count is now 10');    
55 is(Bar->meta->get_count(), 1, '... our Bar count is still 1');
56