Debian lenny version packages
[pkg-perl] / deb-src / libclass-accessor-chained-perl / libclass-accessor-chained-perl-0.01.1~debian / t / chained.t
1 #!perl -w
2 use strict;
3 use Test::More tests => 6;
4
5 package Foo;
6 use base 'Class::Accessor::Chained';
7 __PACKAGE__->mk_accessors(qw( foo bar baz ));
8 package main;
9
10 my $foo = Foo->new->foo(1)->baz(2)->bar(4);
11 isa_ok( $foo, 'Foo' );
12 is( $foo->bar, 4, "get gets the value" );
13 is( $foo->foo( 5 ), $foo, "set gets the object" );
14
15 # and again, but with Fast accessors
16 package Bar;
17 use base 'Class::Accessor::Chained::Fast';
18 __PACKAGE__->mk_accessors(qw( foo bar baz ));
19 package main;
20
21 my $bar = Bar->new->foo(1)->baz(2)->bar(4);
22 isa_ok( $bar, 'Bar' );
23 is( $bar->bar, 4, "get gets the value" );
24 is( $bar->foo( 5 ), $bar, "set gets the object" );