Raymond Wan <r...@kuicr.kyoto-u.ac.jp> writes:

>>>> if (not $success) {
>>>>   return $m->comp('/BAR', %ARGS);
>>>> }
>> 
>> "return" as shown here does nothing to the output that was already sent by
>> the components called before this one (for example your preamble/headings),
>> and does nothing to prevent the component who called this one from sending
>
> Thank you for your explanation!  I never knew about the difference
> between the two.  Actually, I never knew that "return" could take a URL
> as an argument.

return isn't taking a URL as an argument.  in fact the function's return
value is meaningless, and the real intent is to call $m->comp() and then
immediately return.  this:

        if (not $success) {
           return $m->comp('/BAR', %ARGS);
        }

is shorthand for this:

        if (not $success) {
           $m->comp('/BAR', %ARGS);
           return;
        }

> So, to go to another component or URL, I thought "redirect" was basically
> the only way to do it.  I guess from using other languages, I thought
> return is used alone (i.e., "return;") or with some status code (i.e.,
> "return 1;").

like i said it's shorthand since the return value of this function isn't
used by its caller and it looks better to most of us as a single line even
though it's somewhat misleading (but that's perl for you).

> I guess I need to think what I've done and see if my redirect's should be
> return's...  Thanks again!

you don't need a return, strictly speaking.  you could also just fall off
the end of your function.  so the above example could also be written as:

        if (not $success) {
           $m->comp('/BAR', %ARGS);
        } else {
           ...whatever else you might want to do
        }
     }

but the important part is to call the other component and then DO NAUGHT
ELSE before you yourself return.  there are many ways to achieve that, but
the one that you should use is the one that's plainest as to your intent.
i think it's plainest as it was earliest written in this thread:

        if (not $success) {
           return $m->comp('/BAR', %ARGS);
        }

since it leaves absolutely no doubt in a reviewer's mind that you want to
call the other component and then get the hell out of Dodge, with no
possibility that you will ever insert any other logic or action between
those two events.
-- 
Paul Vixie

------------------------------------------------------------------------------
This SF.net email is sponsored by:
SourcForge Community
SourceForge wants to tell your story.
http://p.sf.net/sfu/sf-spreadtheword
_______________________________________________
Mason-users mailing list
Mason-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mason-users

Reply via email to