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