line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Text::Darts; |
2
|
1
|
|
|
1
|
|
55424
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
24
|
|
3
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
18
|
|
4
|
1
|
|
|
1
|
|
4
|
use Carp; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
215
|
|
5
|
|
|
|
|
|
|
our $VERSION = sprintf "%d.%02d", q$Revision: 0.10 $ =~ /(\d+)/g; |
6
|
|
|
|
|
|
|
our $DEBUG = 0; |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
require XSLoader; |
9
|
|
|
|
|
|
|
XSLoader::load('Text::Darts', $VERSION); |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub new{ |
12
|
0
|
|
|
0
|
0
|
|
my $pkg = shift; |
13
|
0
|
|
|
|
|
|
my $dpi = xs_make([ grep { $_ } sort @_]); |
|
0
|
|
|
|
|
|
|
14
|
0
|
|
|
|
|
|
bless \$dpi, $pkg; |
15
|
|
|
|
|
|
|
} |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub open{ |
18
|
0
|
|
|
0
|
0
|
|
my $pkg = shift; |
19
|
0
|
|
|
|
|
|
my $filename = shift; |
20
|
0
|
0
|
|
|
|
|
my $dpi = xs_open($filename) |
21
|
|
|
|
|
|
|
or carp __PACKAGE__, " cannot open $filename"; |
22
|
0
|
|
|
|
|
|
bless \$dpi, $pkg; |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub DESTROY{ |
26
|
0
|
0
|
|
0
|
|
|
if ($DEBUG){ |
27
|
1
|
|
|
1
|
|
7
|
no warnings 'once'; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
184
|
|
28
|
0
|
|
|
|
|
|
require Data::Dumper; |
29
|
0
|
|
|
|
|
|
local $Data::Dumper::Terse = 1; |
30
|
0
|
|
|
|
|
|
local $Data::Dumper::Indent = 0; |
31
|
0
|
|
|
|
|
|
warn "DESTROY:", Data::Dumper::Dumper($_[0]); |
32
|
|
|
|
|
|
|
} |
33
|
0
|
|
|
|
|
|
xs_free(${$_[0]}); |
|
0
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub search{ |
37
|
0
|
|
|
0
|
0
|
|
xs_search(${$_[0]}, $_[1]); |
|
0
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub gsub{ |
41
|
0
|
|
|
0
|
0
|
|
my $cbstr = $_[2]; |
42
|
1
|
|
|
1
|
|
7
|
no warnings 'uninitialized'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
259
|
|
43
|
0
|
0
|
|
0
|
|
|
my $cb = ref $cbstr ? $cbstr : sub { $cbstr }; |
|
0
|
|
|
|
|
|
|
44
|
0
|
|
|
|
|
|
xs_gsub(${$_[0]}, $_[1], $cb); |
|
0
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
if ($0 eq __FILE__){ |
48
|
0
|
|
|
0
|
0
|
|
sub say { print @_, "\n" }; |
49
|
|
|
|
|
|
|
my @a = ("ALGOL", "ANSI", "ARCO", "ARPA", "ARPANET", "ASCII"); |
50
|
|
|
|
|
|
|
my %a = map { $_ => lc $_ } @a; |
51
|
|
|
|
|
|
|
my $da = __PACKAGE__->new(@a); |
52
|
|
|
|
|
|
|
say $da->gsub("I don't like ALGOL at all!", sub{"<$_[0]>"}); |
53
|
|
|
|
|
|
|
say $da->gsub("I don't like nomatch at all!"); |
54
|
|
|
|
|
|
|
say $da->gsub("I don't like ALGOL at all!", \%a); |
55
|
|
|
|
|
|
|
if (@ARGV){ |
56
|
|
|
|
|
|
|
$da = __PACKAGE__->open(shift); |
57
|
|
|
|
|
|
|
say $da->gsub("The quick brown fox jumps over the black lazy dog", |
58
|
|
|
|
|
|
|
sub{"<$_[0]>"}); |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
1; |
63
|
|
|
|
|
|
|
__END__ |