File: 03-extensions.t

package info (click to toggle)
libmoosex-has-options-perl 0.003-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 152 kB
  • sloc: perl: 186; makefile: 2
file content (50 lines) | stat: -rw-r--r-- 1,095 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
48
49
50
use strict;
use warnings;

use Test::Most;

do {
    package TestOptions;

    use Moose;
    use MooseX::Has::Options qw(NativeTypes NoInit);
    use namespace::autoclean;

    has 'no_init_attribute' => qw(:ro :lazy_build :no_init :string);

    has 'arrayref_attribute' =>
        qw(:ro :required :array),
        handles => {
            add_to_arrayref   => 'push',
            arrayref_elements => 'elements',
        };

    has 'hashref_attribute' =>
        qw(:ro :hash),
        isa     => 'HashRef[Int]',
        default => sub { { foo => 1, bar => 2 } },
        handles => { hash_value => 'get' };


    sub _build_no_init_attribute { 'foo' }
};

my $test_obj;

lives_ok {
    $test_obj = TestOptions->new(
        arrayref_attribute => ['crash'],
        no_init_attribute  => 'bar',
    );
} "create object";

is($test_obj->no_init_attribute, 'foo', ":no_init honored");

$test_obj->add_to_arrayref('boom', 'bang');

is_deeply([$test_obj->arrayref_elements], [qw(crash boom bang)], 'array delegation');

is($test_obj->hash_value('foo'), 1, 'hash delegation');


done_testing();