This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Reference cmp'ing should go through the whole stringification
[perl5.git] / t / lib / class-struct.t
CommitLineData
ad6edfcb
JH
1#!./perl -w
2
3BEGIN {
4 chdir 't' if -d 't';
5 @INC = '../lib';
6}
7
af2c551d 8print "1..8\n";
ad6edfcb
JH
9
10package aClass;
11
12sub new { bless {}, shift }
13
14sub meth { 42 }
15
16package MyObj;
17
22633ac4
JH
18use Class::Struct;
19use Class::Struct 'struct'; # test out both forms
ad6edfcb
JH
20
21use Class::Struct SomeClass => { SomeElem => '$' };
22
23struct( s => '$', a => '@', h => '%', c => 'aClass' );
24
25my $obj = MyObj->new;
26
27$obj->s('foo');
28
29print "not " unless $obj->s() eq 'foo';
30print "ok 1\n";
31
32my $arf = $obj->a;
33
34print "not " unless ref $arf eq 'ARRAY';
35print "ok 2\n";
36
37$obj->a(2, 'secundus');
38
39print "not " unless $obj->a(2) eq 'secundus';
40print "ok 3\n";
41
42my $hrf = $obj->h;
43
44print "not " unless ref $hrf eq 'HASH';
45print "ok 4\n";
46
47$obj->h('x', 10);
48
49print "not " unless $obj->h('x') == 10;
50print "ok 5\n";
51
52my $orf = $obj->c;
53
54print "not " unless ref $orf eq 'aClass';
55print "ok 6\n";
56
57print "not " unless $obj->c->meth() == 42;
58print "ok 7\n";
59
60my $obk = SomeClass->new();
61
62$obk->SomeElem(123);
63
64print "not " unless $obk->SomeElem() == 123;
65print "ok 8\n";
66