Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options

Re: Refactoring Perl 1 - Extract Method

by rhesa (Vicar)
on Jun 22, 2007 at 11:37 UTC ( #622772=note: print w/replies, xml ) Need Help??

in reply to Refactoring Perl #1 - Extract Method

Thanks, agianni, looks good.

A little while ago I stumbled on a perl script to perform this refactoring. I found it through Piers Cawley's blog in this post. The script itself is written by Jesse Vincent, and can be found here. Read the comments on Piers' post for further instructions. I've hooked it into my vimrc, and it's proven to be a nice tool.

  • Comment on Re: Refactoring Perl 1 - Extract Method

Replies are listed 'Best First'.
Re^2: Refactoring Perl 1 - Extract Method
by agianni (Hermit) on Jun 25, 2007 at 15:04 UTC

    I haven't had a chance to try the script out, but I'd like to get myself set up to use some of these tools that provide refactoring capacity. I have briefly looked at Komodo and Eclipse but my development environment doesn't make them particularly easy to use and I haven't been able to take the time to get myself setup with them. I've been using emacs for years and just haven't seen the value in switching just yet.

    I would definitely be interested to see other's comments on refactoring tools for Perl. I know Devel::Refactor was built specifically for use within Eclipse. Any others out there?

    perl -e 'split//,q{john hurl, pest caretaker}and(map{print @_[$_]}(joi +n(q{},map{sprintf(qq{%010u},$_)}(2**2*307*4993,5*101*641*5261,7*59*79 +*36997,13*17*71*45131,3**2*67*89*167*181))=~/\d{2}/g));'
      After reading this thread, I hooked up a small Devel::Refactor script to emacs at the weekend. It works, but I haven't used it seriously, and I'm not convinced it provides a huge productivity leap

      Anyway, here's how...

      in your .emacs:

      (defun refactor-extract () "Change region into a subroutine" (interactive) (shell-command-on-region (point) (mark) "./refactor-extract" t) )

      and some Perl in refactor-extract:

      #!/usr/bin/perl ### Rewrite code block as a subroutine # This is mostly intended to be used through emacs' # shell-command-on-region # #(defun refactor-extract () # "Change region in to a subroutine" # (interactive) # (shell-command-on-region (point) (mark) "./refactor-extract" t)) # #Based on a Perlmonks node: use strict; use warnings FATAL => 'all'; use Devel::Refactor; my $code = join '', <>; my $name = "refactored_" . sprintf( "%04d", rand() * 10000 ); print join "\n", Devel::Refactor->new->extract_subroutine( $name, $cod +e );

      use Disclaimer::Std;
      This was a quick hack, quickly hacked. Use at your peril.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://622772]
[Eily]: muthusathish ok, the fact that you can't tell what perl has to do with it proves it: this is not perl

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (9)
As of 2018-02-23 09:20 GMT
Find Nodes?
    Voting Booth?
    When it is dark outside I am happiest to see ...

    Results (301 votes). Check out past polls.