Devel-Refactor

 view release on metacpan or  search on metacpan

README  view on Meta::CPAN

=========================

The Devel::Refactor module is for code refactoring.  Pass it a
a snippet of Perl code that belongs in its own subroutine as
well as a name for that sub.  It figures out which variables
need to be passed into the sub, and which variables might be
passed back.  It then produces the sub along with a call to
the sub.

Included in this module is an example script that pulls the
snippet of code from the KDE clipboard in Linux and passes 
back the transformed code the same way.

INSTALLATION

To install this module type the following:

   perl Makefile.PL
   make
   make test
   make install

Refactor.pm  view on Meta::CPAN

    #      push @results, $hash{$loopvar} || '';
    #   }
    # 
    # 
    #     return ($date, \%hash, \@results);
    # }


Included in the examples directory is a script for use in KDE
under Linux.  The script gets its code snippet from the KDE 
clipboard and returns the transformed code the same way.  The
new sub name is prompted for via STDIN.

=cut

sub extract_subroutine {
    my $self         = shift;
    my $sub_name     = shift;
    my $code_snippet = shift;
    my $syntax_check = shift;

examples/factory.pl  view on Meta::CPAN

#!/usr/bin/perl
use Data::Dumper;
use Devel::Refactor; 

$|++;

# Get the contents of the clipboard.  Requires dcop from KDE.
my $clipboard = `dcop klipper klipper getClipboardContents`;

print "Subroutine Name? ";
my $name = <STDIN>;

chomp $name;

my $refactory = Devel::Refactor->new;
my ($new_sub_call,$new_code) = $refactory->extract_subroutine($name,$clipboard);

my $retval = $new_sub_call . $new_code;

# protect quotes and dollar signs
$retval =~ s/\"/\\"/g;
$retval =~ s/(\$)/\\$1/g;

#Put the results back on the clipboard.
`dcop klipper klipper setClipboardContents "$retval"`;



( run in 2.933 seconds using v1.01-cache-2.11-cpan-84e82930d8c )