File: 01-basic.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 (40 lines) | stat: -rw-r--r-- 876 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
use strict;
use warnings;

use Test::Most;

{
    package TestOptions;

    use Moose;
    use MooseX::Has::Options;
    use namespace::autoclean;

    has 'plain_attribute' =>
    (
        qw(:ro :required),
        isa => 'Str',
    );

    has 'attribute_with_options' =>
    (
        qw(:ro :lazy_build),
        isa => 'Str'
    );

    sub _build_attribute_with_options
    {
        return 'SomeRandomValue';
    }
}

my $to = TestOptions->new( plain_attribute => 'Plain');

is( $to->plain_attribute,        'Plain',           'accessing' );
is( $to->attribute_with_options, 'SomeRandomValue', 'lazy'      );

dies_ok { $to->plain_attribute('Something')                      } 'read only';
dies_ok { my $to_required = TestOptions->new                     } 'required';
dies_ok { my $to_str = TestOptions->new( plain_attribute => [] ) } 'constraint';

done_testing();