14 has foo => ( is => "ro" );
18 metaclass => "Moose::Meta::Class",
19 error_class => "Moose::Error::Croak",
23 has foo => ( is => "ro" );
28 extends 'Moose::Object', 'Moose::Error::Default';
30 has message => ( isa => "Str", is => "ro" );
31 has attr => ( isa => "Moose::Meta::Attribute", is => "ro" );
32 has method => ( isa => "Moose::Meta::Method", is => "ro" );
33 has metaclass => ( isa => "Moose::Meta::Class", is => "ro" );
34 has data => ( is => "ro" );
35 has line => ( isa => "Int", is => "ro" );
36 has file => ( isa => "Str", is => "ro" );
37 has last_error => ( isa => "Any", is => "ro" );
42 metaclass => "Moose::Meta::Class",
43 error_class => "Baz::Error",
47 has foo => ( is => "ro" );
51 sub blah { $line = __LINE__; shift->foo(4) }
58 ok( my $e = $@, "got some error" );
67 my $e = create_error( Foo->new );
68 ok( !ref( $e->{error} ), "error is a string" );
69 like( $e->{error}, qr/line $e->{line}\n.*\n/s, "confess" );
73 my $e = create_error( Bar->new );
74 ok( !ref( $e->{error} ), "error is a string" );
75 like( $e->{error}, qr/line $e->{line}$/s, "croak" );
79 my $e = create_error( my $baz = Baz->new );
80 isa_ok( $e->{error}, "Baz::Error" );
81 unlike( $e->{error}->message, qr/line $e->{line}/s,
82 "no line info, just a message" );
83 isa_ok( $e->{error}->metaclass, "Moose::Meta::Class", "metaclass" );
84 is( $e->{error}->metaclass, Baz->meta, "metaclass value" );
85 isa_ok( $e->{error}->attr, "Moose::Meta::Attribute", "attr" );
86 is( $e->{error}->attr, Baz->meta->get_attribute("foo"), "attr value" );
87 isa_ok( $e->{error}->method, "Moose::Meta::Method", "method" );
88 is( $e->{error}->method, Baz->meta->get_method("foo"), "method value" );
89 is( $e->{error}->line, $e->{line}, "line attr" );
90 is( $e->{error}->file, $e->{file}, "file attr" );
91 is_deeply( $e->{error}->data, [ $baz, 4 ], "captured args" );
92 like( $e->{error}->last_error, qr/Blah/, "last error preserved" );
108 Moose::Util::MetaRole::apply_metaroles(
110 class_metaroles => { class => ['Role::Foo'] },
115 package Baz::Sub::Sub;
117 metaclass => 'Moose::Meta::Class',
118 error_class => 'Moose::Error::Croak',
122 ::dies_ok { extends 'Baz::Sub' } 'error_class is included in metaclass compatibility checks';
129 metaclass => 'Moose::Meta::Class',
130 error_class => 'Moose::Error::Croak',
135 Moose::Util::MetaRole::apply_metaroles(
137 class_metaroles => { class => ['Role::Foo'] },
141 ok( Foo::Sub->meta->error_class->isa('Moose::Error::Croak'),
142 q{Foo::Sub's error_class still isa Moose::Error::Croak} );
145 package Foo::Sub::Sub;
148 ::lives_ok { extends 'Foo::Sub' } 'error_class differs by role so incompat is handled';
150 Moose::Util::MetaRole::apply_metaroles(
152 class_metaroles => { error => ['Role::Foo'] },
156 ok( Foo::Sub::Sub->meta->error_class->meta->does_role('Role::Foo'),
157 q{Foo::Sub::Sub's error_class does Role::Foo} );
158 ok( Foo::Sub::Sub->meta->error_class->isa('Moose::Error::Croak'),
159 q{Foo::Sub::Sub's error_class now subclasses Moose::Error::Croak} );