Bloodnok has asked for the wisdom of the Perl Monks concerning the following question:

Whilst developing a bespoke module to determine the provenance of a class method (local or inherited), this (simplified) test harness code ...
package simple_obj; use Class::Flyweight::Lite::Core qw/attrib/; sub add_attrib { my $self = shift } } sub get_addr { \&add_attrib } package main; use warnings; use strict; use Test::More; diag 'simple_obj->get_addr(): ' . simple_obj->get_addr(); diag 'simple_obj->can(qw/get_addr/): ' . simple_obj->can(qw/get_addr/) +; diag '\&simple_obj::get_addr: ' . \&simple_obj::get_addr;
generates the following unexpected results:
. . # simple_obj->get_addr(): CODE(0x8e9da2c) # simple_obj->can(qw/get_addr/): CODE(0x8ff8bd8) # \&simple_obj::get_addr: CODE(0x8ff8bd8) . .
I say unexpected because, since the same sub is the subject of the various operations, my expectation was that the returned address/ref. should be the same in all cases - but it self-evidently isn't.

So, is it me and my understanding of the perldoc for UNIVERSAL - specifically '...returns a reference to the sub.' ?

By way of an in-situ update, I've now found Class::Inspector - which does everything I wanted my module to do ... thanx be to CPAN - for all the joy, wonders & labour saving :-)

UPDATE: Thanx to dsheroh for pointing out the problem that was so obvious to all but me in Re: How can the same sub have 2 different references.

A user level that continues to overstate my experience :-))

Replies are listed 'Best First'.
Re: How can the same sub have 2 different references
by dsheroh (Monsignor) on Feb 20, 2014 at 09:18 UTC
    diag 'simple_obj->get_addr():        ' . simple_obj->get_addr();

    This one calls get_addr and prints its return value, which is a reference to add_attrib, not a reference to get_addr. The other two print references to get_addr without calling it.