The Perl 6 POD documentation has a section on accessing the current file's POD document by using $=pod
. There is no information on accessing another file's POD document.
How can I access another file's POD structure, without altering the current file's $=pod
?
You can now do that with Pod::Load. From the README
in the examples directory
perl6 -e 'use Pod::Load; .perl.say for load("pod-load-clean.pod6")'
Please note that the Pod6 file has to be "clean", that is, not use any external module that is not generally available or it might fail.
Perhaps someone knows a clean way to do this, in which case I'll probably just delete this weak hacky untested sort-of-comment-sort-of-answer unless someone confirms it works and rough consensus is it's worth leaving here.
I suspect you have to go around the mulberry bush.
Something like the following. (Not tested.)
unit class Pod::To::DotPerl;
method render ($pod) { print $pod.perl }
saved in lib/Pod/To/DotPerl.pm6
and installed with zef
then (not tested):
use MONKEY-SEE-NO-EVAL;
my $pod;
try (run <perl6 --doc=DotPerl.pm6 $file>, :err, :out)
andthen $pod = EVAL .out.slurp(:close)
orelse die .err.slurp(:close)
See the end of my previous answer for an outline of what's going on.
I have created a filesystem-agnostic solution in Module::Pod (soon to be published) at git@github.com:dmaestro/Module-Pod.git
use Module::Pod;
# Get all Pod::Block::* objects in the module, from its own $=pod
my @pod = pod-from-module(<My::Module>);
Pros:
- No direct EVALS of file code (even within Module::Pod)
- Uses CompUnit::Repository and kin to locate the module
- May be used with or without
use
-ing the module for other purposes in your code - If module is already loaded, you may call with its Type Object
Cons:
- Module uses nqp: methods directly, as in Pod::Convenience (maybe not really a con?)
- Not able to retrieve pod from *.pod files
Intended for use in Pod6-checking tests, etc.
来源:https://stackoverflow.com/questions/50990701/access-pod-from-another-perl-6-file