Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

file 83 lines (63 sloc) 1.891 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
use strict;
use warnings;
use Test::More;
use Test::Exception;

use FindBin;
use lib "$FindBin::Bin/lib";

use TestClass;

dies_ok(sub { TestClass->new });
dies_ok(sub { TestClass->new('moo', 23) });
dies_ok(sub { TestClass->new('moo', 8) });
lives_ok(sub { TestClass->new('moo', 52) });

my $o = TestClass->new('foo');
isa_ok($o, 'TestClass');

is($o->{foo}, 'foo');
is($o->{bar}, 42);

lives_ok(sub { $o->set_bar(23) });
is($o->{bar}, 23);

dies_ok(sub { $o->set_bar('bar') });

{
    my $test_hash = { foo => 1 };
    lives_ok(sub { $o->affe($test_hash) });
    is_deeply($o->{baz}, $test_hash);
}

{
    my $test_array = [qw/a b c/];
    lives_ok(sub { $o->affe($test_array) });
    is_deeply($o->{baz}, $test_array);
}

dies_ok(sub { $o->affe('foo') });

dies_ok(sub { $o->named });
dies_ok(sub { $o->named(optional => 42) });
throws_ok(sub { $o->named }, qr/\b at \b .* \b line \s+ \d+/x, "dies with proper exception");

lives_ok(sub {
    is_deeply(
        [$o->named(required => 23)],
        [undef, 23],
    );
});

lives_ok(sub {
    is_deeply(
        [$o->named(optional => 42, required => 23)],
        [42, 23],
    );
});

dies_ok(sub { $o->combined(1, 2) });
dies_ok(sub { $o->combined(1, required => 2) });

lives_ok(sub {
    is_deeply(
        [$o->combined(1, 2, 3, required => 4, optional => 5)],
        [1, 2, 3, 5, 4],
    );
});

lives_ok(sub { $o->with_coercion({}) });
dies_ok(sub { $o->without_coercion({}) });
lives_ok(sub { $o->named_with_coercion(foo => bless({}, 'MyType')) });
lives_ok(sub { $o->named_with_coercion(foo => {}) });

# MooseX::Meta::Signature::Combined bug? optional positional can't be omitted
#lives_ok(sub { $o->combined(1, 2, required => 3) });
#lives_ok(sub { $o->combined(1, 2, required => 3, optional => 4) });

use MooseX::Method::Signatures;

my $anon = method ($foo, $bar) { };
isa_ok($anon, 'Moose::Meta::Method');

done_testing;
Something went wrong with that request. Please try again.