init_arg can be undef
[gitmo/Moose.git] / t / 020_attributes / 018_no_init_arg.t
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5
6 use Test::More tests => 5;
7 use Test::Exception;
8
9 BEGIN {
10     use_ok('Moose');           
11 }
12
13 {
14     package Foo;
15     use Moose;
16     
17     eval {
18         has 'foo' => (
19             is => "rw",
20             init_arg => undef,
21         );
22     };
23     ::ok(!$@, '... created the attr okay');
24 }
25
26 {
27     my $foo = Foo->new( foo => "bar" );
28     isa_ok($foo, 'Foo');
29
30     is( $foo->foo, undef, "field is not set via init arg" );
31
32     $foo->foo("blah");
33
34     is( $foo->foo, "blah", "field is set via setter" );
35 }