I have an experiment for this here:
It's not trying to rebless currently. Instead, it simply calls the controller action as a method rather than as a subroutine.
The drawback vs. reblessing is now you need to keep track of the controller class vs. the app class.
I moved the dispatch logic into the Routes class. I know that might be a separation-of-concerns issue but I noted that Routes was already loading the controller classes, so it's already tightly coupled in that respect.
If you look at this version of Kelp, it simply finds the matching routes and iterates over them, calling dispatch() on each one.
I added a setting to Kelp::Routes, use_method_dispatch(). If false (default), it calls all actions as subroutines, like normal.
If true, it calls them as methods.
So basically, all that's different is that with use_method_dispatch disabled, the controller action signature is:
MyApp::MyController;
sub action {
my $app = shift;
...
}
whereas with it enabled, that becomes:
MyApp::MyController;
sub action;
my $class = shift;
my $app = shift;
...
}
I'm a little ambivalent about it. I like the fact that controllers can now inherit logic, but it seems like a bit of a pain to differentiate between the controller class and the app class, and now there's another flag to manage.
Looking at Rails, it appears that they instantiate the specific controller directly.