The $=pod
variable contains an Array
of values that are each an instance of (a sub-class of) Pod::Block
. So you need to reproduce that.
Letting the Rakudo compiler do all the work
If you compile some P6 code with a P6 compiler then any Pod in it is supposed to be automatically compiled, and the $=pod
variable automatically initialized to contain the results of the Pod compilation. Using Rakudo:
=begin foo
foo-text
=end foo
say $=pod;
displays:
[Pod::Block::Named{:name("foo")}
Pod::Block::Para
foo-text
]
Having glanced over the relevant compiler modules (grammar, actions, compiling wrapper) I suspect it would take a fair amount of effort to understand it. It's possible that the fruit of that understanding will be the ability to use some of this code as is but I suspect it's at least equally likely you can't without refactoring the compiler code to some degree.
Working from the ground up
The following $pod
will also be accepted by pod2text
:
my $pod =
[Pod::Block::Named.new:
:name("foo"),
:contents[Pod::Block::Para.new:
:contents["foo-text"]]];
say $pod; # displays same result as for `$=pod` above
A solution?
Presumably the solution you seek is somewhere between these extremes.