]> git.donarmstrong.com Git - class_modular.git/.git/blob - t/01_module.t
* Module tests now work correctly
[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 _methods {
27           return qw(blah);
28      }
29
30      sub _destroy{
31           $destroy_hit = 1;
32      }
33 }
34
35
36 my $foo = new Foo(qw(bar baz));
37
38 # 1: test new
39 ok(defined $foo and ref($foo) eq 'Foo' and UNIVERSAL::isa($foo,'Class::Modular'), 'new() works');
40
41 $foo->load('Foo');
42 # 2: test load()
43 ok(exists $foo->{__class_modular}{_subclasses}{Foo}, 'load() works');
44 # 3: test AUTOLOAD
45 ok($foo->blah, 'AUTOLOAD works');
46
47 # Check override
48 #$foo->override('blah',sub{return 2});
49 #ok($foo->blah == 2, 'override() works');
50
51 # Check can
52 # 5: Check can
53 ok($foo->can('blah'),'can() works');
54
55 # Check clone
56 ok(defined $foo->clone, 'clone() works');
57
58 # Check handledby
59 ok($foo->handledby('blah') eq 'Foo', 'handledby() works');
60
61 # Check DESTROY
62 undef $foo;
63 ok($destroy_hit,'DESTROY called _destroy');