Hello cavac,

this sounds very fun! For a zillion of XPD I'd write for you something better :)

No, seriously: parsing perl with regexes? "Only perl can parse Perl" see also On Parsing Perl

Above statements and link comes from PPI documentation.. and yes PPI works!

You can give a try to one of most underestimated CUFP of mines: Repeatedly edit a file hacking PPI::Cache and use it to parse PPI::Statement::Sub class in a perl document. Let see it at work:

perl ppi-editor.pl cache file last_hex_id_file.sto not found. # it search for p +revious runs in the hardcoded filename last_hex_id_file.sto Insert the full path of a new file to edit and press enter (or CTRL-C +to terminate) FILE PATH:./Exp.pm # <---- loading a + file loading from cache ok 'last_hex_id_file.sto' succesfully read: using 5a459de7e28b9b423d7c8d5 +ba988fbdb Which PPI class do you want to edit? PPI CLASS:PPI::Statement::Sub # <---- selecting + a PPI class to work on Each element of the type PPI::Statement::Sub will be proposed for edit + (the content). insert your new input terminating it with CTRL-Z on a empty line. use a bare ENTER to skip the current element STATEMENT: sub new{ my $class = shift; my $validated = _validate( $_[0] ); return bless { validated => $validated, stored => [], },$class; } CONTENT: sub new{ my $class = shift; my $validated = _validate( $_[0] ); return bless { validated => $validated, stored => [], },$class; } EDIT: .... # <---- and so on for every su +b statement storing cache hex_id: 5a459de7e28b9b423d7c8d5ba988fbdb in last_hex_id_ +file.sto Enter a filename if you want to save the current version (or ENTER to +skip) OUTPUT FILE:

You can use the above code as skeleton to automatically inspect every sub and then inspect each shift or assignement coming from @_ to change the sub adding signatures. Should be fun!

I suggest you a final diff log just to review what happened to your code: "unexpected is always a possiblity" :)

L*

UPDATE See PPI::Element to see the difference between statement and content ..in effect i forgot it :) but relaunching my program to inspect PPI::Token::Quote class will demonstrate the difference well enough:

perl ppi-editor.pl 'last_hex_id_file.sto' succesfully read: using 5a459de7e28b9b423d7c8d5 +ba988fbdb # it wants to reload previous edited file Which PPI class do you want to edit? + # if it finds last_hex_id_file.sto PPI CLASS:PPI::Token::Quote + # <-- search for Quote Each element of the type PPI::Token::Quote will be proposed for edit ( +the content). insert your new input terminating it with CTRL-Z on a empty line. use a bare ENTER to skip the current element STATEMENT: croak "No arg!" unless $_[0]; + # statement including the PPI::Element CONTENT: "No arg!" + # content of the PPI::Element itself EDIT:"No arguments!" + # a minimal change EDIT:^Z storing cache hex_id: 057d482fed857c338ec5ff25f2312900 in last_hex_id_ +file.sto Enter a filename if you want to save the current version (or ENTER to +skip) OUTPUT FILE:./Exp-bis.pm + # save to a new file to play nicely.. C>diff Exp.pm Exp-bis.pm + # check it out! 17c17 < croak "No arg!" unless $_[0]; --- > croak "No arguments!" unless $_[0];

There are no rules, there are no thumbs..
Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.

In reply to Re: Converting to sub signatures -- PPI by Discipulus
in thread Converting to sub signatures by cavac

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.