#!/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: http://www.perlmonks.org/?node_id=622772 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, $code );