Commit | Line | Data |
ad6edfcb |
1 | #!./perl -w |
2 | |
3 | BEGIN { |
4 | chdir 't' if -d 't'; |
5 | @INC = '../lib'; |
6 | } |
7 | |
f8aada62 |
8 | print "1..12\n"; |
ad6edfcb |
9 | |
10 | package aClass; |
11 | |
12 | sub new { bless {}, shift } |
13 | |
14 | sub meth { 42 } |
15 | |
f8aada62 |
16 | package RecClass; |
17 | |
18 | sub new { bless {}, shift } |
19 | |
ad6edfcb |
20 | package MyObj; |
21 | |
22633ac4 |
22 | use Class::Struct; |
23 | use Class::Struct 'struct'; # test out both forms |
ad6edfcb |
24 | |
25 | use Class::Struct SomeClass => { SomeElem => '$' }; |
26 | |
27 | struct( s => '$', a => '@', h => '%', c => 'aClass' ); |
28 | |
29 | my $obj = MyObj->new; |
30 | |
31 | $obj->s('foo'); |
32 | |
33 | print "not " unless $obj->s() eq 'foo'; |
34 | print "ok 1\n"; |
35 | |
36 | my $arf = $obj->a; |
37 | |
38 | print "not " unless ref $arf eq 'ARRAY'; |
39 | print "ok 2\n"; |
40 | |
41 | $obj->a(2, 'secundus'); |
42 | |
43 | print "not " unless $obj->a(2) eq 'secundus'; |
44 | print "ok 3\n"; |
45 | |
46 | my $hrf = $obj->h; |
47 | |
48 | print "not " unless ref $hrf eq 'HASH'; |
49 | print "ok 4\n"; |
50 | |
51 | $obj->h('x', 10); |
52 | |
53 | print "not " unless $obj->h('x') == 10; |
54 | print "ok 5\n"; |
55 | |
56 | my $orf = $obj->c; |
57 | |
f8aada62 |
58 | print "not " if defined($orf); |
ad6edfcb |
59 | print "ok 6\n"; |
60 | |
f8aada62 |
61 | $obj = MyObj->new( c => aClass->new ); |
62 | $orf = $obj->c; |
63 | |
64 | print "not " if ref $orf ne 'aClass'; |
ad6edfcb |
65 | print "ok 7\n"; |
66 | |
f8aada62 |
67 | print "not " unless $obj->c->meth() == 42; |
68 | print "ok 8\n"; |
69 | |
ad6edfcb |
70 | my $obk = SomeClass->new(); |
71 | |
72 | $obk->SomeElem(123); |
73 | |
74 | print "not " unless $obk->SomeElem() == 123; |
f8aada62 |
75 | print "ok 9\n"; |
ad6edfcb |
76 | |
726cfeaf |
77 | $obj->a([4,5,6]); |
78 | |
79 | print "not " unless $obj->a(1) == 5; |
f8aada62 |
80 | print "ok 10\n"; |
726cfeaf |
81 | |
82 | $obj->h({h=>7,r=>8,f=>9}); |
83 | |
84 | print "not " unless $obj->h('r') == 8; |
f8aada62 |
85 | print "ok 11\n"; |
86 | |
87 | my $recobj = RecClass->new() or print "not "; |
88 | print "ok 12\n"; |
726cfeaf |
89 | |