Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris

Re^3: Refactoring Perl 1 - Extract Method

by FunkyMonk (Canon)
on Jun 25, 2007 at 18:06 UTC ( #623220=note: print w/ replies, xml ) Need Help??

in reply to Re^2: Refactoring Perl 1 - Extract Method
in thread Refactoring Perl #1 - Extract Method

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.

Comment on Re^3: Refactoring Perl 1 - Extract Method
Select or Download Code

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://623220]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (5)
As of 2015-11-29 02:50 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (746 votes), past polls