[Maypole] listing Maypole actions in a template

From: Dave Howorth (Dave.Howorth at acm.org)
Date: Mon Jan 03 2005 - 18:27:05 GMT


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

-- 
No virus found in this outgoing message.
Checked by AVG Anti-Virus.
Version: 7.0.298 / Virus Database: 265.6.7 - Release Date: 30/12/04

_______________________________________________ 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