Benchmark-DKbench

 view release on metacpan or  search on metacpan

data/t/attributes/attribute_reader_generation.t  view on Meta::CPAN

use strict;
use warnings;

use Test::More;
use Test::Fatal;


{
    package Foo;
    use Moose;

    eval {
        has 'foo' => (
            reader => 'get_foo'
        );
    };
    ::ok(!$@, '... created the reader method okay');

    eval {
        has 'lazy_foo' => (
            reader => 'get_lazy_foo',
            lazy => 1,
            default => sub { 10 }
        );
    };
    ::ok(!$@, '... created the lazy reader method okay') or warn $@;

    eval {
        has 'lazy_weak_foo' => (
            reader => 'get_lazy_weak_foo',
            lazy => 1,
            default => sub { our $AREF = [] },
            weak_ref => 1,
        );
    };
    ::ok(!$@, '... created the lazy weak reader method okay') or warn $@;

    my $warn;

    eval {
        local $SIG{__WARN__} = sub { $warn = $_[0] };
        has 'mtfnpy' => (
            reder => 'get_mftnpy'
        );
    };
    ::ok($warn, '... got a warning for mispelled attribute argument');
}

{
    my $foo = Foo->new;
    isa_ok($foo, 'Foo');

    can_ok($foo, 'get_foo');
    is($foo->get_foo(), undef, '... got an undefined value');
    isnt( exception {
        $foo->get_foo(100);
    }, undef, '... get_foo is a read-only' );

    ok(!exists($foo->{lazy_foo}), '... no value in get_lazy_foo slot');

    can_ok($foo, 'get_lazy_foo');
    is($foo->get_lazy_foo(), 10, '... got an deferred value');
    isnt( exception {
        $foo->get_lazy_foo(100);
    }, undef, '... get_lazy_foo is a read-only' );



( run in 1.520 second using v1.01-cache-2.11-cpan-54e63673c56 )