I started writing Perl code using Catalyst, which looked like this:
package My::Controller;
extends 'Catalyst::Controller';
sub handler :Path :Args(0) :Location( some/url )
my ($self, $c) = @_;
$self->do_something_with_arguments($c);
$self->make_a_decision($c);
$self->another_method($c);
}
Then I thought. o O (why switch to $ c all the time?) and I changed this:
package My::Controller;
extends 'Catalyst::Controller';
has c => (is => "rw", isa => "Catalyst");
sub handler :Path :Args(0) :Location( some/url )
my ($self, $c) = @_;
$self->c($c);
$self->do_something_with_arguments;
$self->make_a_decision;
$self->another_method;
}
There is only one entry point for the handler, so $ self-> c will always be set correctly.
My colleagues said that if that was the way Catalyst was intended to be used, then everyone could use it that way. They were worried that running this method would lead to a memory leak, since the link to $ c would remain after the request was completed. It's true?
source
share