in reply to Re: Prototypes and hand-written MMD (Ah! No!!)
in thread Prototypes and hand-written MMD

Sorry about that. I should have posted a link to How does strict determine if something is legally declared? which explains where I get that syntax and what I'm doing. I'm not asking a P6 question in disguise - it really is a P5 question. And, I don't (currently) intend on releasing this code to CPAN - this is just a fun little "Yet Another Perl OO Framework" for my own edification of some squirrelly P5 corners I haven't explored yet. So, to better phrase the question . . .

I have a function defined as so:

sub foo (&) { my ($sub) = @_; ... } # Usage: foo { ... };
I want to also support the following usage: foo 'Bar' is { ... }; which requires a ($$) prototype. (You are correct in that it's $$, not $&.)

Is there a way to do it using the same function name or do I have to use two different functions?


My criteria for good software:
  1. Does it work?
  2. Can someone else come in, make a change, and be reasonably certain no bugs were introduced?

Replies are listed 'Best First'.
Re^3: Prototypes and hand-written MMD (Ah! No!!)
by diotalevi (Canon) on Jan 10, 2006 at 16:49 UTC

    You'd need two different functions. The prototype is to help perl parse your code and perl doesn't provide for conditional prototypes.

    ⠤⠤ ⠙⠊⠕⠞⠁⠇⠑⠧⠊