I was thinking that I don’t really understand why just about everything in catalyst uses the context object. Seems that just about everything starts with
my ( $self, $c ) = @_;
we wrap DBIC with a catalyst model and end up with
$c->model('DBIC::Table') ...
or maybe we do
$c->log->warn('foo');
but I don’t understand why don’t we just do
log('warn', 'foo'); # or whatever the API for some log library is.
Why do we do everything though the context object? what makes it special?
If I understand what is going on correctly (and I haven’t looked at catalyst very hard, so that is easily possible), The context variable is the calling framework. When a request comes in, the framework builds all of the information into itself and the calls a method in your class passing itself along so your method has access to all of that information and the rest of the framework. You may find that reading about inversion of control (or IoC) helps you understand.
Also, by wrapping up all of the functionality in a context variable, you don’t run into any namespace issues. Controller, model, etc. classes only have to have the methods they declare in their namespace.