Hi,
I am learning Moose , and I am trying to write a CGI :: Application with Moose, which is complicated by the fact that the CGI application is not based on Moose.
In my other subclasses of the CGI-App, I like to have a parent class with the setup method that looks at the character table of the child class and sets runmodes automatically. I believe I can use Moose metaclasses to achieve the same element 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 werenβt configured correctly is because the CGI-App constructor is called setup , and Moose::Object sticks to its own constructor in my class. I tried to solve this problem using the method modifier:
around new { $self = $orig->( @_ ); $self->CGI::Application::new( @_ ); }
It gives me
Can't call method "BUILDARGS" on unblessed reference at ...Moose/Object.pm line 21.
I have a feeling, however, that I am doing it completely wrong, and Musa has a much better way to achieve what I want, which I have not yet discovered.
oop perl moose mop
friedo
source share