1use strict;
2use warnings;
3
4use Test::More;
5use Test::Fatal;
6
7use Moose();
8
9{
10    {
11        package Foo;
12        use Moose;
13
14        has 'foo' => (
15            is      => 'ro',
16            isa     => 'ArrayRef',
17            traits  => ['Array'],
18            handles => {
19                grep => 'grep'
20            },
21            required => 1
22        );
23    }
24
25    my $foo_obj = Foo->new( foo => [1, 2, 3] );
26    my $arg = [12];
27
28    my $exception = exception {
29        $foo_obj->grep( $arg );
30    };
31
32    like(
33        $exception,
34        qr/The argument passed to grep must be a code reference/,
35        "an ArrayRef passed to grep");
36
37    isa_ok(
38        $exception,
39        'Moose::Exception::InvalidArgumentToMethod',
40        "an ArrayRef passed to grep");
41
42    is(
43        $exception->method_name,
44        "grep",
45        "an ArrayRef passed to grep");
46
47    is(
48        $exception->argument,
49        $arg,
50        "an ArrayRef passed to grep");
51
52    is(
53        $exception->type_of_argument,
54        "code reference",
55        "an ArrayRef passed to grep");
56
57    is(
58        $exception->type,
59        "CodeRef",
60        "an ArrayRef passed to grep");
61}
62
63done_testing;
64