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. |
edb20ed3 |
11 | use Test::More tests => 3; |
12 | |
13 | { |
14 | package NewTestPlugin; |
15 | use strict; |
16 | use warnings; |
17 | sub new { |
18 | my $class = shift; |
19 | return bless $_[0], $class; |
20 | } |
21 | } |
22 | |
23 | { # This is all in the same file so that the setup method on the |
24 | # application is called at runtime, rather than at compile time. |
25 | # This ensures that the end of scope hook has to happen at runtime |
26 | # correctly, otherwise the test will fail (ergo the switch from |
27 | # B::Hooks::EndOfScope to Sub::Uplevel) |
28 | package TestAppPluginWithNewMethod; |
29 | use Test::Exception; |
30 | use Catalyst qw/+NewTestPlugin/; |
31 | |
32 | sub foo : Local { |
33 | my ($self, $c) = @_; |
34 | $c->res->body('foo'); |
35 | } |
36 | |
37 | use Moose; # Just testing method modifiers still work. |
38 | __PACKAGE__->setup; |
39 | our $MODIFIER_FIRED = 0; |
40 | |
41 | lives_ok { |
42 | before 'dispatch' => sub { $MODIFIER_FIRED = 1 } |
43 | } 'Can apply method modifier'; |
44 | no Moose; |
45 | } |
3d041c32 |
46 | |
47 | use FindBin; |
edb20ed3 |
48 | use lib "$FindBin::Bin/lib"; |
3d041c32 |
49 | |
edb20ed3 |
50 | use Catalyst::Test qw/TestAppPluginWithNewMethod/; |
3d041c32 |
51 | ok request('/foo')->is_success; |
52 | is $TestAppPluginWithNewMethod::MODIFIER_FIRED, 1, 'Before modifier was fired correctly.'; |