Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

Dear Monks,

we've recently acquired a significant perl codebase that clearly has been growing "organically" for some time... As we need to integrate it into our existing systems and need to make sure we can maintain it long term, work to clean-up/refactoring has commenced.

One of the tasks is the "unused subroutine cleanup" (seems common - see here and here) or at least an identification of potential cruft. We thought that instead of a regexp massacre, we'd like to go for PPI

PPI however seems no tame beast. Documentation is terse and maybe outdated. At least when trying to set up some examples according to documentation, we fail (bitterly). From the docs in PPI::Document:

# Find all the named subroutines my @subs = $Document->find( sub { $_[1]->isa('PPI::Statement::Sub') and $_[1]->name } );

Eh - well - no sir. This will put some ARRAYREF into the first element of @subs and that's it. Dumpering that ARRAYREF reveals a monstrous PPI parse tree. Basically equivalent of the Perl DOM we had in first place. Of course, if we let print out $_[1]->name within the find sub, there the names are, but unfortunately you cannot simply return the name. So for now, the only workaround to get PPI to DWIM, would be to save the names within the find sub into some global variable. Like so:

my @subs; $document->find( sub { if($_[1]->isa('PPI::Statement::Sub') && $_[1]->na +me()) { push @subs, $_[1]->name(); } });

That does the trick, but seems quite hacky, quite nonconformat to what the documentation says (but the docs seem to be wrong in that case anyway).

So the question is - are we missing some general concept of PPI, or are the docs wrong - or both?

Bye
 PetaMem
    All Perl:   MT, NLP, NLU


In reply to Hard time to make use of PPI by PetaMem

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



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (8)
As of 2024-04-18 13:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found