blib/lib/Text/Levenshtein/XS.pm

filter: Statementstmt 90.4% 19 / 21 Branchbran 50.0% 1 / 2 Conditioncond 100% 2 / 2 MC/DCmcdc 100% 1 / 1 Subroutinesub 100% 5 / 5 Podpod 50.0% 1 / 2 totaltotal 87.8% 29 / 33 CC 2 SCAR 2.9
CC
2
Cov
88%
distance
2.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.3
↑ Summary XS.xs »
1 #
2 # This file is part of Text-Levenshtein-XS
3 #
4 # This software is copyright (c) 2016 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 3 ▶use 5.008;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 3 ▶use warnings FATAL => 'all';
Subroutine BEGIN: called CC=1 SCAR=0.0
14 3 require Exporter;
15  
16 3 @Text::Levenshtein::XS::ISA = qw/Exporter/;
17 3 @Text::Levenshtein::XS::EXPORT_OK = qw/distance/;
18 3 $Text::Levenshtein::XS::VERSION = 0.503;
19  
20 eval {
21 3 require XSLoader;
22 3 XSLoader::load(__PACKAGE__, $Text::Levenshtein::XS::VERSION);
23 3 1;
24 } or do {
25 0 require DynaLoader;
26 0 DynaLoader::bootstrap(__PACKAGE__, $Text::Levenshtein::XS::VERSION);
27 3 ▶ sub dl_load_flags {0} # Prevent DynaLoader from complaining and croaking
Subroutine dl_load_flags: called CC=1 SCAR=0.0
Pod undocumented
28 3 ▶};
Branch: 1 branch
BranchTrueFalseTotal
eval { do { require XSLoader; XSLoader::load(__PACKAGE__, $Text::Levenshtein::XS::VERSION); 1 } } or do { require DynaLoader; DynaLoader::bootstrap(__PACKAGE__, $Text::Levenshtein::XS::VERSION) } 3 0 3
29  
30  
31  
32 54 ▶sub distance {
Subroutine distance: called CC=2 SCAR=6.9
Pod documented
33 54 ▶ return Text::Levenshtein::XS::xs_distance( [unpack('U*', shift)], [unpack('U*', shift)], shift || 0);
Condition100%2/2
shift() || 0
l!l
2430
MC/DC100%1/1
shift() || 0
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
34 }
35  
36  
37  
38 3 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, and substitution
47  
48 =head1 VERSION
49  
50 version 0.503
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<Text::LevenshteinXS>
100  
101 =head1 SEE ALSO
102  
103 =over 4
104  
105 =item * L<Text::Levenshtein::Damerau>
106  
107 =item * L<Text::Levenshtein::Damerau::PP>
108  
109 =item * L<Text::Levenshtein::Damerau::XS>
110  
111 =item * L<Text::Fuzzy>
112  
113 =item * L<Text::Levenshtein::Flexible>
114  
115 =back
116  
117 =head1 REPOSITORY
118  
119 L<https://github.com/ugexe/Text--Levenshtein--XS>
120  
121 =for HTML <a href="https://travis-ci.org/ugexe/Text--Levenshtein--XS?branch=release"><img src="https://travis-ci.org/ugexe/Text--Levenshtein--XS.svg?branch=release"></a>
122 <a href='https://coveralls.io/r/ugexe/Text--Levenshtein--XS?branch=release'><img src='https://coveralls.io/repos/ugexe/Text--Levenshtein--XS/badge.png?branch=release' alt='Coverage Status' /></a>
123  
124 =head1 BUGS
125  
126 Please report bugs to:
127  
128 L<https://github.com/ugexe/Text--Levenshtein--XS/issues>
129  
130 =head1 AUTHOR
131  
132 ugexe <ugexe@cpan.org>
133  
134 =head1 COPYRIGHT AND LICENSE
135  
136 This software is copyright (c) 2016 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__
↑ Summary XS.xs »