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

RE: marking can() coderef as a method

Thread Previous | Thread Next
From:
Geoffrey Young
Date:
August 23, 2001 11:29
Subject:
RE: marking can() coderef as a method
Message ID:
A14A9ADE3BEAD311AF95009027B6FBE0011E2133@corpex.laserlink.net


> -----Original Message-----
> From: Arthur Bergman [mailto:arthur@contiller.se]
> Sent: Thursday, August 23, 2001 2:24 PM
> To: Geoffrey Young; perl5-porters@perl.org
> Subject: SV: marking can() coderef as a method
> 
> 
> 
> 
> > 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.  
> > 
> >   please forgive me if I misunderstand the purpose of 
> CvMETHOD_on - I
> > scoured the archives but could only find a smattering of 
> information and I'm
> > probably a bit out of my league here anyway... 
> > 
> > --Geoff
> > 
> > this patch is against the current bleedperl available from 
> rsync - a clean
> > build passes all tests on my system.
> 
> This seems logical but unnecessary.
> 
> When you have a coderef, why not just call perl_call_sv and 
> push the object as the first argument. Since can already 
> found the correct method, we don't need to search again using 
> call_method.

well, I'm neither an XS nor perlguts expert (actually I claim no knowledge
whatsoever ;)  but here was my (rather specific) problem.  

mod_perl has a method that accepts either a literal or a coderef.  If it
sees a literal it converts it into either class->method or class::method()
my searching for '->'.  if it gets passed a coderef, it just passes the
coderef perl_call_sv.

after thinking about it some, I said to myself "oh, you can't determine from
just a coderef whether it needs -> or not."  then a few months later I saw
the CvMETHOD_on macro somewhere and thought this might be the way.

> 
> I also wonder why you want to know it is a method, you cannot 
> call it unless you have an object connected to it, and then 
> you already know it is a method.

that may be.  as I said, this isn't my area, but with the patch I was able
to get mod_perl to behave the way I wanted with a minimum of effort.  Doug
or someone similarly qualified might say phooey and know of a better way.  I
didn't.

I'm not trying to introduce something to core just to meet my whims - I
thought it might have a broader applications than I could dream up is all.
which is why I posed the question to the people who know :)

--Geoff

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About