1 BEGIN { chdir 't' if -d 't' };
5 use Test::More 'no_plan';
8 my $Class = 'Object::Accessor';
9 my $MyClass = 'My::Class';
14 ### establish another package that subclasses our own
16 use base 'Object::Accessor';
19 my $Object = $MyClass->new;
22 { ok( $Object, "Object created" );
23 isa_ok( $Object, $MyClass );
24 isa_ok( $Object, $Class );
27 ### create an accessor
28 { ok( $Object->mk_accessors( $Acc ),
29 "Accessor '$Acc' created" );
30 ok( $Object->can( $Acc ), " Object can '$Acc'" );
31 ok( $Object->$Acc(1), " Objects '$Acc' set" );
32 ok( $Object->$Acc(), " Objects '$Acc' retrieved" );
35 ### check if we do the right thing when we call an accessor that's
36 ### not a defined function in the base class, and not an accessors
37 ### in the object either
38 { my $sub = eval { $MyClass->can( $$ ); };
40 ok( !$sub, "No sub from non-existing function" );
41 ok( !$@, " Code handled it gracefully" );
44 ### check if a method called on a class, that's not actually there
45 ### doesn't get confused as an object call;
46 { eval { $MyClass->$$ };
48 ok( $@, "Calling '$$' on '$MyClass' dies" );
49 like( $@, qr/from somewhere else/,
50 " Dies with an informative message" );