Access POD from another Perl 6 file

254 views Asked by At

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?

2

There are 2 answers

0
jjmerelo On

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.

1
dmaestro12 On

I have created a filesystem-agnostic solution in Module::Pod (soon to be published) at [email protected]: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.