How could you get the POD method from a REPL or debugger?

I would like to be able to see the method / function documentation when using it inside a REPL or debuger.

Is there any module that will allow you to see the documentation of the function when using REPL or debuger ?.

Obviously, if this module exists, it will ask you to have your POD and syntax-structured code for document extraction. This is not a problem, because I have all my code, and I can adapt to what is needed. Currently I have all my methods with previous PODs =head2 method_nameand typical strings for name, usage, example, arguments, return, exceptions, etc.

A typical example: when you are in a debugger (or REPL), and you want to use a function, and you do not remember the order of the arguments or their types, the type of the returned item, or want to get a hint for use.

I would like to have something like get_pod ($ moudle_bar, $ method_foo) or even better put get_pod in the base module and say $bar->get_pod('foo'). I know that this is not trivial and has many angular cases. It is for this reason that I ask about the POD method extractor module.

I want to show the result inside REPL or debuger, so any pointer to the attached html-pod in the browser is not convenient for me.

Maybe there is something much simpler, and I'm confused.

My first brute force and expensive approach:

> $self = new MyModule
> m $self # to see the available methods for double check the spelling
> # method wanted '_connect_db'
> $cmd = 'perldoc -t ' . ref($self)
> x qx{$cmd}=~/(_connect_db.*?)\n\n/msg
0 '_connect_db
     Title: _connect_db
     Usage:
     Function: create a database conection and return the handler
     Example : $dbh = $self->_connect_db($user, $pass, $db_name) # host is FPrefect by default
     Returns : [0] DBI $dbh object
     Args    :
                [0] $user,
                [1] $pass,
                [2] $db_name,
                [3] $host,
                [4] $db_brand # mysql, sqlite
                [5] $mode = (ro, rw) # not used now. in the future it would use this for read the user and password'

, , , POD, .*?)\n\n , POD.

- ?

UPDATE:

snoopy, Pod:: Coverage, , Pod:: Coverage:: Extractor ( Pod:: Coverage) command, . , .

# package Pod::Coverage::Extractor
#extract subnames from a pod stream
sub command {
    my $self = shift;
    my ( $command, $text, $line_num ) = @_;
    if ( $command eq 'item' || $command =~ /^head(?:2|3|4)/ ) {

        # take a closer look
        my @pods = ( $text =~ /\s*([^\s\|,\/]+)/g );
        $self->{recent} = [];

        foreach my $pod (@pods) {
            print "Considering: '$pod'\n" if debug;

            # it dressed up like a method cal
            $pod =~ /-E<\s*gt\s*>(.*)/ and $pod = $1;
            $pod =~ /->(.*)/           and $pod = $1;

            # it used as a (bare) fully qualified name
            $pod =~ /\w+(?:::\w+)*::(\w+)/ and $pod = $1;

            # it wrapped in a pod style B<>
            $pod =~ s/[A-Z]<//g;
            $pod =~ s/>//g;

            # has arguments, or a semicolon
            $pod =~ /(\w+)\s*[;\(]/ and $pod = $1;

            print "Adding: '$pod'\n" if debug;
            push @{ $self->{ $self->{nonwhitespace}
                    ? "recent"
                    : "identifiers" } }, $pod;
        }
    }

2

, , pdoc. script html API-, Ensembl BioPerl. , -, .

+3
2

CPAN, , .

, - Pod:: Coverage Pod:: .

Pod:: , :

snoopy@deb6:~$ perl -de0
DB<1> use Pod::Coverage
DB<2> our $pc = Pod::Coverage->new(package => 'Mouse');
DB<3> $pc->coverage;
DB<4> use Data::Dumper
DB<5> p Dumper $pc->{symbols}
$VAR1 = {
  'around' => 1,
  'init_meta' => 0,
  'super' => 0,
  'has' => 1,
  'after' => 1,
  'augment' => 0,
  'inner' => 0,
  'override' => 0,
  'with' => 0,
  'extends' => 1,
  'before' => 1
};

, Pod:: Select ( Similar) ?

EDIT , , / Pod:: Coverage, .

+1

PDL (perldl) PDL ? ??, , - REPL.

+1

Source: https://habr.com/ru/post/1786264/


All Articles