Skip to content

Instantly share code, notes, and snippets.

@jhthorsen
Created December 22, 2021 08:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jhthorsen/fb2d339c0bf4933974c3433e7a0ec0a0 to your computer and use it in GitHub Desktop.
Save jhthorsen/fb2d339c0bf4933974c3433e7a0ec0a0 to your computer and use it in GitHub Desktop.
Used to get package information recursive
sub traverse_packages {
my ($name, $depth) = @_;
my $pkg = do { no strict qw(refs); \%{"$name\::"}; };
for my $key (sort keys %$pkg) {
printf "%s%s::%s\n", ' ' x ($depth * 2), $name, $key;
traverse_packages("$name\::$1", $depth + 1) if $key =~ m!^(\w+)::$!;
}
}
traverse_packages('Foo', 0);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment