Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

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 ( [id://731382]=note: print w/replies, xml ) Need Help??


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

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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://731382]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (2)
As of 2024-04-25 19:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found