On Wed, 23 May 2001, Andy Wardley wrote:
> On Wed, May 23, 2001 at 02:30:40PM +0800, Stas Bekman wrote:
> > depending on that feature. Not having this context makes all the functions
> > that use wantarray() half usable and unintuitive. Of course your patch
> > provides this feature, but are there any reasons for not having these in
> > core?
>
> None that I can think of.
I'm not sure whether I've asked you before this question, but why did you
go away from $,%,@ in first place? If I may ask?
> To do the job properly will require some hacking on the stash to either
> set flags to denote the context in which a variable should be evaluated,
> or provide different methods, get(...), get_list(...). It probably
> wouldn't be too hard to hack the parser grammar to accept an optional
> '@' as a prefix on a variable name and generate the appropriate Perl
> code to fetch the variable from the stash using the get_list() method,
> or by setting a LIST_CONTEXT flag, instead of the default scalar context
> method.
Well anything you prefer, is fine with me. I'm in need for functionality
and willing to use any technique that is a core part of TT and documented.
Unfortunately I was forced already today to apply kind Craig's "patch",
because two of our programmers very banging their heads on the wall,
trying various work arounds for this problem. They very very greatful to
have Craig's path! Thanks Craig. So if this syntax sticks in that would be
cool :)
> But until then, I'm happy to apply this functionality to the core.
Thanks!
I'm only worried about this part of Craig's patch:
$Template::Stash::LIST_OPS = {
'scalar' => sub { ref $_[0] eq "ARRAY" ? $_[0][0] : $_[0] },
'array' => sub { ref $_[0] eq "ARRAY" ? $_[0] : [$_[0]] },
};
I don't think that poping the first list's element for list.scalar is the
intuitive thing to do. 'scalar @list' (== list.scalar) should be the same
as list.size and in case of function func.scalar it should let the
function know that the context it scalar so wantarray() will do the right
thing, but this seems to be not impossible to do with the suggested patch,
since the alteration of the data structure happens after the function was
called in the list context (always).
In any case, I'm happy to have a solution for our particular problem
which func.array solves.
Thanks again!
_____________________________________________________________________
Stas Bekman JAm_pH -- Just Another mod_perl Hacker
http://stason.org/ mod_perl Guide http://perl.apache.org/guide
mailto:[EMAIL PROTECTED] http://apachetoday.com http://eXtropia.com/
http://singlesheaven.com http://perl.apache.org http://perlmonth.com/