Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint
Share this Page URL
Help

17. Modules > Refactoring

Refactoring

Place original code inline.

Place duplicated code in a subroutine.

Place duplicated subroutines in a module.

The first time you're tempted to copy-paste-and-modify a piece of code:

package Process::Queue;
use Carp;
{
    use overload (
        # Type coercions don't make sense for process queues...
        q{""}   => sub {
            croak q{Can't stringify a Process::Queue};
        },
        q{0+}   => sub {
            croak q{Can't numerify a Process::Queue };
        },
        q{bool} => sub {
            croak q{Can't get the boolean value of a Process::Queue };
        },
    );
}
# and later...

package Socket;
use Carp;
{
    use overload (
        # Type coercions don't make sense for sockets...
        q{""}   => sub {
            croak q{Can't convert a Socket to a string};
        },
        q{0+}   => sub {
            croak q{Can't convert a Socket to a number};
        },
        q{bool} => sub {
            croak q{Can't get the boolean value of a Socket };
        },
    );
}

  

You are currently reading a PREVIEW of this book.

                                                                                        

Get instant access to over
$1 million worth of books and videos.

  

Start a Free Trial