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