Make "use Class::Struct 'struct';" work again (broken by #7617);
[p5sagit/p5-mst-13.2.git] / t / lib / class-struct.t
1 #!./perl -w
2
3 BEGIN {
4         chdir 't' if -d 't';
5         @INC = '../lib';
6 }
7
8 print "1..2\n";
9
10 package aClass;
11
12 sub new { bless {}, shift }
13
14 sub meth { 42 }
15
16 package MyObj;
17
18 use Class::Struct 'struct';
19
20 use Class::Struct SomeClass => { SomeElem => '$' };
21
22 struct( s => '$', a => '@', h => '%', c => 'aClass' );
23
24 my $obj = MyObj->new;
25
26 $obj->s('foo');
27
28 print "not " unless $obj->s() eq 'foo';
29 print "ok 1\n";
30
31 my $arf = $obj->a;
32
33 print "not " unless ref $arf eq 'ARRAY';
34 print "ok 2\n";
35
36 $obj->a(2, 'secundus');
37
38 print "not " unless $obj->a(2) eq 'secundus';
39 print "ok 3\n";
40
41 my $hrf = $obj->h;
42
43 print "not " unless ref $hrf eq 'HASH';
44 print "ok 4\n";
45
46 $obj->h('x', 10);
47
48 print "not " unless $obj->h('x') == 10;
49 print "ok 5\n";
50
51 my $orf = $obj->c;
52
53 print "not " unless ref $orf eq 'aClass';
54 print "ok 6\n";
55
56 print "not " unless $obj->c->meth() == 42;
57 print "ok 7\n";
58
59 my $obk = SomeClass->new();
60
61 $obk->SomeElem(123);
62
63 print "not " unless $obk->SomeElem() == 123;
64 print "ok 8\n";
65
66
67
68
69