[Chicago-talk] Object interogation

Jay Strauss me at heyjay.com
Tue Oct 25 20:09:54 PDT 2005


Randal L. Schwartz wrote:
>>>>>>"Jay" == Jay Strauss <me at heyjay.com> writes:
> 
> 
> Jay> Can you do the same with Perl?  I know you can ->can, but that requires 
> Jay> prior knowledge of method names.  I can't think of how you'd get object 
> Jay> attributes.
> 
> Yes.  You can look at the subroutines defined in the package of the
> class.  However, you will not be able to tell which of those are
> "really" methods and which are merely private subroutines.
> 
> sub UNIVERSAL::methods_of_class {
>   my $this = shift;
>   my $class = ref $this || $this;
>   no strict 'refs';
>   grep exists &$_, keys %{ $class . "::" };
> }
> 
> ...
> 
> my @methods = $some_object->methods_of_class;
> my @others = Some::Class->methods_of_class;
> 

thanks Randal.  I was thinking there may be a more core built-in 
facility than having to do it manually for each class.

Thanks
Jay


More information about the Chicago-talk mailing list