[Maypole] Using additional_data on a page not related to a table
Jason Kohles
email@jasonkohles.com
Tue, 6 Jul 2004 00:27:50 -0400
Greetings,
I'm in the process of developing my first real application with Maypole,
and have run into a problem. I'm not sure if this is my
misunderstanding the way it should work, or if the way it is working is
as screwy as I think it is :), so any suggestions would be appreciated.
It all started with wanting to display some an overview of several
tables as they relate to the person who is currently logged in. I
started by trying to use additional_data to put some information into
the template_args. My additional_data sub looks like this:
sub additional_data {
my $r = shift;
$r->{template_args}{my} = $r->{user};
$r->{template_args}{login} = $ENV{REMOTE_USER};
}
I then added to my frontpage template:
<h3>Login: [% login %]</h3>
However, the login is always blank. I tracked down where it was getting
lost and found this:
* Maypole::handler contains this snippet:
my $status = $r->handler_guts();
return $status unless $status == OK;
* Maypole::handler_guts calls is_applicable() and then bases its
decision on what to do next based on the return from is_applicable.
Only one of the two possible branches based on this return calls
additional_data, however, if is_applicable does not return OK, then
it runs some code that is commented with "it's just a plain template"
* is_applicable sets up some defaults in the event that ok_tables is
not populated, and then has this line of code:
return DECLINED() unless exists $config->{ok_tables}{$self->{table}};
When is_applicable gets called during the processing of the frontpage
template, $self->{table} is set to 'frontpage', therefore is_applicable
returns false, and additional_data() is never run.
So the question is, is there a reason that additional_data() doesn't run
for plain templates? Or is there some other way to accomplish what I'm
trying here?
This is the patch I applied to get it working, so far I haven't seen any
strange side effects from this, but should I expect to find any?
*** Maypole.pm.orig Tue Jul 6 00:29:28 2004
--- Maypole.pm Tue Jul 6 00:29:45 2004
***************
*** 79,84 ****
--- 79,85 ----
delete $r->{model_class};
$r->{path} =~ s{/}{}; # De-absolutify
$r->template($r->{path});
+ $r->additional_data();
}
if (!$r->{output}) { # You might want to do it yourself
return $r->view_object->process($r);
--
Jason Kohles A witty saying proves nothing.
email@jasonkohles.com -- Voltaire (1694 - 1778)
http://www.jasonkohles.com/