]> git.donarmstrong.com Git - class_modular.git/.git/blob - t/01_module.t
17ce5ec528bde92b0130fe50d8a4e16f75bdf3d8
[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 => 9;
9
10 use UNIVERSAL;
11
12 my $destroy_hit = 0;
13
14 {
15      # Foo 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      # Bar require.
37      $INC{'Bar.pm'} = '1';
38      package Bar;
39
40      use base qw(Class::Modular);
41      use constant METHODS => 'bleh';
42
43      sub bleh {
44           return 1;
45      }
46
47      sub _methods {
48           return qw(bleh);
49      }
50 }
51
52
53
54
55 my $foo = new Foo(qw(bar baz));
56
57 # 1: test new
58 ok(defined $foo and UNIVERSAL::isa($foo,'Class::Modular'), 'new() works');
59
60 # 2: test load()
61 ok(exists $foo->{__class_modular}{_subclasses}{Foo}, 'load() works');
62 # 3: test AUTOLOAD
63 ok($foo->blah, 'AUTOLOAD works');
64
65 # Check override
66 $foo->override('blah',sub{return 2});
67 ok($foo->blah == 2, 'override() works');
68
69 # Check can
70 # 5: Check can
71 ok($foo->can('blah'),'can() works');
72
73 # Check clone
74 ok(defined $foo->clone, 'clone() works');
75
76 # Check handledby
77 ok($foo->handledby('blah') eq 'Foo', 'handledby() works');
78
79 # Check DESTROY
80 undef $foo;
81 ok($destroy_hit,'DESTROY called _destroy');
82
83 # Check non-existant _destroy doesn't cause a failure
84
85 eval {my $bar = new Bar();
86       undef $bar;
87  };
88 ok($@ eq '','Non existant _destroy not a problem');