line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Text::HumanComputerWords; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
229858
|
use strict; |
|
1
|
|
|
|
|
8
|
|
|
1
|
|
|
|
|
30
|
|
4
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
23
|
|
5
|
1
|
|
|
1
|
|
15
|
use 5.022; |
|
1
|
|
|
|
|
4
|
|
6
|
1
|
|
|
1
|
|
541
|
use experimental qw( signatures refaliasing ); |
|
1
|
|
|
|
|
3587
|
|
|
1
|
|
|
|
|
6
|
|
7
|
1
|
|
|
1
|
|
804
|
use Ref::Util qw( is_ref is_plain_coderef ); |
|
1
|
|
|
|
|
1696
|
|
|
1
|
|
|
|
|
85
|
|
8
|
1
|
|
|
1
|
|
7
|
use Carp qw( croak ); |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
1042
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
# ABSTRACT: Split human and computer words in a naturalish manner |
11
|
|
|
|
|
|
|
our $VERSION = '0.04'; # VERSION |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
|
14
|
10
|
|
|
|
|
18
|
sub new ($class, @args) |
15
|
10
|
|
|
10
|
1
|
22357
|
{ |
|
10
|
|
|
|
|
23
|
|
|
10
|
|
|
|
|
13
|
|
16
|
10
|
100
|
|
|
|
286
|
croak "uneven arguments passed to constructor" if @args % 2; |
17
|
|
|
|
|
|
|
|
18
|
9
|
|
|
|
|
16
|
my $i=0; |
19
|
9
|
|
|
|
|
23
|
while(exists $args[$i]) |
20
|
|
|
|
|
|
|
{ |
21
|
18
|
|
|
|
|
31
|
my $name = $args[$i]; |
22
|
18
|
|
|
|
|
27
|
my $code = $args[$i+1]; |
23
|
|
|
|
|
|
|
|
24
|
18
|
100
|
|
|
|
40
|
croak "argument @{[ $i+1 ]} is undef" unless defined $name; |
|
1
|
|
|
|
|
134
|
|
25
|
17
|
100
|
|
|
|
32
|
croak "argument @{[ $i+2 ]} is undef" unless defined $code; |
|
1
|
|
|
|
|
101
|
|
26
|
16
|
100
|
|
|
|
34
|
croak "argument @{[ $i+1 ]} is not a plain string" if is_ref $name; |
|
1
|
|
|
|
|
98
|
|
27
|
15
|
100
|
|
|
|
36
|
croak "argument @{[ $i+2 ]} is not a plain code reference" unless is_plain_coderef $code; |
|
1
|
|
|
|
|
101
|
|
28
|
|
|
|
|
|
|
|
29
|
14
|
|
|
|
|
32
|
$i+=2; |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
5
|
|
|
|
|
50
|
bless [@args], $class; |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub default_perl |
37
|
|
|
|
|
|
|
{ |
38
|
|
|
|
|
|
|
return ( |
39
|
11
|
|
|
11
|
|
15
|
path_name => sub ($text) { |
|
11
|
|
|
|
|
17
|
|
|
11
|
|
|
|
|
12
|
|
40
|
11
|
100
|
|
|
|
58
|
$text =~ m{^/(bin|boot|dev|etc|home|lib|lib32|lib64|mnt|opt|proc|root|sbin|tmp|usr|var)(/|$)} |
41
|
|
|
|
|
|
|
|| $text =~ m{^[a-z]:[\\/]}i |
42
|
|
|
|
|
|
|
}, |
43
|
7
|
|
|
7
|
|
9
|
url_link => sub ($text) { |
|
7
|
|
|
|
|
9
|
|
|
7
|
|
|
|
|
10
|
|
44
|
7
|
100
|
|
|
|
50
|
$text =~ /^[a-z]+:\/\//i |
45
|
|
|
|
|
|
|
|| $text =~ /^(file|ftps?|gopher|https?|ldapi|ldaps|mailto|mms|news|nntp|nntps|pop|rlogin|rtsp|sftp|snew|ssh|telnet|tn3270|urn|wss?):\S/i |
46
|
|
|
|
|
|
|
}, |
47
|
5
|
|
|
5
|
|
9
|
module => sub ($text) { |
|
5
|
|
|
|
|
7
|
|
|
5
|
|
|
|
|
6
|
|
48
|
5
|
|
|
|
|
23
|
$text =~ /^[a-z]+::([a-z]+(::[a-z]+)*('s)?)$/i |
49
|
|
|
|
|
|
|
}, |
50
|
1
|
|
|
1
|
1
|
6250
|
); |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
|
54
|
5
|
|
|
|
|
25
|
sub split ($self, $text) |
55
|
5
|
|
|
5
|
1
|
4173
|
{ |
|
5
|
|
|
|
|
10
|
|
|
5
|
|
|
|
|
8
|
|
56
|
5
|
|
|
|
|
8
|
my @result; |
57
|
|
|
|
|
|
|
|
58
|
5
|
|
|
|
|
36
|
frag_loop: foreach my $frag (CORE::split /\s+/, $text) |
59
|
|
|
|
|
|
|
{ |
60
|
23
|
50
|
|
|
|
67
|
next unless $frag =~ /\w/; |
61
|
|
|
|
|
|
|
|
62
|
23
|
|
|
|
|
35
|
my $i=0; |
63
|
23
|
|
|
|
|
53
|
while(defined $self->[$i]) |
64
|
|
|
|
|
|
|
{ |
65
|
40
|
|
|
|
|
97
|
my $name = $self->[$i++]; |
66
|
40
|
|
|
|
|
48
|
my $code = $self->[$i++]; |
67
|
40
|
100
|
|
|
|
98
|
if($name eq 'substitute') |
|
|
100
|
|
|
|
|
|
68
|
|
|
|
|
|
|
{ |
69
|
2
|
|
|
|
|
7
|
\local $_ = \$frag; |
70
|
2
|
|
|
|
|
6
|
$code->(); |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
elsif($code->($frag)) |
73
|
|
|
|
|
|
|
{ |
74
|
13
|
100
|
|
|
|
75
|
push @result, [ $name, $frag ] unless $name eq 'skip'; |
75
|
13
|
|
|
|
|
35
|
next frag_loop; |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
10
|
|
|
|
|
108
|
word_loop: foreach my $word (CORE::split /\b{wb}/, $frag) |
80
|
|
|
|
|
|
|
{ |
81
|
19
|
100
|
|
|
|
49
|
next word_loop unless $word =~ /\w/; |
82
|
14
|
|
|
|
|
40
|
push @result, [ word => $word ]; |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
5
|
|
|
|
|
20
|
@result; |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
1; |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
__END__ |