I strongly advice against using the same subs for different APIs.*

If you really want to go with this strange requirement - what is $self supposed to be in non method calls (?) - you can use a different namespaces to mirror the function/methods.

# UNTESTED package functional_Util; my $default_self= "something"; sub utility { unshift $default_self, @_; goto &methodlike_Util::utility; } package methodlike_Util; sub utility { my $self =shift; # ... do it }

Of course you are free to use it the other way round if $self doesn't matter.

Please note that Perl is flexible enough to autogenerate the needed "mirrors", either/or per

It's a trade: You are gaining large runtime performance and a clean interface for adding little compile-time complexity.

But again I doubt the requirements are well thought off, sounds like a political compromise inside a big team meeting where everyone wants his own private menu in a restaurant just to prove he knows cooking.

Cheers Rolf
(addicted to the Perl Programming Language and ☆☆☆☆ :)
Je suis Charlie!

update

*) since checking the arguments is complicated, error prone and slow, see other replies.


In reply to Re: Perl OOO Function Entrance by LanX
in thread Perl OOP Function Entrance by Mano_Man

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.