Greetings,
I'm learning Moose and I'm trying to write a CGI::Application subclass with Moose, which is made difficult by the fact that CGI-App is not based on Moose.
In my other CGI-App subclasses, I like to have a parent class with a setup
method that looks at the child class's symbol table and automatically sets up the runmodes. I figure I can use Moose's metaclass facilities to achieve the same thing in a cleaner way. So here is what I have in my parent class:
use MooseX::Declare;
class MyApp::CGI
extends Moose::Object
extends CGI::Application {
method setup {
$self->start_mode( 'main' );
my @methods = map { $_->name } $self->meta->get_all_methods;
$self->run_modes( map { /^rm_(.+)$/ => $_ }
grep { /^rm_/ }
@methods
);
}
}
...and in my child class:
use MooseX::Declare;
class MyApp::CGI::Login
extends MyApp::CGI {
method rm_main {
return "it works";
}
}
I realized that the reason my runmodes were not getting setup properly is because setup
is called by the CGI-App constructor, and Moose::Object
is sticking its own constructor in my class. I tried to solve this with a method modifier:
around new {
$self = $orig->( @_ );
$self->CGI::Application::new( @_ );
}
This gives me
Can't call method "BUILDARGS" on unblessed reference at ...Moose/Object.pm line 21.
I have a feeling, however, that I'm going about this in completely the wrong way, and Moose has a much better facility for achieving what I want, which I have not as yet discovered.