Refactoring: Adding "rename_subroutine"

  • Matisse Enzer

    Matisse Enzer - 2005-01-30

    I've been talking in email with the author of Devel::Refactor, Scott Sotka, and I am trying to add a "rename_subroutine" feature that could be made avaiable in EPIC. This raises some questions:

    1. How would you feel about my changing Devel::Refactor so that the current "extract subroutine" was provided by a new object method:
       my $refactory = Devel::Refactor->new;
       my ($new_sub_call,$new_code) = $refactory->extract_subroutine($new_name,$code_snippet);

    2. What would be the best interface to rename_subroutine() for EPIC? I think we want to be able to pass either a single file name, or a directory to search all Perl files. I think it would be nice if EPIC showing a comparison for each file, showing the proposed changes, like a diff, so the user can accept or reject each propsoed change.

    • LeO

      LeO - 2005-02-04

      Don't know if Jochen has already replied to your questions -cause this issue is his business. Either you code it by yourself - prefered way. There you can make your own proposals and see what the result will be.

      Otherwise if there is no response, open a RFE and then let's see what the outcome will be.

      • Matisse Enzer

        Matisse Enzer - 2005-02-04

        I have started coding it, but since I do not know how eclipse and EPIC work insternally I wanted to ask to make sure that I don't make it too hard to integrate.

        What I am doing is creating a method that takes either a file name or a directory, and returns a list of file-name/line-number pairs for each time the old subroutine name is found.  I might provide a second method that actually does the replacement, taking a list of file-name/line-number pairs and replacing /old/new/ only on those line numbers.

    • Matisse Enzer

      Matisse Enzer - 2005-02-05

      I am now thinking of two alternatives for what rename_subroutine should return.

      Option 1 is a data structure that has just the lines that change.
      Option 2 is a data structure that contains the entire changed file(s)

      My hope is that the result in EPIC would be to show the user a file comparison, and allow the user to pick which changes to make to the file in the workspace.

      Option 1 would return a hashref of arrays of hashes like this:

                ./path/to/ => [
                                        { 11  => "if (myClass->newName($x)) {\n" },
                                        { 27  => "my $result = myClass->newName($foo);\n"},
                ./path/to/ => [
                                        { 235 => "sub newName {\n"},

      In Option 2, the values of the hashref would be the entire text of the changed file(s)

      • Matisse Enzer

        Matisse Enzer - 2005-02-07

        I finished a first version of the changes, using basically Option1 as described above.

        I've sent a tarfile to Scott (the author of Devel::Refactor) and to Jochen.

        If anyone wants a copy (this is alpha software!) let me know and I'll send you a copy.

    • LeO

      LeO - 2005-02-07

      I'm curious, please send me also a copy.


Log in to post a comment.