bulk88 has asked for the wisdom of the Perl Monks concerning the following question:

Can I put POD in XS code and somehow have xsubpp generate a pod file during the build? How do you go about documenting a XS module with documentation inline with the XS or C code? Anything I should add to makefile.pl or postamble section of the makefile? Any magic parameters for ExtUtils::MakeMaker? MAN3PODS? I searched monks already but I didnt see an answer, just it being asked before.

Replies are listed 'Best First'.
Re: POD in XS
by tobyink (Canon) on Mar 18, 2012 at 20:12 UTC

    As BrowserUk said, you'd generally have a .pm file that loads your XS - you can put your POD documentation into the .pm file.

    That said though, it is possible to add pod to an .xs file. Just include the pod in a C comment...

    #include "EXTERN.h" #include "perl.h" #include "XSUB.h" #include "ppport.h" MODULE = Mytest PACKAGE = Mytest void hello() CODE: printf("Hello, world!\n"); /* =head1 NAME Mytest - this is a test! =cut */

    Note the start of the comment needs to be indented for the benefit of xsubpp. Not sure if the end of the comment needs to be, but no harm in doing so. Don't forget the =cut.

    Now, that gives you pod in XS. You should be able to run something like pod2man on it and it will work. EU:MM will not automatically find the pod there and install it for the end user though. You can probably play some games with Pod::Man in your Makefile.PL.

    perl -E'sub Monkey::do{say$_,for@_,do{($monkey=[caller(0)]->[3])=~s{::}{ }and$monkey}}"Monkey say"->Monkey::do'
      So far MAN3PODS is useless or buggy on activeperl's HTML system. Changing the parameters UpdateHTML_blib is possible and suggested in the docs for AP's MM, but I think thats very prone to future breakage. I think I will try to just have a makefile section automatically copy and rename the .xs file to a .pod. I will update this post with my results.
      MAN3PODS => { 'MYXSLIB.xs' => '/blib/man3/MYXSLIB.3'},
      # --- MakeMaker manifypods section: POD2MAN_EXE = $(PERLRUN) "-MExtUtils::Command::MM" -e pod2man "--" POD2MAN = $(POD2MAN_EXE) manifypods : pure_all \ MYXSLIB.xs $(NOECHO) $(POD2MAN) --section=3 --perm_rw=$(PERM_RW) \ MYXSLIB.xs /blib/man3/MYXSLIB.3 # --- MakeMaker htmlifypods section: POD2HTML_EXE = $(PERLRUN) "-MActivePerl::DocTools" -e "UpdateHTML_blib +(installdirs => "$(INSTALLDIRS)")" POD2HTML = $(POD2HTML_EXE) htmlifypods : \ MYXSLIB.xs $(NOECHO) $(POD2HTML)
      Update:

      I found putting this in makefile.pl works with ActivePerl.
      package MY; sub postamble { return ' MoreDocs.pod :: $(CP) $(BASEEXT).xs .\lib\$(FULLEXT)\MoreDocs.pod $(BASEEXT).xs :: MoreDocs.pod '; }
Re: POD in XS
by BrowserUk (Patriarch) on Mar 18, 2012 at 17:09 UTC

    You need a .PM file to load the XS code. If you insist on using POD, that's the obvious place to put it.

Re: POD in XS
by LanX (Saint) on Mar 18, 2012 at 17:57 UTC