Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: Meta-perl - sorting my perl subs with perl?

by Perlbotics (Archbishop)
on Jan 20, 2012 at 19:58 UTC ( [id://949034]=note: print w/replies, xml ) Need Help??


in reply to Meta-perl - sorting my perl subs with perl?

Maybe you can start with B::Xref and render the output as a report?

perl -MO=Xref YourMod.pm

Update: Perhaps, I misunderstood... you seem to want to sort the source code, such that e.g. sub a_func comes before/above sub b_func?

Personally, I would rather group the subs by functionality and let the editor do the work localising the subs (e.g. Emacs Imenu, other editors have similar functionality).

But with an amount of 150 subs, there is a good chance they can be grouped in specialised (sub-)modules, reducing the set of subs to an amount that can be managed (read: edit, document, test) with less effort.

Replies are listed 'Best First'.
Re^2: Meta-perl - sorting my perl subs with perl?
by mbethke (Hermit) on Jan 20, 2012 at 21:16 UTC
    Personally, I would rather group the subs by functionality and let the editor do the work localising the subs (e.g. Emacs Imenu, other editors have similar functionality).
    +1 Or if it has to be alphabetical, what about just inserting them in this order? It's not like you write a new sub every couple of seconds.
    But with an amount of 150 subs, there is a good chance they can be grouped in specialised (sub-)modules, reducing the set of subs to an amount that can be managed (read: edit, document, test) with less effort.
    Double plus good! Plus you get the alphabetical sorting as ls' default ;)
Re^2: Meta-perl - sorting my perl subs with perl?
by Syndaryl (Initiate) on Jan 23, 2012 at 14:48 UTC

    I'm already grouping subs by functionality. This is literally a cluster of 150 subs with related functionality - the rest of the program is elsewhere :/

    To expand a little on how this particular project is merrily spiraling out of control:

    Project is text extraction from a print-ready format never meant to be used as a text source, parsing the natural-language text out of known tables to XML, and finally burping up reformatted text via FO.

    Client initially indicated they didn't have that many uniquely-presenting tables to rip out. Client provided samples (in PDF, not the production format) for our assessment that were consistent with this claim. We received samples in the production format and found a rather hairier situation. But nobody Upstairs is changing deadlines :/ Since the client apparently can't count, the "solution" is that they're now regularly sending us more samples, where we find more types of tables and have to shove more items onto the match-text-goto-handling-sub hash, even as we're trying to do everything else.

    The team IDing new sections and match regexes are batch-generating skeletons of the relevant parts of the code via a couple of algorithms, which I then get to put into my module and flesh out. The last thing anyone's really been concerned about is alphabetizing the "handle text in table format XYZ" subs. I don't think I can justify to my boss taking half an hour or so out to reorganize the ones we have just because it annoys me, and frankly that's more boring than I find it irritating. If I'm going to do it on my own time, I'd rather write script than cut and paste code. :)

      stick __END__ at the top of your file, then use

      perl -MAutoSplit -e  " autosplit( $ARGV[0], $ARGV[1], 0, 0 ) " lib/Some/File.pm  out/dir/like/a/lib

      This will generates one file for each function, then you can glob/sort/cat and reconstitute Some::File with subs in sorted order

Log In?
Username:
Password:

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

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

    No recent polls found