File: chained.t

package info (click to toggle)
libclass-accessor-chained-perl 0.01.1~debian-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, buster, sid, stretch
  • size: 84 kB
  • ctags: 6
  • sloc: perl: 87; makefile: 2
file content (24 lines) | stat: -rw-r--r-- 636 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#!perl -w
use strict;
use Test::More tests => 6;

package Foo;
use base 'Class::Accessor::Chained';
__PACKAGE__->mk_accessors(qw( foo bar baz ));
package main;

my $foo = Foo->new->foo(1)->baz(2)->bar(4);
isa_ok( $foo, 'Foo' );
is( $foo->bar, 4, "get gets the value" );
is( $foo->foo( 5 ), $foo, "set gets the object" );

# and again, but with Fast accessors
package Bar;
use base 'Class::Accessor::Chained::Fast';
__PACKAGE__->mk_accessors(qw( foo bar baz ));
package main;

my $bar = Bar->new->foo(1)->baz(2)->bar(4);
isa_ok( $bar, 'Bar' );
is( $bar->bar, 4, "get gets the value" );
is( $bar->foo( 5 ), $bar, "set gets the object" );