make all_methods explicitly show all subs/globals/funcs
This commit is contained in:
64
Info/MRO.pm
64
Info/MRO.pm
@@ -125,28 +125,38 @@ either the name of a Perl module, or an object instance of SNMP::Info.
|
|||||||
|
|
||||||
=item all_methods( $module )
|
=item all_methods( $module )
|
||||||
|
|
||||||
Returns the set of methods defined in C<$module> and all its ancestor
|
Returns the location of methods defined in C<$module> and all its ancestor
|
||||||
classes (superclasses), either as Perl subroutines or via C<%GLOBALS>
|
classes (superclasses), either as Perl subroutines or via C<%GLOBALS>
|
||||||
and C<%MUNGE> configuration. The data structure looks like:
|
or C<%FUNCS> configuration. The data structure looks like:
|
||||||
|
|
||||||
{
|
{
|
||||||
method_name => [
|
method_name => {
|
||||||
'Package::Name',
|
subs => [],
|
||||||
'Other::Package::Name',
|
globals => [
|
||||||
],
|
'Package::Name',
|
||||||
|
'Other::Package::Name',
|
||||||
|
],
|
||||||
|
funcs => [],
|
||||||
|
},
|
||||||
other_method_name => [
|
other_method_name => [
|
||||||
'Package::Name',
|
subs => [
|
||||||
|
'Package::Name',
|
||||||
|
],
|
||||||
|
globals => [],
|
||||||
|
funcs => [],
|
||||||
],
|
],
|
||||||
}
|
}
|
||||||
|
|
||||||
If a method has been defined as a Perl subroutine, you'll see the list of
|
It should be noted that the order of method resolution in SNMP::Info is to
|
||||||
classes where this was done, with the package used at runtime being first.
|
first look for a defined subroutine (this is done by Perl), then the
|
||||||
If the method is created via C<%GLOBALS> or C<%MUNGE> then in a similar way
|
AUTOLOAD sequence will search for a definition in C<%GLOBALS> followed by
|
||||||
you'll see the list of modules where this was done. However if a method
|
C<%FUNCS>.
|
||||||
is defined I<both> ways, then only the Perl subroutine definitions are shown.
|
|
||||||
Therefore, the defining class or module at runtime is always:
|
|
||||||
|
|
||||||
$data->{method_name}->[0];
|
The defining class or module at runtime is always the first entry in the
|
||||||
|
list, if it exists:
|
||||||
|
|
||||||
|
$data->{method_name}->{subs}->[0]
|
||||||
|
if scalar @{ $data->{method_name}->{subs} };
|
||||||
|
|
||||||
=cut
|
=cut
|
||||||
|
|
||||||
@@ -155,29 +165,25 @@ sub all_methods {
|
|||||||
my $class = (ref $self ? ref $self : $self);
|
my $class = (ref $self ? ref $self : $self);
|
||||||
|
|
||||||
my $results = subroutines( $class );
|
my $results = subroutines( $class );
|
||||||
$results = { map { $_ => [ $results->{$_}, [], [] ] }
|
$results = { map { $_ => { subs => $results->{$_} } }
|
||||||
keys %$results };
|
keys %$results };
|
||||||
|
|
||||||
my $globals = globals( $class );
|
my $globals = globals( $class );
|
||||||
foreach my $key (keys %$globals) {
|
foreach my $key (keys %$globals) {
|
||||||
my $data = [ map { keys %$_ } @{ $globals->{$key} } ];
|
$results->{$key}->{globals} = [ map { keys %$_ }
|
||||||
if (exists $results->{$key}) {
|
@{ $globals->{$key} } ];
|
||||||
$results->{$key}->[1] = $data;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
$results->{$key} = [ [], $data, [] ];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
my $funcs = funcs( $class );
|
my $funcs = funcs( $class );
|
||||||
foreach my $key (keys %$funcs) {
|
foreach my $key (keys %$funcs) {
|
||||||
my $data = [ map { keys %$_ } @{ $funcs->{$key} } ];
|
$results->{$key}->{funcs} = [ map { keys %$_ }
|
||||||
if (exists $results->{$key}) {
|
@{ $funcs->{$key} } ];
|
||||||
$results->{$key}->[1] = $data;
|
}
|
||||||
}
|
|
||||||
else {
|
foreach my $key (keys %$results) {
|
||||||
$results->{$key} = [ [], [], $data ];
|
$results->{$key}->{subs} ||= [];
|
||||||
}
|
$results->{$key}->{globals} ||= [];
|
||||||
|
$results->{$key}->{funcs} ||= [];
|
||||||
}
|
}
|
||||||
|
|
||||||
return $results;
|
return $results;
|
||||||
|
|||||||
Reference in New Issue
Block a user