line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Text::Tidx; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
21337
|
use 5.010001; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
37
|
|
4
|
1
|
|
|
1
|
|
6
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
32
|
|
5
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
13
|
|
|
1
|
|
|
|
|
43
|
|
6
|
1
|
|
|
1
|
|
4
|
use Carp; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
544
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
require Exporter; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our @ISA = qw(Exporter); |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
# Items to export into callers namespace by default. Note: do not export |
13
|
|
|
|
|
|
|
# names by default without a very good reason. Use EXPORT_OK instead. |
14
|
|
|
|
|
|
|
# Do not simply export all your public functions/methods/constants. |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
# This allows declaration use Text::Tidx ':all'; |
17
|
|
|
|
|
|
|
# If you do not need this, moving things directly into @EXPORT or @EXPORT_OK |
18
|
|
|
|
|
|
|
# will save memory. |
19
|
|
|
|
|
|
|
our %EXPORT_TAGS = ( 'all' => [ qw( |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
) ] ); |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } ); |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
our @EXPORT = qw( |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
); |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
our $VERSION = '0.94'; |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
require XSLoader; |
32
|
|
|
|
|
|
|
XSLoader::load('Text::Tidx', $VERSION); |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
# Preloaded methods go here. |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub lookup { |
37
|
0
|
0
|
|
0
|
0
|
0
|
if (@_ == 3) { |
38
|
0
|
|
|
|
|
0
|
return lookup_c(@_, "^"); |
39
|
|
|
|
|
|
|
} |
40
|
0
|
0
|
|
|
|
0
|
if (@_ == 4) { |
41
|
0
|
|
|
|
|
0
|
return lookup_cr(@_, "^"); |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub query { |
46
|
3
|
|
|
3
|
1
|
20556
|
my $r; |
47
|
3
|
100
|
|
|
|
48
|
if (@_ == 3) { |
48
|
1
|
|
|
|
|
90
|
$r = lookup_c(@_, "^"); |
49
|
|
|
|
|
|
|
} |
50
|
3
|
100
|
|
|
|
12
|
if (@_ == 4) { |
51
|
2
|
|
|
|
|
67
|
$r = lookup_cr(@_, "^"); |
52
|
|
|
|
|
|
|
} |
53
|
3
|
50
|
|
|
|
9
|
return () if (!$r); |
54
|
3
|
|
|
|
|
42
|
$r =~ s/^\^//; |
55
|
3
|
|
|
|
|
36
|
return split /\^/, $r; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
sub build { |
59
|
1
|
|
|
1
|
1
|
21
|
my ($file, %op) = @_; |
60
|
1
|
50
|
|
|
|
5
|
croak "usage: build(file, options)\n" unless $file; |
61
|
1
|
50
|
|
|
|
8
|
$op{skip} = '#' if !defined($op{skip}); |
62
|
1
|
50
|
|
|
|
10
|
$op{skip_c} = $op{skip} !~ /^\d+$/ ? $op{skip} : ''; |
63
|
1
|
50
|
|
|
|
7
|
$op{skip_i} = $op{skip} =~ /^\d+$/ ? $op{skip} : 0; |
64
|
1
|
50
|
33
|
|
|
327
|
$op{sub_e} = $op{sub} || $op{sub_e} ? 1 : 0; |
65
|
1
|
50
|
|
|
|
7
|
$op{sep} = "\t" if !$op{sep}; |
66
|
1
|
50
|
|
|
|
6
|
$op{chr} = 1 if !defined($op{chr}); |
67
|
1
|
50
|
|
|
|
4
|
$op{beg} = 2 if !$op{beg}; |
68
|
1
|
50
|
|
|
|
6
|
$op{end} = 3 if !$op{end}; |
69
|
|
|
|
|
|
|
# one based index, consistent with command-line version |
70
|
1
|
|
|
|
|
3
|
--$op{chr}; |
71
|
1
|
|
|
|
|
2
|
--$op{beg}; |
72
|
1
|
|
|
|
|
2
|
--$op{end}; |
73
|
|
|
|
|
|
|
# todo... for kicks: allow indexing on text only, no positions |
74
|
1
|
|
|
|
|
47073
|
tidx_build($file, $op{sep}, $op{chr}, $op{beg}, $op{end}, $op{skip_i}, $op{skip_c}, $op{sub_e}); |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
1; |
78
|
|
|
|
|
|
|
__END__ |