Skip to content

Instantly share code, notes, and snippets.

@softmoth
Created August 14, 2012 17:02
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 softmoth/3350872 to your computer and use it in GitHub Desktop.
Save softmoth/3350872 to your computer and use it in GitHub Desktop.
Somewhat improved pod-dump
#! /usr/bin/env perl6
# vim:set ft=perl6:
sub print-pod(Pod::Block $pod, $level = 0) {
my $leading = ' ' x $level;
my %confs;
for <config name level caption type headers> {
my $thing = $pod.?"$_"();
if $thing {
%confs{$_} = $thing ~~ Iterable ?? $thing.perl !! $thing.Str;
}
}
note $leading, $pod.^name, (%confs.perl if %confs);
for $pod.content.list {
when Pod::Block {
print-pod($_, $level + 2);
}
when Array {
note $leading, 'ARRAY [';
for @$_ {
note $leading, " '$_',";
}
note $leading, ']';
}
when Str {
note $_.indent($level + 2);
}
default {
note $leading, 'UNKNOWN {{{', $_.perl, '}}}';
}
}
}
sub MAIN($pod-file) {
my $pod = eval slurp($pod-file) ~ "\n\$=pod";
print-pod($_) for @$pod;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment