File: class.t

package info (click to toggle)
libclass-tiny-chained-perl 0.004-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 168 kB
  • sloc: perl: 177; makefile: 2
file content (47 lines) | stat: -rw-r--r-- 1,240 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
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
use strict;
use warnings;

package MyClass;
use Class::Tiny 'foo';

package MyClass::Chained;
use Class::Tiny::Chained 'abc', 'def';

package MyClass::Unchained;
@MyClass::Unchained::ISA = ('MyClass::Chained');
use Class::Tiny 'abc';

package MyClass::Rechained;
@MyClass::Rechained::ISA = ('MyClass');
use Class::Tiny::Chained 'abc';

package main;

use Scalar::Util 'blessed';
use Test::More;

my $obj;

$obj = MyClass->new;
is $obj->foo(2), 2, 'setter is not chained';
is $obj->foo, 2, 'getter is not chained';

$obj = MyClass::Chained->new;
is blessed($obj->abc(2)), 'MyClass::Chained', 'setter is chained';
is $obj->abc, 2, 'getter is not chained';
is blessed($obj->def(3)), 'MyClass::Chained', 'setter is chained';
is $obj->def, 3, 'getter is not chained';

$obj = MyClass::Unchained->new;
is $obj->abc(2), 2, 'setter is not chained';
is $obj->abc, 2, 'getter is not chained';
is blessed($obj->def(3)), 'MyClass::Unchained', 'setter is chained';
is $obj->def, 3, 'getter is not chained';

$obj = MyClass::Rechained->new;
is $obj->foo(2), 2, 'setter is not chained';
is $obj->foo, 2, 'getter is not chained';
is blessed($obj->abc(3)), 'MyClass::Rechained', 'setter is chained';
is $obj->abc, 3, 'getter is not chained';

done_testing;