File: 03-lazy.t

package info (click to toggle)
libmoosex-attributeshortcuts-perl 0.024-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 312 kB
  • ctags: 9
  • sloc: perl: 326; makefile: 2
file content (50 lines) | stat: -rw-r--r-- 1,026 bytes parent folder | download | duplicates (2)
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;

{
    package TestClass;

    use Moose;
    use namespace::autoclean;
    use MooseX::AttributeShortcuts;

    has foo => (is => 'lazy');
    has bar => (is => 'lazy', default => 'bip!');

    # if this one fails, we're just going to get a die() off it for a "cannot
    # have both a builder and a default!" violation.  So, the test here really
    # is "does it not die?"
    has baz => (is => 'lazy', default => 0);
}

use Test::More;
use Test::Moose;

require 't/funcs.pm' unless eval { require funcs };

my %foo_accessors = (
    reader   => 'foo',
    init_arg => 'foo',
    lazy     => 1,
    builder  => '_build_foo',
    default  => undef,
);

my %bar_accessors = (
    reader   => 'bar',
    init_arg => 'bar',
    lazy     => 1,
    default  => 'bip!',
    builder  => undef,
);

with_immutable {

    test_class_sanity_checks('TestClass');
    check_attribute('TestClass', foo => %foo_accessors);
    check_attribute('TestClass', bar => %bar_accessors);

} 'TestClass';

done_testing;