simplification of code, fixes #45260 and makes behavior same as Moose attributes
[gitmo/MooseX-ClassAttribute.git] / t / 09-bare-native-attribute-trait.t
1
2 # reported in https://rt.cpan.org/Public/Bug/Display.html?id=59573
3
4 use strict;
5 use warnings;
6
7 use Test::More tests => 2;
8 use Test::NoWarnings;
9 use Test::Exception;
10
11 {
12     package Foo;
13     use Moose;
14     use MooseX::ClassAttribute;
15     class_has attr => (
16         is => 'bare', isa => 'HashRef[Str]',
17         lazy => 1,
18         default => sub { {} },
19         traits => ['Hash'],
20         handles => {
21             has_attr => 'exists',
22         },
23     );
24 }
25
26 package main;
27
28 # in Moose 1.08/MooseX::ClassAttribute 0.16, this dies with:
29 # Can't use an undefined value as a HASH reference
30 lives_ok { Foo->has_attr('key') }
31     'Default builder in a native attribute trait is properly run when the attribute is defined with no standard accessors';
32
33