Access POD from another Perl 6 file

妖精的绣舞 提交于 2019-12-01 17:23:44

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.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!