Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

POD, come let me see thee, I have thee not, but still I clutch thee

by Bloodnok (Vicar)
on Dec 18, 2008 at 15:07 UTC ( [id://731273]=perlquestion: print w/replies, xml ) Need Help??

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

Felicitations of the season to all you venerable monks out there ,

Having had a bit of a Super Search round (initially, I tried googling myself silly ... but enjoyed it far too much), I don't seem to be able to find what I'm looking for .. but then again it could be that I'm not asking quite the right question ;-)

This time, the question to which I seek an answer is (takes deep breath and asks more in hope than expectation) ...

Does anybody know of a way to use perldoc (or an alternative) in a manner similar to the perldoc -f <func> command to list the doc for a built-in.

The difference being that I'd like to run it against any CPAN/bespoke module such that the given functions' doc is listed from said module e.g. perldoc -f sub Foo::Bar to list the doc for Foo::Bar::sub() ... c/w perldoc Foo::Bar and get the user to trawl thro' looking for the requisite information on sub.

TIA ,

Sits back to await xmas and enlightening answers - but not necessarily in that order :-)

Update:

.oO(Hmmm, maybe emulate perldoc itself - getting the wanted behaviour by overloading one/some of the Pod::Perldoc::* methods as appropriate i.e. iff called with -f & 2 args and then handing off to perldoc itself...)

A user level that continues to overstate my experience :-))

Replies are listed 'Best First'.
Re: POD, come let me see thee, I have thee not, but still I clutch thee
by LanX (Saint) on Dec 18, 2008 at 21:35 UTC
    > .oO(Hmmm, maybe emulate perldoc itself - getting the wanted behaviour by overloading one/some of the Pod::Perldoc::* methods as appropriate i.e. iff called with -f & 2 args and then handing off to perldoc itself...)

    If your thinking about emulating perldoc, I'm wondering what you really need to realize...

    Just a suggestion: The book Perl Hacks Hack #45 describes how to implement docstrings using Attribute::Handlers. (with a package "Attribute::Docstring" which unfortunately is not on CPAN* ) This allone should work with just compiling the code, and you can introspect all subs and package-vars directly!

    Alternatively you may add a simple static parser which reads the docstrings like sub name :Doc( 'documentation text ...' ) { } without even compiling.

    For me, this looks much easier than emulating perldoc.

    Cheers Rolf

    UPDATE:
    (*) But here perl_hacks_examples.tar.gz /object_hacks/add_information_with_attributes/lib/Attribute/Docstring.pm

Re: POD, come let me see thee, I have thee not, but still I clutch thee
by jplindstrom (Monsignor) on Dec 18, 2008 at 20:37 UTC

    Smart Docs in PerlySense does someting that sounds very similar to what you want.

    Pressing C-o C-d on a method name will try to find it and display the sub/method POD in the echo area (screen shot).

    The PerlySense command line script can only output Emacs elisp and Vim dictionary data structures at the moment, but it should be trivial to just get the POD text.

    Actually, here's a minimal script to do that. Install Devel::PerlySense and save this into psdoc.pl:

    #!/usr/bin/perl -w use strict; use warnings; use Devel::PerlySense; { my ($module_name, $sub_name) = @ARGV; $module_name && $sub_name or die("Syntax: $0 MODULE SUB\n"); my $ps = Devel::PerlySense->new(); my $class = $ps->classByName(name => $module_name, dirOrigin => ". +") or die("Could not find module ($module_name)\n"); my $location = $class->oLocationMethodDoc(method => $sub_name) or die("Could not find sub ($sub_name)\n"); my $pod_text = $location->rhProperty->{text} || "No docs"; print("$pod_text\n"); } __END__

    E.g. call:

    psdoc.pl HTTP::Response base DESCRIPTION $r->base Returns the base URI for this response. The return value will +be a reference to a URI object. The base URI is obtained from one the following sources (in pr +iority order):

    (actually, that one triggers a bug where =item pod isn't treated properly, but I'll fix that :)

    Obviously it won't work for everything since not all module POD are structured in a way that makes it possible to find it. but if the sub/method name is mentioned in a =head or =item line it should work most of the time.

    For your own code it could work flawlessly, since you can be diciplined and document things properly (especially if you can see the obvious benefit). Here's an example:

    psdoc.pl Devel::CoverX::Covered::Db test_files_covering METHODS test_files_covering($source_file_name, [$sub]) : @test_file_names Return list of test files that cover any line in $source_file_name +. Or if $sub is passed, limit to test files covering that sub.

    To be fair, I don't use this hugely often myself. For a project code base I find that I usually need to go to the method anyway in order to make sure I know enough to call it. And for CPAN modules it's usually beneficial to read the whole thing and to make sure I'm not missing something.

    But I hope you'll find it useful.

    /J

Re: POD, come let me see thee, I have thee not, but still I clutch thee
by LanX (Saint) on Dec 18, 2008 at 15:44 UTC
    No I don't know how to achieve this, but I have a motivation 8 )

    Realizing this feature might lead to a powerful alternative for docstrings...

    ... such that one may implement something like introspection - the documentation for a sub may pop up in the editor on selection...

    Cheers Rolf

Re: POD, come let me see thee, I have thee not, but still I clutch thee
by Anonymous Monk on Dec 18, 2008 at 15:42 UTC
Re: POD, come let me see thee, I have thee not, but still I clutch thee
by Zen (Deacon) on Dec 18, 2008 at 20:15 UTC
    A little irony, here. Someday, super search and possibly google may not entice readers to view this node, either, due to the title.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://731273]
Approved by Corion
Front-paged by Tanktalus
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (None)
    As of 2024-04-18 23:42 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      No recent polls found