Allow parameterized roles to be applied as plugins.
[catagits/Catalyst-Runtime.git] / t / lib / PluginTestApp / Controller / Root.pm
CommitLineData
9d04b685 1package PluginTestApp::Controller::Root;
2use Test::More;
3
4use base 'Catalyst::Controller';
5
6#use Catalyst qw(
7# Test::Plugin
8# +TestApp::Plugin::FullyQualified
9# );
10
11__PACKAGE__->config->{namespace} = '';
12
13sub compile_time_plugins : Local {
14 my ( $self, $c ) = @_;
15
16 isa_ok $c, 'Catalyst::Plugin::Test::Plugin';
17 isa_ok $c, 'TestApp::Plugin::FullyQualified';
18
19 can_ok $c, 'registered_plugins';
20 $c->_test_plugins;
21
22 $c->res->body("ok");
23}
24
25sub run_time_plugins : Local {
26 my ( $self, $c ) = @_;
27
28 $c->_test_plugins;
29 my $faux_plugin = 'Faux::Plugin';
30
31# Trick perl into thinking the plugin is already loaded
32 $INC{'Faux/Plugin.pm'} = 1;
33
b3986722 34 ref($c)->plugin( faux => $faux_plugin );
9d04b685 35
36 isa_ok $c, 'Catalyst::Plugin::Test::Plugin';
62b6b631 37
38 # applied parameterized role
39 if (eval { require MooseX::Role::Parameterized; 1 }) {
40 can_ok $c, 'affe';
41 is $c->affe, 'birne', 'right method created by parameterized role';
42 }
43
9d04b685 44 isa_ok $c, 'TestApp::Plugin::FullyQualified';
45 ok !$c->isa($faux_plugin),
46 '... and it should not inherit from the instant plugin';
47 can_ok $c, 'faux';
48 is $c->faux->count, 1, '... and it should behave correctly';
49 is_deeply [ $c->registered_plugins ],
50 [
51 qw/Catalyst::Plugin::Test::Plugin
52 Faux::Plugin
53 TestApp::Plugin::FullyQualified/
54 ],
55 'registered_plugins() should report all plugins';
56 ok $c->registered_plugins('Faux::Plugin'),
57 '... and even the specific instant plugin';
58
59 $c->res->body("ok");
60}
61
621;