#427 Extract subroutine accepts invalid function names

Core (65)

If a chunk of code is extracted into a subroutine, then the dialog allows the user to enter kind of string.

However, the subroutine name should be checked for invalid characters and cleaned before the extraction is run. Otherwise the subroutine extraction will lead to invalid code.

A simple example:
CODE> $bar = 1;
CODE> $foo = $bar + 1;

extract the second line to a subroutine with the name "bar {} sub foo".

will lead to the following code:

CODE> $bar = 1;
CODE> $foo = bar {} sub foo ($bar);
CODE> sub bar {}
CODE> sub foo {
CODE> my $bar = shift;
CODE> my $foo = $bar + 1;
CODE> return ($foo);

this is not the correct behavior, because the code will not run any longer.

The users should not be able to create invalid code by using the refactoring function.

If a user wants to fool around then the user should end up with code like:

CODE> $bar =1;
CODE> $foo = bar_sub_foo( $bar );
CODE> sub bar_sub_foo {
CODE> my $bar = shift;
CODE> $foo = $bar + 1;
CODE> return ($foo);

Remark: this has been tested with EPIC 0.6.12


  • Nobody/Anonymous

    Logged In: NO


    Running EPIC 0.6.17 here and I experience a different behavior, but also resulting in invalid code :

    original code :

    CODE>$bar = 1;
    CODE>$foo = $bar + 1;
    CODE>print "this is $foo";

    after refactoring line 2 (select all line and then "Refactor->Extract Subroutine") I also end up with invalid code :

    CODE>$bar = 1;
    CODE>my () = bar_sub_foo ($foo, $bar);
    CODE>print "this is $foo";

    CODE>sub bar_sub_foo {
    CODE> my $foo = shift;
    CODE> my $bar = shift;
    CODE> $foo = $bar + 1;
    CODE> return ();

  • Oliver Trosien

    Oliver Trosien - 2016-05-15

    Agree, this refactoring function is still a bit flawed. A possible workaround (and better code style) would be introducing vars with "my / our".


Log in to post a comment.