Mouse::Util::does_role() respects $thing->does() method
[gitmo/Mouse.git] / t / 100_bugs / 010_immutable_n_default_x2.t
1 #!/usr/bin/perl
2 # This is automatically generated by author/import-moose-test.pl.
3 # DO NOT EDIT THIS FILE. ANY CHANGES WILL BE LOST!!!
4 use t::lib::MooseCompat;
5
6 use strict;
7 use warnings;
8
9 use Test::More;
10
11
12 {
13     package Foo;
14     use Mouse;
15
16     our $foo_default_called = 0;
17
18     has foo => (
19         is      => 'rw',
20         isa     => 'Str',
21         default => sub { $foo_default_called++; 'foo' },
22     );
23
24     our $bar_default_called = 0;
25
26     has bar => (
27         is      => 'rw',
28         isa     => 'Str',
29         lazy    => 1,
30         default => sub { $bar_default_called++; 'bar' },
31     );
32
33     __PACKAGE__->meta->make_immutable;
34 }
35
36 my $foo = Foo->new();
37
38 is($Foo::foo_default_called, 1, "foo default was only called once during constructor");
39
40 $foo->bar();
41
42 is($Foo::bar_default_called, 1, "bar default was only called once when lazy attribute is accessed");
43
44 done_testing;