blib/lib/Text/Tidx.pm untested

filter: Statementstmt 0.0% 0 / 53 Branchbran 0.0% 0 / 28 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 0.0% 0 / 9 Podpod 0.0% 0 / 3 totaltotal 0.0% 0 / 98 CC 15 SCAR 39.8
CC
15
Cov
0%
build
110.0
query
20.0
lookup
12.0
CRAP 53.4
1 package Text::Tidx;
2  
3 use 5.010001;
4 use strict;
5 use warnings;
6 use Carp;
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 if (@_ == 3) {
38 return lookup_c(@_, "^");
39 }
40 if (@_ == 4) {
41 return lookup_cr(@_, "^");
42 }
43 }
44  
45 sub query {
46 my $r;
47 if (@_ == 3) {
48 $r = lookup_c(@_, "^");
49 }
50 if (@_ == 4) {
51 $r = lookup_cr(@_, "^");
52 }
53 return () if (!$r);
54 $r =~ s/^\^//;
55 return split /\^/, $r;
56 }
57  
58 sub build {
59 my ($file, %op) = @_;
60 croak "usage: build(file, options)\n" unless $file;
61 $op{skip} = '#' if !defined($op{skip});
62 $op{skip_c} = $op{skip} !~ /^\d+$/ ? $op{skip} : '';
63 $op{skip_i} = $op{skip} =~ /^\d+$/ ? $op{skip} : 0;
64 $op{sub_e} = $op{sub} || $op{sub_e} ? 1 : 0;
65 $op{sep} = "\t" if !$op{sep};
66 $op{chr} = 1 if !defined($op{chr});
67 $op{beg} = 2 if !$op{beg};
68 $op{end} = 3 if !$op{end};
69 # one based index, consistent with command-line version
70 --$op{chr};
71 --$op{beg};
72 --$op{end};
73 # todo... for kicks: allow indexing on text only, no positions
74 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__