File Coverage

blib/lib/Text/Levenshtein/XS.pm
Criterion Covered Total %
statement 10 10 100.0
branch n/a
condition 2 2 100.0
subroutine 5 5 100.0
pod 1 2 50.0
total 18 19 94.7


line stmt bran cond sub pod time code
1             #
2             # This file is part of Text-Levenshtein-XS
3             #
4             # This software is copyright (c) 2015 by Nick Logan.
5             #
6             # This is free software; you can redistribute it and/or modify it under
7             # the same terms as the Perl 5 programming language system itself.
8             #
9             package Text::Levenshtein::XS;
10              
11 2     2   38302 use 5.008;
  2         7  
12 2     2   11 use strict;
  2         3  
  2         44  
13 2     2   9 use warnings FATAL => 'all';
  2         4  
  2         416  
14             require Exporter;
15              
16             @Text::Levenshtein::XS::ISA = qw/Exporter/;
17             @Text::Levenshtein::XS::EXPORT_OK = qw/distance/;
18             $Text::Levenshtein::XS::VERSION = 0.501;
19              
20             eval {
21             require XSLoader;
22             XSLoader::load(__PACKAGE__, $Text::Levenshtein::XS::VERSION);
23             1;
24             } or do {
25             require DynaLoader;
26             DynaLoader::bootstrap(__PACKAGE__, $Text::Levenshtein::XS::VERSION);
27 2     2 0 473 sub dl_load_flags {0} # Prevent DynaLoader from complaining and croaking
28             };
29              
30              
31              
32             sub distance {
33 53   100 53 1 638387 return Text::Levenshtein::XS::xs_distance( [unpack('U*', shift)], [unpack('U*', shift)], shift || 0);
34             }
35              
36              
37              
38             1;
39              
40             =pod
41              
42             =encoding UTF-8
43              
44             =head1 NAME
45              
46             Text::Levenshtein::XS - Calculate edit distance based on insertion, deletion, substitution, and transposition
47              
48             =head1 VERSION
49              
50             version 0.501
51              
52             =head1 SYNOPSIS
53              
54             use Text::Levenshtein::XS qw/distance/;
55              
56             print distance('Neil','Niel');
57             # prints 2
58              
59             =head1 DESCRIPTION
60              
61             Returns the number of edits (insert,delete,substitute) required to turn the source string into the target string. XS implementation (requires a C compiler). Works correctly with utf8.
62              
63             use Text::Levenshtein::XS qw/distance/;
64             use utf8;
65              
66             distance('ⓕⓞⓤⓡ','ⓕⓤⓞⓡ'),
67             # prints 2
68              
69             =for Pod::Coverage dl_load_flags xs_distance
70              
71             =head1 METHODS
72              
73             =head2 distance
74              
75             =over 4
76              
77             =item Arguments: $source_text, $target_text, (optional) $max_distance
78              
79             =item Return Value: Int $edit_distance || undef (if max_distance is exceeded)
80              
81             =back
82              
83             Returns: int that represents the edit distance between the two argument, or undef if $max_distance threshold is exceeded.
84              
85             Takes the edit distance between a source and target string using XS 2 vector implementation.
86              
87             use Text::Levenshtein::XS qw/distance/;
88             print distance('Neil','Niel');
89             # prints 2
90              
91             Stops calculations and returns undef if $max_distance is set, non-zero (0 = no limit), and the algorithm has determined the final distance will be greater than $max_distance.
92              
93             my $distance = distance('Neil','Niel',1);
94             print (defined $distance) ? $distance : "Exceeded max distance";
95             # prints "Exceeded max distance"
96              
97             =head1 NOTES
98              
99             Drop in replacement for L
100              
101             =head1 SEE ALSO
102              
103             =over 4
104              
105             =item * L
106              
107             =item * L
108              
109             =item * L
110              
111             =item * L
112              
113             =item * L
114              
115             =back
116              
117             =head1 REPOSITORY
118              
119             L
120              
121             =for HTML
122             Coverage Status
123              
124             =head1 BUGS
125              
126             Please report bugs to:
127              
128             L
129              
130             =head1 AUTHOR
131              
132             ugexe
133              
134             =head1 COPYRIGHT AND LICENSE
135              
136             This software is copyright (c) 2015 by Nick Logan.
137              
138             This is free software; you can redistribute it and/or modify it under
139             the same terms as the Perl 5 programming language system itself.
140              
141             =cut
142              
143             __END__