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

Some of you might have already heard about Padre, the Perl IDE I have started to write.

I am not sure if the more experienced users will need the calltip feature but it seems that when you are a beginner and type a perl command it helps if your editor shows you what parameters can you give to that function.

I created a screenshot showing an example on Padre 0.08.

So far what I did was creating a hash such as this:

my %keywords = ( chomp => '(STRING)', substr => '(EXPR, OFFSET, LENGTH, REPLACEMENT)', index => '(STR, SUBSTR, INDEX)', pop => '(@ARRAY)', psush => '(@ARRAY, LIST)', print => '(LIST) or (FILEHANDLE LIST)', join => '(EXPR, LIST)', split => '(/PATTERN/,EXPR,LIMIT)', wantarray => '()', );
The question is if I have to create this mapping for all the functions or if I can fetch it from somewhere?

I looked at the perlfunc.pod and for every function it has several =item funcname PARAMS entries providing all the possible paramters.

I might build the list from there on the fly but I think it might be better to put the examples in order of how common they are or show only the most common one to reduce confusion.

In case you wonder, if I create a mapping, I'll certainly will make it separate from Padre so other IDEs or editors will be able to use it.

Actually this might be interesting to and advanced user as well especially when she is looking at functions or methods she does not use often.

I wonder if the same functionality could be or should be provided for standard modules too? What about the general case of CPAN? What about DarkPAN, that is modules in companies or otherwise not on CPAN?
Can we define some way to fetch the signature of functions from the documentation of the module?

What do you think? How should this be solved?

Replies are listed 'Best First'.
Re: Calltips for Padre
by LesleyB (Friar) on Sep 11, 2008 at 15:34 UTC

    mucho ++ for all this work especially the proposal to make the mapping available outside of padre.

    I think the tooltips might be very useful for beginners although I would prefer the opportunity to turn them off - or indeed back on again!

    Deciding what are the most common uses of a function will make much more work than 'simply' extracting the function name and parameter list from the pod documentation, but it might be effective in the first instance.

    However, short forms might also lure the lazy into a false sense of security, so do you plan to provide the short form and the full form or just the short form?

    How would you indicate this is a short list and not the full list?

    An advanced user might want to always get the full list of parameters

    I think it would be good to have the capability for the standard modules too but this may confuse beginners when they expect the data to be there for non-standard modules. This may give rise to much noise.

    Lots of +++ to your karma

      You can already turn it on/off. Default is on.

      Maybe there should be a default set of calltips and then you could switch to different sets...

      good ideas, thanks.

Re: Calltips for Padre
by j1n3l0 (Friar) on Sep 11, 2008 at 15:53 UTC
    Komodo Edit and Eclipe + EPIC plugin both have this functionality. Perhaps you can look into how they got this done? They may already have this list you speak of creating.

    Can we define some way to fetch the signature of functions from the documentation of the module?

    Again this is something Komodo Edit does and it does not require documentation to do so. Once you define your subroutine, it looks at what is retrieved from @_ and creates a signature. I've never looked at the source code so I can't tell you how they get it done.

    Ps: I think you miss-spelled "push" in your %keywords list =)


    Smoothie, smoothie, hundre prosent naturlig!
      push typo fixed. In the code. Thanks
Re: Calltips for Padre
by tod222 (Pilgrim) on Sep 11, 2008 at 19:11 UTC
    The CPerl Mode for Emacs puts terse documentation in the status line when the cursor remains on a keyword or function for a few seconds. Maybe you can use its info as a start?
Re: Calltips for Padre
by moritz (Cardinal) on Sep 12, 2008 at 07:38 UTC
    I wonder if the same functionality could be or should be provided for standard modules too? What about the general case of CPAN?

    It would be very cool if there were some way to extract such information, but to stay realistic, that won't work until Perl has function/method signatures.

    Currently much documentation actually duplicates the argument passing code in some way

    =item C<foo($bar, $count)> Frobs the object by doing C<$bar> at least C<$count> times =cut sub foo { my ($self, $bar, $count) = @_; }

    This duplication is mostly done in a non-standard way, and as thus really hard to automatically distract.

    I don't think that you'll have overwhelming success with convincing CPAN authors on a standard documentation format. The only way to win is to enable function and method signatures. By hacking them into bleadperl, or by helping Perl 6 development.

      What I thought was that I can establish a way (or two) how Padre (or whatever module does the work) fetches this information from the pod. Once that is in place module authors might update their pods in order to play nice with the IDEs.

      Its still duplication of work on their part but at least I don't have to triplicate (?) the work in a totally unmaintainable way.

      Real signatures in Perl would of course help but I don't think I want to wait for that. Especially as most of CPAN won't use them for the next 10 years as they will want to be compatible with 5.10.

Re: Calltips for Padre
by manni (Novice) on Sep 12, 2008 at 06:50 UTC

    I think you should forget the standard modules and not even start ot think about CPAN. There's probably some clever way to come up with a calltip in a large number of cases, but would it be useful?

    Suppose I typed "Data::Dumper->Dump(" and got "[@ARRAY], [@ARRAY]". How would that help?

    IMHO, calltips are fine for the builtin functions, but they are not going to help you with anything but the most simplistic modules.

    Cudos for all the good and fast work you are doing on Padre. I hope I will succeed in installing it one of these days.
      The difficult part is the Wx installation. There is some help on the download page and if that does not help you can ask on the wxPerl mailing lists

      If it is something else, ask on PerlMonks...

Re: Calltips for Padre
by wazoox (Prior) on Sep 12, 2008 at 14:04 UTC
    The question is if I have to create this mapping for all the functions or if I can fetch it from somewhere?

    I've made such a calltip file for Nedit (my preferred editor) quite a while ago. I should probably refresh it with the 5.10 new stuff, but if it can help you you'll find it there : http://www.nedit.org/ftp/contrib/calltips/Perl.tips