File: 50objectpad.t

package info (click to toggle)
libsub-handlesvia-perl 0.050000-1%2Bdeb12u1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,840 kB
  • sloc: perl: 9,585; makefile: 2
file content (52 lines) | stat: -rw-r--r-- 1,039 bytes parent folder | download
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;
{ package Local::Dummy1; use Test::Requires { 'Object::Pad' => 0.67 }; }

##############################################################################

use Object::Pad;

class FooBar {
	has $x :reader = [];
	use Sub::HandlesVia::Declare '$x', Array => (
		all_x => 'all',
		add_x => 'push',
	);

	has @y;
	use Sub::HandlesVia::Declare '@y', (
		all_y => 'all',
		add_y => 'push',
	);
	
	has %z;
	use Sub::HandlesVia::Declare '%z', (
		all_z => 'all',
		add_z => 'set',
	);
}

my $o = FooBar->new;

$o->add_x( 123 );
$o->add_x( 456 );
is_deeply( $o->x, [ 123, 456 ] );
is_deeply( [ $o->all_x ], [ 123, 456 ] );

$o->add_y( 123 );
$o->add_y( 456 );
is_deeply( [ $o->all_y ], [ 123, 456 ] );

$o->add_z( foo => 123 );
$o->add_z( bar => 456 );
is_deeply( { $o->all_z }, { bar => 456, foo => 123 } );

for my $method ( qw/ add_x all_x add_y all_y add_z all_z / ) {
	no warnings 'once';
	local $Data::Dumper::Deparse = 1;
	note "==== $method ====";
	note explain( $o->can($method) );
}

done_testing;