>That's not a bug at all. A substitution tag is more or less equivalent to
>calling $m->print(), which in turn works a lot like Perl's built-in print.
>That means it's in list context.
Fine. That answers the question.
print want();
sub want()
{
return wantarray ? "WANT" : "DON'T WANT";
}
>The idea of using the return value of a component in a substitution tag is
>really dubious. As I said before, if the component _only_ returns a value,
>then just make it a subroutine in a module.
And I'll say it again - sometimes it's simpler and easier to do it in
a component. Maybe later, when the backend guys can be persuaded to
fold it into the modules it can be moved there.
It also, as Mark has just pointed out, makes it nice and easy to
override in other component roots.
Components are just perl code. They may not meet your best practice,
but I like it that way. It helps me get things done quicker.
>You seem to expect that a substitution tag should be in void context, but
>that really makes no sense. A subsitution tag basically says "evaluate the
>Perl bits inside the substitution tag and use the _return value_ as
>output". The fact that it expects a return value is what makes it work,
>and that's why it can't be in void context.
OK. Fair enough. My expectation was wrong. Now you've made the point
about print expecting list context, it makes perfect sense. Not a
bug. Just my cluelessness.
>It's not my call? You asked for help on the mailing list and I gave
>advice. You don't have to follow it, but don't get annoyed when someone
>crticizes your design.
I didn't get annoyed. I merely said I don't think that's your call.
Which, you know, it isn't :) You can read as much annoyance into it
as you like. Now if I'd called you a Nazi or not included two gags
about . Of course, I now understand that you would actually like to
make it as near as dammit to mandatory not to return values from
components.
As it happens I ran into this as I was overhauling old code which had
this in it and found this issue as I tried to apply an interim fix
while I transitioned it. Your explanation has helped me decide how
to proceed - thanks.
BTW I am also familiar with the etiquette of lists being the
moderator of one myself (and one considerably larger and busier than
the Mason list ;) where our rule of thumb is shout at the person is
they're off topic, help them with their specific question if it's on
topic even if you don't agree with how they're going about it.
It's not like I asked a modperl or apache question. I wanted to know
why Mason behaved as it did. You have now given me the answer (ie.
that is how Perl works) and I am more than happy with that. As I said
I can now make a sensible decision about how to proceed.
>Massive changes to the docs probably belong as part of the Mason 2.0
>project, which will be out by Christmas.
Fine. Any chance of further reports on what's going on with M2?
>
>> Is wantarray a legitimate perl function (name aside) or not?
>
>That is the name of the Perl built-in, yes.
Right. So it is perfectly valid to use, even in a mason component. As
long as you understand that in a substitution will automatically be
in list context :)
-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Mason-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mason-users