Change can() to return a Method object #84

schwern opened this Issue Jan 27, 2010 · 2 comments


None yet
2 participants

schwern commented Jan 27, 2010

Method objects provide more info than just a code ref can provide. It would be nice if can() returned a Method object instead of a bare code ref.

A Method object must be very light and very fast to create.


exodist commented Jan 31, 2010

Can we help performance by changing the return based on what we want? Sometimes people use can() as a check $obj->a if $obj->can( 'a' ); In this case building the object would be a performance loss, light and fast to create is one solution, but looking at it looks like we can tell if boolean context is desired.

So perhaps can should return true/false in boolean context, and only build an object in a context where it makes sense. There are probably other context differences to consider as well.


schwern commented Feb 4, 2010

want() is probably more expensive than making an object.

If all goes well, creating the object should be just bless $code, "Method" and that's hard to beat.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment