|
From: Chris W. <ch...@cw...> - 2002-08-22 11:21:48
|
On Thu, 2002-08-22 at 00:03, Chris McDaniel wrote:
> Maybe I'm just revealing my own ignorance here, but can anyone tell me about
> what is in $class and $p?
>
> as in:
> sub handler {
> my $class = shift;
> my $p = shift;
> my $R = OpenInteract::Request->instance;
> ...
> }
>
> Thanks, and sorry if this is a dumb question.
It's not. If I picked a more descriptive variable name it might be
easier :-)
Second item first: $p is a hashref of parameters. What is in there
depends on how things are setup. If you use 'GenericHandler' as a parent
(described below), you'll have some security settings in there.
Otherwise, it depends on how you're called. Handlers dealing with a
single object frequently look there first to find the object and/or ID
to act on, like:
my $news = $p->{news};
unless ( $news ) {
my $news_id = $p->{news_id} || $R->apache->param( 'news_id' );
$news = ( $news_id ) ? $R->news->fetch( $news_id )
: $R->news->new();
}
$class is the class of your handler. All handler methods are class
methods, so the class is always the first argument. This is useful for
inheritance -- many times you may want a top-level 'handler' method to
deal with some generic setup stuff but generate the content from a
specific class. So in OI you might have:
URL: /News/show/
Action: 'news' => { class => 'MySite::Handler::News' }
OpenInteract::Handler::GenericHandler
| - defines 'handler'
|
|---MySite::Handler::News
- defines 'show'
OI will call
MySite::Handler::News->handler(...)
which will call the inherited method from 'GenericHandler'. This checks
security, finds the task from the URL, etc. It then calls the content
method 'show' which is defined in your handler and which does the actual
work.
Hope that makes sense!
Chris
--
Chris Winters (ch...@cw...)
Building enterprise-capable snack solutions since 1988.
|