Code-DRY
view release on metacpan or search on metacpan
Code::DRY version
=================
Code::DRY (short for Don't Repeat Yourself) is a Perl distribution
used to detect repeated code fragments in Perl source code.
It uses C code, so a C compiler is necessary.
INSTALLATION
To install this module type the following:
perl Makefile.PL
make
make test
lib/Code/DRY.pm view on Meta::CPAN
Code::DRY::clip_lcp_to_fileboundaries(\@Code::DRY::fileoffsets);
# avoid matches overlapping into each other
Code::DRY::reduce_lcp_to_nonoverlapping_lengths();
# avoid matches that are included in longer matches
Code::DRY::set_lcp_to_zero_for_shadowed_substrings();
# then iterate through the lcp array via get_len_at(index)
# and through the suffix/offset array via get_offset_at(index)
=head1 DESCRIPTION
The module's main purpose is to report repeated text fragments (typically Perl code)
that could be considered for isolation and/or abstraction in order to
reduce multiple copies of the same code (aka cut and paste code).
Code duplicates may occur in the same line, file or directory.
The ad hoc approach to compare every item against every other item
leads to computing times growing exponentially with the amount of code,
which is not useful for anything but the smallest code bases.
So a efficient data structure is needed.
lib/Code/DRY.pm view on Meta::CPAN
The parameter C<$ignoreContent> can be used to avoid duplication reports for content matching this regex.
If C<$ignoreContent> is not a ref of type 'Regexp', it is expected to be a pattern string that
will be converted into a regexp with C<qr{}xms>.
All repetitions with a minimum length of C<$minlength> will be reported by the C<report> callback function.
=head2 C<set_reporter(sub{ CODE BLOCK })>
Set custom code to report duplicates of a code fragment. The callback is invoked with
position information for the copies found during analysis.
The supplied code has to accept two scalars and an array reference.
The first parameter is the required minimum length of duplicates to be reported.
The second parameter contains a string describing the units for minimum length ('lines' or 'bytes').
The referenced array (third parameter) contains one entry with an anonymous array reference for each copy found.
Copies are reported in the order of the processing of the files and then in the order of positions.
( run in 3.334 seconds using v1.01-cache-2.11-cpan-364913b4093 )