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 => 'test.pl'); 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; }

Output:

spek@scelia ~/scratch $ perl des.pl 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 :)


In reply to Re^2: Any smart Perl editors? by stevieb
in thread Any smart Perl editors? by harangzsolt33

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.