Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?

Re^2: Any smart Perl editors?

by stevieb (Canon)
on Jun 08, 2019 at 21:42 UTC ( #11101143=note: print w/replies, xml ) Need Help??

in reply to Re: Any smart Perl editors?
in thread Any smart Perl editors?

I like the idea here, check out Devel::Examine::Subs, which uses PPI to figure out where subs are. Not only that, it fetches the sub code and stuffs each sub into objects where you can spit them out individually. Works on any Perl file type.

I'm currently working AFK so I can't demo anything at the moment, but I'll see if I can get a chance a little later, but here's a quick and dirty example:

use strict; use warnings; use 5.10.0; use Devel::Examine::Subs; my $des = Devel::Examine::Subs->new(file => ''); my $subs = $des->objects; for my $sub (@$subs){ say $sub->name; say "------"; say $_ for @{ $sub->code }; say "\n"; }

Input file:

use warnings; use strict; three(5); sub three { return two(shift); } sub two { return one(_helper(shift)); } sub one { my $num = calc(shift); display($num); } sub calc { my $num = shift; return $num ** 3; } sub display { my $num = shift; print "$num\n"; } sub _helper { my $num = shift; return ++$num; }


spek@scelia ~/scratch $ perl display ------ sub display { my $num = shift; print "$num\n"; } two ------ sub two { return one(_helper(shift)); } three ------ sub three { return two(shift); } one ------ sub one { my $num = calc(shift); display($num); } calc ------ sub calc { my $num = shift; return $num ** 3; } _helper ------ sub _helper { my $num = shift; return ++$num; }

Might help facilitate the separation with a bit more reliability :)

Replies are listed 'Best First'.
Re^3: Any smart Perl editors?
by FreeBeerReekingMonk (Deacon) on Jun 08, 2019 at 22:57 UTC
    wow... nice module!

    Fiddling with Notepad++ I found that you can run external commands and pass your file (FULL_CURRENT_PATH) and the selected subroutine name (CURRENT_WORD). This external command would use your module to write the subroutine to a file, then call notepad++ again to open that file in the editor...

    But now a question to the OP: Is this the way to go?

    It will be a temporal file, just for looking at it?

    If not: Saving that file back, you can run another external command that find the name of the subroutine, finds the multiline string in the original file, and replaces it with the updated content of the isolated subroutine. And Notepad++ is intelligent enough to tell you the file has changed and you need to update it. The only problem is that you somehow need to make sure the main pl file is saved before doing this, or you lose your changes to the main body (edit: just checked and NPP does NOT autosave before running external commands).

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (10)
As of 2021-06-16 13:44 GMT
Find Nodes?
    Voting Booth?
    What does the "s" stand for in "perls"? (Whence perls)

    Results (74 votes). Check out past polls.