I'm dealing with an apparent simple issue.
I'm writing a module similar to UML::Class::Simple but with some improvements. Summarizing, the idea is to retrieve a record card for each module in a given source, containing information about the Methods, Properties, Dependencies and Children. My current problem is getting Methods and Properties for each module. Let's see the code I've already written:
use Class::Inspector;
use Data::Dumper;
sub _load_methods{
my $pkg = shift;
my $methods = Class::Inspector->methods( $pkg, 'expanded' );
print Dumper $methods;
return 1;
}
Calling this function for a given package, I get more methods than I expect. The reason is Class::Inspector returns all inherited methods and also the accessors if the module is a Moose::Object. I would like to filter all of this methods to get just those defined in the given package, not in its parents.
Can anyone provide an elegant way to filter the list of methods in the way I suggest?
Thanks in advance.
If a class is a Moose class, don't inspect it with Class::Inspector. Moose provides its own very extensive introspection API. It can give you lists of methods, attributes, etc.
The documentation for all this is sadly split across a lot of different pages. Moose::Meta::Class is not a bad place to start.
Mouse provides an almost, but not quite identical introspection API.
Moo does not provide an introspection API of its own, but if Moose is loaded will hook into Moose's API, so that you can retrieve information about Moo classes using
Moose::Util::find_meta
.Thanks to @Oesor, who introduced to me the module Data::Printer, which contains a solution for my problem in its source code, and to @tobyink, who give me the key to parse Moose classes, I came up with the following solution: