]> git.donarmstrong.com Git - class_modular.git/.git/blob - t/01_module.t
e2711c50a5eaca3c594ab39dc8b8c1a0665d7b14
[class_modular.git/.git] / t / 01_module.t
1 # This file is part of Class::Modular and is released under the terms
2 # of the GPL version 2, or any later version at your option. See the
3 # file README and COPYING for more information.
4 # Copyright 2004 by Don Armstrong <don@donarmstrong.com>.
5 # $Id: $
6
7
8 use Test::Simple tests => 7;
9
10 use UNIVERSAL;
11
12 my $destroy_hit = 0;
13
14 {
15      # Fool require.
16      $INC{'Foo.pm'} = '1';
17      package Foo;
18
19      use base qw(Class::Modular);
20      use constant METHODS => 'blah';
21
22      sub blah {
23           return 1;
24      }
25
26      sub _destroy{
27           $destroy_hit = 1;
28      }
29 }
30
31
32 my $foo = new Foo(qw(bar baz));
33
34 # 1: test new
35 ok(defined $foo and ref($foo) eq 'Foo' and UNIVERSAL::isa($foo,'Class::Modular'), 'new() works');
36
37 $foo->load('Foo');
38 # 2: test load()
39 ok(exists $foo->{_subclasses}{Foo}, 'load() works');
40 # 3: test AUTOLOAD
41 ok($foo->blah, 'AUTOLOAD works');
42
43 # Check override
44 #$foo->override('blah',sub{return 2});
45 #ok($foo->blah == 2, 'override() works');
46
47 # Check can
48 # 5: Check can
49 ok($foo->can('blah'),'can() works');
50
51 # Check clone
52 ok(defined $foo->clone, 'clone() works');
53
54 # Check handledby
55 ok($foo->handledby('blah') eq 'Foo', 'handledby() works');
56
57 # Check DESTROY
58 undef $foo;
59 ok($destroy_hit,'DESTROY called _destroy');