Improv has asked for the wisdom of the Perl Monks concerning the following question:
and recieving code does something like$foo->bar(myarg1 => "myval", myarg2 => "baz");
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)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Force caller to return - reflection
by kyle (Abbot) on Jan 20, 2009 at 03:06 UTC | |
by Improv (Pilgrim) on Jan 20, 2009 at 14:17 UTC | |
|
Re: Force caller to return - reflection
by Corion (Patriarch) on Jan 20, 2009 at 10:53 UTC | |
by Improv (Pilgrim) on Jan 20, 2009 at 14:21 UTC | |
by Corion (Patriarch) on Jan 20, 2009 at 14:26 UTC | |
by Improv (Pilgrim) on Jan 20, 2009 at 14:33 UTC | |
by Prof Vince (Friar) on Jan 24, 2009 at 11:40 UTC | |
|
Re: Force caller to return - reflection
by moritz (Cardinal) on Jan 20, 2009 at 07:09 UTC | |
|
Re: Force caller to return - reflection
by JavaFan (Canon) on Jan 20, 2009 at 10:49 UTC | |
by Improv (Pilgrim) on Jan 20, 2009 at 14:12 UTC |