Let's say we have a module that handles structured argument passing, so that calling code can say
$foo->bar(myarg1 => "myval", myarg2 => "baz");
and recieving code does something like
sub bar { my $self = shift @_; my $args = Argpass::new('strictpolicy', @_); my $argone = $args->accept('myarg1', 'defaultvalue'); my $argtwo = $args->mandate('myarg2'); $args->argok(); # And the function goes on, provided all mandated arguments are passed + in and any arguments that needed type checking passed it successfull +y, anything that needed processing was processed, etc.. # ... # ... }

(fill in a number of additional possibly meaningful and useful ways to automagically pass arguments around, some mandatory, some not, some with defaults, include some typechecking, etc)

This works, and it's been used on some reasonably large projects. It would be useful to add a new 'policy' allowing me to do a kind of reflection - to force the caller, as soon as argument passing is finished (when argok() is called) to return with a structured set of data describing the parameters it takes based on all these accept/mandate/etc methods. Unfortunately, after staring at caller(), goto, etc, I don't see a way to do this.

In short, is there a way, from a subroutine/method to force your caller to return with a value you specify? (let's assume we don't want to complicate the caller with conditionals and have it do the returning)


In reply to Force caller to return - reflection by Improv

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.