develooper Front page | perl.perl5.porters | Postings from August 2001

RE: marking can() coderef as a method

Thread Previous | Thread Next
Geoffrey Young
August 24, 2001 05:06
RE: marking can() coderef as a method
Message ID:

> On Thu, Aug 23, 2001 at 01:51:56PM -0400, Geoffrey Young wrote:
> > hi all...
> > 
> >   I thought it might be genuinely useful to mark a coderef 
> returned by
> > UNIVERSAL::can() as being a method so that XS routines can 
> know whether to
> > use perl_call_method or perl_call_sv on it.  
>     use Text::Soundex;
>     my $func = UNIVERSAL::can('Text::Soundex', 'soundex');
>     print $func->("I assure you, this is not a method");
> even if called like this:
>     my $func = Text::Soundex->can('soundex');
> it's still not a method.

true. ok, so polluting can() isn't the proper approach...

still, is there no way to capture a coderef that knows it is to be called
using a method syntax?

maybe it's not a generally useful thing to have, but I wrote some XS that
illustrates what I was after

  cv = sv_2cv(sv, &stash, &gv, FALSE);
  if (cv && (CvFLAGS(cv) & CVf_METHOD)) {
    perl_call_sv(sv, G_METHOD);

if the incoming sv is a coderef and is marked as a method then I have
everything I need to make the call properly.  this example only works for
class methods (and probably goofs up refcounts or something since I'm new to
this), but it probably isn't too hard to make a similar version for object
methods as well (I didn't try)...

I guess I was interested in this on intellectual level -  as I gather from
your later responses, this probably isn't something for perl5, which is

at any rate, thanks for putting up with my thoughts - I appreciate it.


Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About