Mouse::Util::does_role() respects $thing->does() method
[gitmo/Mouse.git] / t / 100_bugs / 010_immutable_n_default_x2.t
CommitLineData
4c98ebb0 1#!/usr/bin/perl
ee5e6a03 2# This is automatically generated by author/import-moose-test.pl.
3# DO NOT EDIT THIS FILE. ANY CHANGES WILL BE LOST!!!
4use t::lib::MooseCompat;
4c98ebb0 5
6use strict;
7use warnings;
8
ee5e6a03 9use Test::More;
4c98ebb0 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
36my $foo = Foo->new();
37
38is($Foo::foo_default_called, 1, "foo default was only called once during constructor");
39
40$foo->bar();
41
42is($Foo::bar_default_called, 1, "bar default was only called once when lazy attribute is accessed");
ee5e6a03 43
44done_testing;