Moose now warns when you try to load it from the main package. Added a
[gitmo/Moose.git] / t / 020_attributes / 001_attribute_reader_generation.t
CommitLineData
ca01a97b 1#!/usr/bin/perl
2
3use strict;
4use warnings;
5
7ff56534 6use Test::More tests => 13;
ca01a97b 7use Test::Exception;
8
7ff56534 9
ca01a97b 10
11{
12 package Foo;
ca01a97b 13 use Moose;
14
15 eval {
16 has 'foo' => (
17 reader => 'get_foo'
18 );
19 };
20 ::ok(!$@, '... created the reader method okay');
21
22 eval {
23 has 'lazy_foo' => (
24 reader => 'get_lazy_foo',
25 lazy => 1,
26 default => sub { 10 }
27 );
28 };
9e93dd19 29 ::ok(!$@, '... created the lazy reader method okay') or warn $@;
ca01a97b 30}
31
32{
33 my $foo = Foo->new;
34 isa_ok($foo, 'Foo');
35
36 can_ok($foo, 'get_foo');
37 is($foo->get_foo(), undef, '... got an undefined value');
38 dies_ok {
39 $foo->get_foo(100);
40 } '... get_foo is a read-only';
41
42 ok(!exists($foo->{lazy_foo}), '... no value in get_lazy_foo slot');
43
44 can_ok($foo, 'get_lazy_foo');
45 is($foo->get_lazy_foo(), 10, '... got an deferred value');
46 dies_ok {
47 $foo->get_lazy_foo(100);
48 } '... get_lazy_foo is a read-only';
49}
50
51{
52 my $foo = Foo->new(foo => 10, lazy_foo => 100);
53 isa_ok($foo, 'Foo');
54
55 is($foo->get_foo(), 10, '... got the correct value');
56 is($foo->get_lazy_foo(), 100, '... got the correct value');
57}
58
59
60