Re: [Templates] constructing named parameters for subroutines
[prev]
[thread]
[next]
[Date index for 2004/05/17]
On 17 May 2004 07:55:46 -0700
merlyn@xxxxxxxxxx.xxx (Randal L. Schwartz) wrote:
Hi all,
> >>>>> "Matthias" == Matthias Dillier <Matthias.Dillier@xxx.xx> writes:
>
> Matthias> [%
> Matthias> value1=1
> Matthias> value2="xxx"
> Matthias> test = mysubroutine(param1 => value1, param2 => value2)
> Matthias> %]
>
> This is untested, but named parameters are merely passed as a hashref
> as the last element in the list. So, you should be able to simulate
> that example with:
>
> myhash = {};
> myhash.value1 = 1;
> myhash.value2 = "xxx";
> test = mysubroutine(myhash);
>
> with no difference perceptible to the subroutine. If I'm wrong,
> someone will correct me. :)
this works :-)
I had 'named parameters for subroutines' related problem in passing hash
as argument of proxed classes with Template::Plugin::Class (but it's also a
problem with simple subs reference):
[% class.somemethod(param1 => value1, param2 => value2) %]
I currently solved it with:
sub somemethod {
my $self = shift;
my %args = ref($_[0]) eq 'HASH' ? %{$_[0]} : @_;
...
}
Since it isn't always possible to fix thirdy parts methods, a possible
workaround is to call 'class.somemethod' with:
[% class.somemethod('param1','value1','param2','value2') %]
but it doesn't sound too good for me... :-)
My question is: there is a way to pass hashes in order to have them (inside
subs) without dereferencing?
by
- Enrico
_______________________________________________
templates mailing list
templates@xxxxxxxxxxxxxxxx.xxx
http://lists.template-toolkit.org/mailman/listinfo/templates