in reply to Re^3: How to de-reference a coderef?
in thread How to de-reference a coderef?
I can tell you're already happy with the solution you've got, but I'd like to recommend a few alternates anyway. :-)
I think you're losing a lot of flexibility by requiring the passed in coderef to be a named sub in the same namespace. Any time you're passing around coderefs, anonymous subs become more and more useful. To this end, I can think of a few ways to allow them:
foobar(Code::Wrapper->new( code => \&foo )); foobar(Code::Wrapper->new( code => sub { "baz" }, label => "baz" ) +)
Then this object could encapsulate the behavior mentioned earlier, by either searching the symbol table or using the specified label.
Which one you choose depends on how much flexibility you want in the future, and how much you want to insulate certain parts of your code from others. I have a feeling you will just go with the symbol table scan, but hopefully you'll at least give my ideas some consideration.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
•Re^5: How to de-reference a coderef?
by merlyn (Sage) on Dec 09, 2004 at 18:02 UTC | |
by Anonymous Monk on Dec 09, 2004 at 20:50 UTC | |
by merlyn (Sage) on Dec 10, 2004 at 00:06 UTC |