--- /dev/null
+package DynamicAppDemo::Controller::FakeExample;
+use Moose;
+use namespace::clean -except => 'meta'; # N.B. namespace clean cest tres important
+ # as this package is introspected, a lot!
+
+BEGIN { extends 'DynamicAppDemo::ControllerBase' }
+
+# This is a fake controller.
+
+# It exists to show an example of using ::ControllerBase which is autogenerated,
+# which helps me seperate the building and testing of the controller action
+# registration functionality, seperate the the code generation :)
+
+sub register_me {
+ my ($self, $c) = @_;
+ $c->res->body('quux');
+ $c->res->header('X-Foo', 'bar');
+}
+
+sub _do_not_register_me { }
+
+# In a non-trivial example, you would use MX::Method::Sigs :)
+
+__PACKAGE__->meta->make_immutable;
+
package DynamicAppDemo::ControllerBase;
use Moose;
+use Moose::Util qw/find_meta/;
use namespace::clean -except => 'meta';
# Should not need attributes here, but what the hell..
BEGIN { extends 'Catalyst::Controller' }
+around get_action_methods => sub {
+ my $orig = shift;
+ my $self = shift;
+
+ my $meta = find_meta($self);
+
+ # FIXME - fugly, and nasty
+ return (
+ ( map {
+ my $m = $meta->get_method($_);
+ # EPIC CHEAT to just smash the attribute definition :)
+ $m->meta->get_attribute('attributes')->set_value($m, ['Local']);
+ $m;
+ }
+ grep { ! /^(_|new|meta)/ }
+ $meta->get_method_list
+ ),
+ (
+ $self->$orig(@_)
+ )
+ );
+};
+
__PACKAGE__->meta->make_immutable;
use strict;
use warnings;
-use Test::More tests => 2;
+use Test::More tests => 3;
BEGIN { use_ok 'Catalyst::Test', 'DynamicAppDemo' }
-ok( request('/')->is_success, 'Request should succeed' );
+{
+ my $res = request('/fakeexample/register_me');
+ ok( $res->is_success, 'should succeed' );
+ is( $res->header('X-Foo'), 'bar', 'is calling correct code' );
+}
+