Commit | Line | Data |
3d041c32 |
1 | # Test that plugins with their own new method don't break applications. |
2 | |
3 | # 5.70 creates all of the request/response structure itself in prepare, |
4 | # and as the new method in our plugin just blesses our args, that works nicely. |
5 | |
6 | # In 5.80, we rely on the new method to appropriately initialise data |
7 | # structures, and therefore we need to inline a new method on MyApp to ensure |
8 | # that plugins don't get it wrong for us. |
9 | |
10 | # Also tests method modifiers and etc in MyApp.pm still work as expected. |
6e5505d4 |
11 | use Test::More tests => 4; |
12 | use Test::Exception; |
edb20ed3 |
13 | |
14 | { |
15 | package NewTestPlugin; |
16 | use strict; |
17 | use warnings; |
18 | sub new { |
19 | my $class = shift; |
20 | return bless $_[0], $class; |
21 | } |
22 | } |
23 | |
24 | { # This is all in the same file so that the setup method on the |
25 | # application is called at runtime, rather than at compile time. |
26 | # This ensures that the end of scope hook has to happen at runtime |
27 | # correctly, otherwise the test will fail (ergo the switch from |
28 | # B::Hooks::EndOfScope to Sub::Uplevel) |
29 | package TestAppPluginWithNewMethod; |
30 | use Test::Exception; |
31 | use Catalyst qw/+NewTestPlugin/; |
32 | |
33 | sub foo : Local { |
34 | my ($self, $c) = @_; |
35 | $c->res->body('foo'); |
36 | } |
37 | |
38 | use Moose; # Just testing method modifiers still work. |
39 | __PACKAGE__->setup; |
40 | our $MODIFIER_FIRED = 0; |
41 | |
42 | lives_ok { |
43 | before 'dispatch' => sub { $MODIFIER_FIRED = 1 } |
44 | } 'Can apply method modifier'; |
45 | no Moose; |
46 | } |
3d041c32 |
47 | |
48 | use FindBin; |
edb20ed3 |
49 | use lib "$FindBin::Bin/lib"; |
3d041c32 |
50 | |
edb20ed3 |
51 | use Catalyst::Test qw/TestAppPluginWithNewMethod/; |
3d041c32 |
52 | ok request('/foo')->is_success; |
53 | is $TestAppPluginWithNewMethod::MODIFIER_FIRED, 1, 'Before modifier was fired correctly.'; |
6e5505d4 |
54 | |
55 | throws_ok { |
56 | package TestAppBadlyImmutable; |
57 | use Catalyst qw/+NewTestPlugin/; |
58 | |
59 | TestAppBadlyImmutable->setup; |
60 | |
61 | __PACKAGE__->meta->make_immutable( inline_constructor => 0 ); |
62 | } |
63 | qr/\QYou made your application class (TestAppBadlyImmutable) immutable/, |
64 | 'An application class that is already immutable but does not inline the constructor dies at ->setup'; |
65 | |