Hi,
In a full Mojo app with controllers, I want to have some extra
initialization done with every controller that is instantiated
(checking the session, logging, auditing).
The schoolbook way would be to make an abstract class, I guess:
# MyApp/Ctrlr.pm
Package MyApp::Ctrlr;
use Mojo::Base 'Mojolicious::Controller';
sub new {
my ($class, @args) = @_;
my $self = $class->SUPER::new(@args);
return $self->_init(@args);
}
sub _init { # do the wanted initializations
my ($self, @args) = @_;
# set up session, logging, ....
return $self;
}
# MyApp/Ctrlr/Movies.pm
Package MyApp::Ctrlr::Movies;
use MyApp::Ctrlr;
...
Is this the way to go? Is above code correct? It seems a bit of an
overkill to intruduce an extra class in the hierarchy for just having
an initialization method called on each new controller. Are there more
sophisticated ways to reach the same goal? Can and should I perhaps
use one of Mojo's hooks?
TIA
Henk
--
You received this message because you are subscribed to the Google Groups
"Mojolicious" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.