File: role.t

package info (click to toggle)
libsub-handlesvia-perl 0.050002-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 1,656 kB
  • sloc: perl: 9,585; makefile: 2
file content (52 lines) | stat: -rw-r--r-- 902 bytes parent folder | download | duplicates (4)
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
48
49
50
51
52
use strict;
use warnings;
use Test::More;
use Test::Fatal;
{ package Local::Dummy1; use Test::Requires 'Moose' };

{
	package Local::Role1;
	use Moose::Role;
	use Sub::HandlesVia;
	use Types::Standard qw( ArrayRef Int );
	has nums => (
		is           => 'ro',
		isa          => ArrayRef[Int],
		builder      => '_build_nums',
		handles_via  => 'Array',
		handles      => { pop_num => 'pop', push_num => 'push' },
	);
	sub _build_nums { [ 1..10 ] }
}

{
	package Local::Class1;
	use Moose;
	with 'Local::Role1';
}

#require B::Deparse;
#::note( B::Deparse->new->coderef2text(\&Local::Class1::pop_num) );

my $obj = Local::Class1->new;

is( $obj->pop_num, 10 );
is( $obj->pop_num, 9 );
is( $obj->pop_num, 8 );
is( $obj->pop_num, 7 );

isnt(
	exception { $obj->push_num(44.5) },
	undef,
);

is( $obj->pop_num, 6 );

is(
	exception { $obj->push_num(6) },
	undef,
);

is( $obj->pop_num, 6 );

done_testing;