--- Dave Howorth <Dave.Howorth at acm.org> wrote:
> I needed to get a list of the available actions for a class to put into
> a template. In case that's of use to anyone else, here's what I did.
>
> First, I wrote a function to identify all the actions in a model class:
>
> sub actions
> {
> my ($model_class_name) = @_;
> use Class::Inspector;
> my @actions;
> for my $method (@{Class::Inspector->methods($model_class_name)}) {
> push @actions, $method if $model_class_name->is_public($method);
> }
>
> return \@actions;
> }
>
> I put it in my driver class and added this line to my additional_data()
> function:
>
> $r->template_args->{actions} = \&actions;
>
> Now in my templates I can say:
>
> [% list_of_actions = actions("BeerDB::Brewery") %]
>
> which suits my use case. An alternative would be to make the function be
> a method of the base model class and change its first line to extract
> the class of its invoker. Then you could invoke it as an object method
> in the template.
>
> Cheers, Dave
>
This is cool Dave. It got me thinking Maybe a Maypole::Plugin::Menu would be
feasible. Also a simple menu template should ship with Maypole. It would be
great for just starting with Maypole and throughout production to have links to
all possible actions handy. I probably shouldn't admit this but I debugged for
a half hour once before i realized I hadn't "Exported" my action.
A simple menu template would just take your action sub and make html links out
of em. Maybe have a sub, "action_names" in the model equivalent to column_names
but for methods.
A more complex system could be put in a Maypole::Plugin::Menu . It be cool to
have:
-- A way to distinguish object actions and class actions.
-- A way for model to customize and add additional actions from other model
classes to their menus
-- A "action_names" sub to specify what to call these
-- Maybe different menu headings.
thanks.
=====
pjs
__________________________________
Do you Yahoo!?
Yahoo! Mail - Easier than ever with enhanced search. Learn more.
http://info.mail.yahoo.com/mail_250
_______________________________________________
maypole mailing list
maypole at lists.netthink.co.uk
http://lists.netthink.co.uk/listinfo/maypole
This archive was generated by hypermail 2.1.3 : Thu Feb 24 2005 - 22:25:57 GMT