7 my @complist = map { "MyApp::$_"; } qw/C::Controller M::Model V::View/;
12 use base qw/Catalyst/;
14 __PACKAGE__->components({ map { ($_, $_) } @complist });
16 # this is so $c->log->warn will work
17 __PACKAGE__->setup_log;
20 is(MyApp->comp('MyApp::V::View'), 'MyApp::V::View', 'Explicit return ok');
22 is(MyApp->comp('C::Controller'), 'MyApp::C::Controller', 'Two-part return ok');
24 is(MyApp->comp('Model'), 'MyApp::M::Model', 'Single part return ok');
26 is_deeply([ MyApp->comp() ], \@complist, 'Empty return ok');
28 # Is this desired behaviour?
29 is_deeply([ MyApp->comp('Foo') ], \@complist, 'Fallthrough return ok');
33 is_deeply( [ MyApp->comp( qr{Model} ) ], [ 'MyApp::M::Model' ], 'regexp ok' );
37 no warnings 'redefine';
38 local *Catalyst::Log::warn = sub { $warnings++ };
40 is_deeply( [ MyApp->comp('::M::Model') ], \@complist, 'no reulsts for regexp fallback');
41 ok( $warnings, 'regexp fallback warnings' );
48 my @expected = sort qw( MyApp::C::Controller MyApp::M::Model );
49 my @got = sort MyApp->comp( qr{::[MC]::} );
50 is_deeply( \@got, \@expected, 'multiple results from regexp ok' );
55 is_deeply( scalar MyApp->comp( qr{DNE} ), 0, 'no results for failed search' );
59 #checking @args passed to ACCEPT_CONTEXT
65 *MyApp::M::Model::ACCEPT_CONTEXT = sub { my ($self, $c, @args) = @_; $args= \@args};
68 my $c = bless {}, 'MyApp';
70 $c->component('MyApp::M::Model', qw/foo bar/);
71 is_deeply($args, [qw/foo bar/], 'args passed to ACCEPT_CONTEXT ok');
73 $c->component('M::Model', qw/foo2 bar2/);
74 is_deeply($args, [qw/foo2 bar2/], 'args passed to ACCEPT_CONTEXT ok');