| 1 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||
| 3 | Text::Same::Util | ||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||
| 5 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||
| 7 | Utility methods for Text::Same | ||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||
| 9 | =head1 METHODS | ||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||
| 11 | See below. Methods private to this module are prefixed by an | ||||||||||||||||||||||||||||||||||||||
| 12 | underscore. | ||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||
| 14 | =cut | ||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||
| 16 | package Text::Same::Util; | ||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||
| 18 | 5 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 19 | 5 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 20 | 5 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||
| 22 | 5 | ▶ | use vars qw($VERSION @ISA @EXPORT); | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 23 | 5 | ▶ | use Exporter; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||
| 25 | 5 | @ISA = qw( Exporter ); | |||||||||||||||||||||||||||||||||||||
| 26 | 5 | @EXPORT = qw( hash is_ignorable ); | |||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||
| 28 | 5 | $VERSION = '0.07'; | |||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||
| 30 | 5 | ▶ | use Digest::MD5 qw(md5); | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||
| 32 | =head2 hash | ||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||
| 34 | Title : hash | ||||||||||||||||||||||||||||||||||||||
| 35 | Usage : my $hash_value = hash($options, $text) | ||||||||||||||||||||||||||||||||||||||
| 36 | Function: return an integer hash/checksum for the given text | ||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||
| 38 | =cut | ||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||
| 40 | sub hash | ||||||||||||||||||||||||||||||||||||||
| 41 | 1672 | ▶ | { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
hash: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 42 | 1672 | my $options = shift; | |||||||||||||||||||||||||||||||||||||
| 43 | 1672 | my $text = shift; | |||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||
| 45 | 1672 | ▶ | if ($options->{ignore_case}) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 46 | 399 | $text = lc $text; | |||||||||||||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||||||||||||
| 48 | 1672 | ▶ | if ($options->{ignore_space}) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 49 | 281 | $text =~ s/^\s+//; | |||||||||||||||||||||||||||||||||||||
| 50 | 281 | $text =~ s/\s+/ /g; | |||||||||||||||||||||||||||||||||||||
| 51 | 281 | $text =~ s/\s+$//; | |||||||||||||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||||||||||||
| 53 | 1672 | return md5($text); | |||||||||||||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||
| 56 | sub _is_simple | ||||||||||||||||||||||||||||||||||||||
| 57 | 824 | ▶ | { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
_is_simple: called CC=3 SCAR=16.7
| |||||||||||||||||||||||||||||||||||||||
| 58 | 824 | my ($options, $text) = @_; | |||||||||||||||||||||||||||||||||||||
| 59 | 824 | ▶ | if ($options->{ignore_simple}) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 60 | 0 | my $simple_len = $options->{ignore_simple}; | |||||||||||||||||||||||||||||||||||||
| 61 | 0 | $text =~ s/\s+//g; | |||||||||||||||||||||||||||||||||||||
| 62 | 0 | ▶ | if (length $text <= $simple_len) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 63 | 0 | return 1; | |||||||||||||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||||||||||||
| 66 | 824 | return 0; | |||||||||||||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||
| 69 | =head2 is_ignorable | ||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||
| 71 | Title : is_ignorable | ||||||||||||||||||||||||||||||||||||||
| 72 | Usage : if (is_ignorable($options, $text)) { ... } | ||||||||||||||||||||||||||||||||||||||
| 73 | Function: return true if and only if for the given options, the given text | ||||||||||||||||||||||||||||||||||||||
| 74 | should be ignored during comparisons | ||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||
| 76 | =cut | ||||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||||
| 78 | sub is_ignorable | ||||||||||||||||||||||||||||||||||||||
| 79 | 928 | ▶ | { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
is_ignorable: called CC=4 SCAR=14.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 80 | 928 | my ($options, $text) = @_; | |||||||||||||||||||||||||||||||||||||
| 81 | 928 | ▶ | return 1 if !defined $text; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 82 | 928 | ▶ | return (($options->{ignore_blanks} && $text =~ m/^\s*$/) || | ||||||||||||||||||||||||||||||||||||
|
Condition83%5/6
$options->{'ignore_blanks'} && $text =~ /^\s*$/ || _is_simple($options, $text)
$options->{"ignore_blanks"} and $text =~ /^\s*$/
MC/DC66%2/3
$options->{'ignore_blanks'} && $text =~ /^\s*$/ || _is_simple($options, $text)
$options->{"ignore_blanks"}
$text =~ /^\s*$/
_is_simple($options, $text)
Truth table60%3/5
A and B || C
A= $options->{"ignore_blanks"}B= $text =~ /^\s*$/C= _is_simple($options, $text)
| |||||||||||||||||||||||||||||||||||||||
| 83 | _is_simple($options, $text)); | ||||||||||||||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||
| 86 | =head1 AUTHOR | ||||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||||
| 88 | Kim Rutherford <kmr+same@xenu.org.uk> | ||||||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||||||
| 90 | =head1 COPYRIGHT & LICENSE | ||||||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||||||
| 92 | Copyright 2005,2006 Kim Rutherford. All rights reserved. | ||||||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||||||
| 94 | This program is free software; you can redistribute it and/or modify it | ||||||||||||||||||||||||||||||||||||||
| 95 | under the same terms as Perl itself. | ||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||
| 97 | =head1 DISCLAIMER | ||||||||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||||||
| 99 | This module is provided "as is" without warranty of any kind. It | ||||||||||||||||||||||||||||||||||||||
| 100 | may redistributed under the same conditions as Perl itself. | ||||||||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||||||||
| 102 | =cut | ||||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||||
| 104 | 5 | 1; | |||||||||||||||||||||||||||||||||||||