1 # Test that plugins with their own new method don't break applications.
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.
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.
10 # Also tests method modifiers and etc in MyApp.pm still work as expected.
11 use Test::More tests => 4;
15 package NewTestPlugin;
20 return bless $_[0], $class;
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;
31 use Catalyst qw/+NewTestPlugin/;
38 use Moose; # Just testing method modifiers still work.
40 our $MODIFIER_FIRED = 0;
43 before 'dispatch' => sub { $MODIFIER_FIRED = 1 }
44 } 'Can apply method modifier';
49 use lib "$FindBin::Bin/lib";
51 use Catalyst::Test qw/TestAppPluginWithNewMethod/;
52 ok request('/foo')->is_success;
53 is $TestAppPluginWithNewMethod::MODIFIER_FIRED, 1, 'Before modifier was fired correctly.';
56 package TestAppBadlyImmutable;
57 use Catalyst qw/+NewTestPlugin/;
59 TestAppBadlyImmutable->setup;
61 __PACKAGE__->meta->make_immutable( inline_constructor => 0 );
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';