| 1 | package Spellunker; | ||||||||||||||||||||||||||||
| 2 | 11 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 11 | ▶ | use warnings FATAL => 'all'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 11 | ▶ | use utf8; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 11 | ▶ | use 5.008001; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 11 | ▶ | use version; our $VERSION = version->declare("v0.4.0"); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 11 | ▶ | use Scalar::Util (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 11 | ▶ | use File::Spec (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 11 | ▶ | use File::ShareDir (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 11 | ▶ | use Regexp::Common qw /URI/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | # Ref http://www.din.or.jp/~ohzaki/mail_regex.htm#Simplify | ||||||||||||||||||||||||||||
| 15 | 11 | my $MAIL_REGEX = ( | |||||||||||||||||||||||||||
| 16 | q{(?:[-!#-'*+/-9=?A-Z^-~]+(?:\.[-!#-'*+/-9=?A-Z^-~]+)*|"(?:[!#-\[\]-} . | ||||||||||||||||||||||||||||
| 17 | q{~]|\\\\[\x09 -~])*")@[-!#-'*+/-9=?A-Z^-~]+(?:\.[-!#-'*+/-9=?A-Z^-~]+} . | ||||||||||||||||||||||||||||
| 18 | q{)*} | ||||||||||||||||||||||||||||
| 19 | ); | ||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | 10 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=3 SCAR=11.1
Pod
documented
| |||||||||||||||||||||||||||||
| 23 | 10 | my $class = shift; | |||||||||||||||||||||||||||
| 24 | 0 | ▶ | my %args = @_==1 ? %{$_[0]} : @_; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 25 | 10 | my $self = bless {}, $class; | |||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | # From https://code.google.com/p/dotnetperls-controls/downloads/detail?name=enable1.tx | ||||||||||||||||||||||||||||
| 28 | 10 | $self->load_dictionary(File::Spec->catfile(File::ShareDir::dist_dir('Spellunker'), 'enable1.txt')); | |||||||||||||||||||||||||||
| 29 | 10 | $self->load_dictionary(File::Spec->catfile(File::ShareDir::dist_dir('Spellunker'), 'spellunker-dict.txt')); | |||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | 10 | ▶ | unless ($ENV{PERL_SPELLUNKER_NO_USER_DICT}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 32 | 2 | $self->_load_user_dict(); | |||||||||||||||||||||||||||
| 33 | } | ||||||||||||||||||||||||||||
| 34 | 10 | return $self; | |||||||||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | 2 | ▶ | sub _load_user_dict { | ||||||||||||||||||||||||||
|
Subroutine
_load_user_dict: called CC=4 SCAR=15.0
| |||||||||||||||||||||||||||||
| 38 | 2 | my $self = shift; | |||||||||||||||||||||||||||
| 39 | 2 | my $home = $ENV{HOME}; | |||||||||||||||||||||||||||
| 40 | 2 | ▶ | return unless defined $home; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 41 | 2 | ▶ | return unless -d $home; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 42 | 2 | my $dictpath = File::Spec->catfile($home, '.spellunker.en'); | |||||||||||||||||||||||||||
| 43 | 2 | ▶ | if (-f $dictpath) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 44 | 0 | $self->load_dictionary($dictpath); | |||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | 24 | ▶ | sub load_dictionary { | ||||||||||||||||||||||||||
|
Subroutine
load_dictionary: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 49 | 24 | my ($self, $filename_or_fh) = @_; | |||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | 24 | my $fh; | |||||||||||||||||||||||||||
| 52 | 24 | ▶ | if (Scalar::Util::openhandle($filename_or_fh)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 53 | 4 | $fh = $filename_or_fh; | |||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||
| 55 | else { | ||||||||||||||||||||||||||||
| 56 | 20 | ▶ | open $fh, '<:utf8', $filename_or_fh | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 57 | or die "Cannot open '$filename_or_fh' for reading: $!"; | ||||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | 24 | local $/; | |||||||||||||||||||||||||||
| 61 | 24 | my $chunk = <$fh>; | |||||||||||||||||||||||||||
| 62 | 24 | $chunk =~ s/\#[^\n]*$//xmsg; # remove comments. | |||||||||||||||||||||||||||
| 63 | 24 | $self->add_stopwords(split ' ', $chunk); | |||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | 27 | ▶ | sub add_stopwords { | ||||||||||||||||||||||||||
|
Subroutine
add_stopwords: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 67 | 27 | my $self = shift; | |||||||||||||||||||||||||||
| 68 | 27 | for (@_) { | |||||||||||||||||||||||||||
| 69 | 1733996 | $self->{stopwords}->{$_}++ | |||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||
| 71 | 27 | return undef; | |||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | 1 | ▶ | sub clear_stopwords { | ||||||||||||||||||||||||||
|
Subroutine
clear_stopwords: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 75 | 1 | my $self = shift; | |||||||||||||||||||||||||||
| 76 | 1 | undef $self->{stopwords}; | |||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | 904 | ▶ | sub check_word { | ||||||||||||||||||||||||||
|
Subroutine
check_word: called CC=36 SCAR=36.0
Pod
documented
| |||||||||||||||||||||||||||||
| 80 | 904 | my ($self, $word) = @_; | |||||||||||||||||||||||||||
| 81 | 904 | ▶ | return 0 unless defined $word; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | 904 | ▶ | return 1 if length($word)==0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 84 | 896 | ▶ | return 1 if length($word)==1; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | # There is no alphabetical characters. | ||||||||||||||||||||||||||||
| 87 | 864 | ▶ | return 1 if $word !~ /[A-Za-z]/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | # git sha1 | ||||||||||||||||||||||||||||
| 90 | 857 | ▶ | return 1 if $word =~ /\A[a-z0-9]{40}\z/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | # 19xx 2xx | ||||||||||||||||||||||||||||
| 93 | 856 | ▶ | return 1 if $word =~ /^[0-9]+(xx|yy)$/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 94 | # 4th | ||||||||||||||||||||||||||||
| 95 | 853 | ▶ | return 1 if $word =~ /^[0-9]+(th)$/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | # Method name | ||||||||||||||||||||||||||||
| 98 | 852 | ▶ | return 1 if $word =~ /\A([a-zA-Z0-9]+_)+[a-zA-Z0-9]+\z/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | # Extensions | ||||||||||||||||||||||||||||
| 101 | 843 | ▶ | return 1 if $word =~ /\A\.[a-zA-Z0-9]{2,4}\z/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | # File name | ||||||||||||||||||||||||||||
| 104 | 835 | ▶ | return 1 if $word =~ /\A[a-zA-Z0-9-]+\.[a-zA-Z0-9]{1,4}\z/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||
| 106 | 833 | ▶ | return 1 if looks_like_domain($word); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 107 | 833 | ▶ | return 1 if looks_like_perl_code($word); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 108 | 789 | ▶ | return 1 if looks_like_file_path($word); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||
| 110 | # Ignore capital letter words like RT, RFC, IETF. | ||||||||||||||||||||||||||||
| 111 | # And so "IT'S" should be allow. | ||||||||||||||||||||||||||||
| 112 | # AUTHORS | ||||||||||||||||||||||||||||
| 113 | # APIs | ||||||||||||||||||||||||||||
| 114 | 782 | ▶ | return 1 if $word =~ /\A [A-Z']+ s? \z/x; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||
| 116 | # good | ||||||||||||||||||||||||||||
| 117 | 723 | ▶ | return 1 if $self->{stopwords}->{$word}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||
| 119 | # ucfirst-ed word. | ||||||||||||||||||||||||||||
| 120 | # 'How' | ||||||||||||||||||||||||||||
| 121 | # Dan | ||||||||||||||||||||||||||||
| 122 | 164 | ▶ | if ($word =~ /\A[A-Z][a-z]+\z/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 123 | 80 | return 1; | |||||||||||||||||||||||||||
| 124 | } | ||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||
| 126 | # CamelCase-ed word like "McCamant" | ||||||||||||||||||||||||||||
| 127 | 84 | ▶ | if ($word =~ /\A [A-Z][a-z]+ (?:[A-Z][a-z]+)+ \z/x) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 128 | 1 | return 1; | |||||||||||||||||||||||||||
| 129 | } | ||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||
| 131 | # Suffix rules | ||||||||||||||||||||||||||||
| 132 | 83 | ▶ | return 1 if $word =~ /\A | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$word =~ /\A
(.*?)
(?:
's # Dan's
| s' # cookies'
| 've # You've
| 're # We're
| 'll # You'll
| n't # doesn't
| 'd # You'd
| -ish # -ish
)
\z/x and $self->check_word($1)
MC/DC50%1/2
$word =~ /\A
(.*?)
(?:
's # Dan's
| s' # cookies'
| 've # You've
| 're # We're
| 'll # You'll
| n't # doesn't
| 'd # You'd
| -ish # -ish
)
\z/x and $self->check_word($1)
$word =~ /\A
(.*?)
(?:
's # Dan's
| s' # cookies'
| 've # You've
| 're # We're
| 'll # You'll
| n't # doesn't
| 'd # You'd
| -ish # -ish
)
\z/x
$self->check_word($1)
Truth table66%2/3
A and B
A= $word =~ /\A
(.*?)
(?:
's # Dan's
| s' # cookies'
| 've # You've
| 're # We're
| 'll # You'll
| n't # doesn't
| 'd # You'd
| -ish # -ish
)
\z/xB= $self->check_word($1)
| |||||||||||||||||||||||||||||
| 133 | (.*?) | ||||||||||||||||||||||||||||
| 134 | (?: | ||||||||||||||||||||||||||||
| 135 | 's # Dan's | ||||||||||||||||||||||||||||
| 136 | | s' # cookies' | ||||||||||||||||||||||||||||
| 137 | | 've # You've | ||||||||||||||||||||||||||||
| 138 | | 're # We're | ||||||||||||||||||||||||||||
| 139 | | 'll # You'll | ||||||||||||||||||||||||||||
| 140 | | n't # doesn't | ||||||||||||||||||||||||||||
| 141 | | 'd # You'd | ||||||||||||||||||||||||||||
| 142 | | -ish # -ish | ||||||||||||||||||||||||||||
| 143 | ) | ||||||||||||||||||||||||||||
| 144 | \z/x && $self->check_word($1); | ||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||
| 146 | # comE<gt> | ||||||||||||||||||||||||||||
| 147 | ## Prefixes | ||||||||||||||||||||||||||||
| 148 | 67 | ▶ | return 1 if $word =~ /\Anon-(.*)\z/ && $self->check_word($1); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$word =~ /\Anon-(.*)\z/ and $self->check_word($1)
MC/DC50%1/2
$word =~ /\Anon-(.*)\z/ and $self->check_word($1)
$word =~ /\Anon-(.*)\z/
$self->check_word($1)
Truth table66%2/3
A and B
A= $word =~ /\Anon-(.*)\z/B= $self->check_word($1)
| |||||||||||||||||||||||||||||
| 149 | 66 | ▶ | return 1 if $word =~ /\Are-(.*)\z/ && $self->check_word($1); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$word =~ /\Are-(.*)\z/ and $self->check_word($1)
MC/DC50%1/2
$word =~ /\Are-(.*)\z/ and $self->check_word($1)
$word =~ /\Are-(.*)\z/
$self->check_word($1)
Truth table66%2/3
A and B
A= $word =~ /\Are-(.*)\z/B= $self->check_word($1)
| |||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||
| 151 | # <p></p> | ||||||||||||||||||||||||||||
| 152 | 65 | ▶ | return 1 if $word =~ /\A<p>(.*)<\/p>\z/ && $self->check_word($1); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$word =~ m[\A<p>(.*)</p>\z] and $self->check_word($1)
MC/DC50%1/2
$word =~ m[\A<p>(.*)</p>\z] and $self->check_word($1)
$word =~ m[\A<p>(.*)</p>\z]
$self->check_word($1)
Truth table66%2/3
A and B
A= $word =~ m[\A<p>(.*)</p>\z]B= $self->check_word($1)
| |||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||
| 154 | # :Str - Moose-ish type definition | ||||||||||||||||||||||||||||
| 155 | 64 | ▶ | return 1 if $word =~ /\A | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 156 | : | ||||||||||||||||||||||||||||
| 157 | (?:[A-Z][a-z]+)+ | ||||||||||||||||||||||||||||
| 158 | \z/x; | ||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||
| 160 | # IRC channel name | ||||||||||||||||||||||||||||
| 161 | 63 | ▶ | return 1 if $word =~ /\A#[a-z0-9-]+\z/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||
| 163 | # Suffix | ||||||||||||||||||||||||||||
| 164 | 61 | ▶ | return 1 if $word =~ /\A(.*?)[^A-Za-z]+\z/ && $self->check_word($1); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$word =~ /\A(.*?)[^A-Za-z]+\z/ and $self->check_word($1)
MC/DC100%2/2
$word =~ /\A(.*?)[^A-Za-z]+\z/ and $self->check_word($1)
$word =~ /\A(.*?)[^A-Za-z]+\z/
$self->check_word($1)
Truth table100%3/3
A and B
A= $word =~ /\A(.*?)[^A-Za-z]+\z/B= $self->check_word($1)
| |||||||||||||||||||||||||||||
| 165 | # Prefix | ||||||||||||||||||||||||||||
| 166 | 35 | ▶ | return 1 if $word =~ /\A[^A-Za-z]+(.*?)\z/ && $self->check_word($1); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$word =~ /\A[^A-Za-z]+(.*?)\z/ and $self->check_word($1)
MC/DC100%2/2
$word =~ /\A[^A-Za-z]+(.*?)\z/ and $self->check_word($1)
$word =~ /\A[^A-Za-z]+(.*?)\z/
$self->check_word($1)
Truth table100%3/3
A and B
A= $word =~ /\A[^A-Za-z]+(.*?)\z/B= $self->check_word($1)
| |||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||
| 168 | 26 | ▶ | if ($word =~ /[^A-Za-z]+/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 169 | 11 | my @words = split /[^A-Za-z]+/, $word; | |||||||||||||||||||||||||||
| 170 | 11 | my $ok = 0; | |||||||||||||||||||||||||||
| 171 | 11 | for (@words) { | |||||||||||||||||||||||||||
| 172 | 31 | ▶ | if ($self->check_word($_)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 173 | 31 | $ok++; | |||||||||||||||||||||||||||
| 174 | } | ||||||||||||||||||||||||||||
| 175 | } | ||||||||||||||||||||||||||||
| 176 | 11 | ▶ | return 1 if @words == $ok; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 177 | } | ||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||
| 179 | 15 | return 0; | |||||||||||||||||||||||||||
| 180 | } | ||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||
| 182 | 797 | ▶ | sub looks_like_file_path { | ||||||||||||||||||||||||||
|
Subroutine
looks_like_file_path: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 183 | 797 | my ($word) = @_; | |||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||
| 185 | # ~/ | ||||||||||||||||||||||||||||
| 186 | # ~/foo/ | ||||||||||||||||||||||||||||
| 187 | # ~foo/ | ||||||||||||||||||||||||||||
| 188 | # /dev/tty | ||||||||||||||||||||||||||||
| 189 | # t/01_simple.t | ||||||||||||||||||||||||||||
| 190 | 797 | ▶ | return 1 if $word =~ m{\A | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 191 | (?: | ||||||||||||||||||||||||||||
| 192 | ~ [a-zA-Z0-9_.-]* / (?: [a-z0-9A-Z_.-]+ / )* (?: [a-z0-9A-Z_.-]+ )? | ||||||||||||||||||||||||||||
| 193 | | | ||||||||||||||||||||||||||||
| 194 | / (?: [a-z0-9A-Z_.-]+ / )* (?: [a-z0-9A-Z_.]+ )? | ||||||||||||||||||||||||||||
| 195 | | | ||||||||||||||||||||||||||||
| 196 | (?: [a-z0-9A-Z_.-]+ / )+ (?: [a-z0-9A-Z_.]+ )? | ||||||||||||||||||||||||||||
| 197 | ) | ||||||||||||||||||||||||||||
| 198 | \z}x; | ||||||||||||||||||||||||||||
| 199 | 783 | return 0; | |||||||||||||||||||||||||||
| 200 | } | ||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||
| 202 | 833 | ▶ | sub looks_like_domain { | ||||||||||||||||||||||||||
|
Subroutine
looks_like_domain: called CC=2 SCAR=7.1
Pod
undocumented
| |||||||||||||||||||||||||||||
| 203 | 833 | my ($word) = @_; | |||||||||||||||||||||||||||
| 204 | 833 | ▶ | return 1 if $word =~ /\A | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 205 | ([a-zA-Z0-9]([a-zA-Z0-9\-]{0,61}[a-zA-Z0-9])?\.)+[a-zA-Z]{2,6} | ||||||||||||||||||||||||||||
| 206 | \z/x; | ||||||||||||||||||||||||||||
| 207 | 833 | return 0; | |||||||||||||||||||||||||||
| 208 | } | ||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||
| 210 | 208 | ▶ | sub check_line { | ||||||||||||||||||||||||||
|
Subroutine
check_line: called CC=10 SCAR=23.1
Pod
documented
| |||||||||||||||||||||||||||||
| 211 | 208 | my ($self, $line) = @_; | |||||||||||||||||||||||||||
| 212 | 208 | ▶ | return unless defined $line; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 213 | |||||||||||||||||||||||||||||
| 214 | 208 | $line =~ s!<$MAIL_REGEX>|$MAIL_REGEX!!; # Remove E-mail address. | |||||||||||||||||||||||||||
| 215 | 208 | $line =~ s!$RE{URI}{HTTP}{-scheme => 'https?'}!!g; # Remove HTTPS? URI | |||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||
| 217 | 208 | my @bad_words; | |||||||||||||||||||||||||||
| 218 | 208 | for ( grep /\S/, split /[\|*=\[\]`" \t,?!]+/, $line) { | |||||||||||||||||||||||||||
| 219 | 796 | s/\n//; | |||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||
| 221 | 796 | ▶ | if (/\A'(.*)'\z/) { | ||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||
| 222 | 4 | push @bad_words, $self->check_line($1); | |||||||||||||||||||||||||||
| 223 | } elsif (/\A(.*)\.\z/) { # The word ended by dot | ||||||||||||||||||||||||||||
| 224 | 54 | my $word = $1; | |||||||||||||||||||||||||||
| 225 | 54 | ▶ | $self->check_word($word) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 226 | or push @bad_words, $word; | ||||||||||||||||||||||||||||
| 227 | } elsif (/\./) { # The word includes dot | ||||||||||||||||||||||||||||
| 228 | 14 | ▶ | $self->check_word($_) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 229 | or push @bad_words, $_; | ||||||||||||||||||||||||||||
| 230 | } else { | ||||||||||||||||||||||||||||
| 231 | # Ignore command line options | ||||||||||||||||||||||||||||
| 232 | 724 | ▶ | next if /\A | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 233 | -- | ||||||||||||||||||||||||||||
| 234 | (?: [a-z]+ - )+ | ||||||||||||||||||||||||||||
| 235 | [a-z]+ | ||||||||||||||||||||||||||||
| 236 | \z/x; | ||||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||
| 238 | 723 | ▶ | $self->check_word($_) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 239 | or push @bad_words, $_; | ||||||||||||||||||||||||||||
| 240 | } | ||||||||||||||||||||||||||||
| 241 | } | ||||||||||||||||||||||||||||
| 242 | 208 | return @bad_words; | |||||||||||||||||||||||||||
| 243 | } | ||||||||||||||||||||||||||||
| 244 | |||||||||||||||||||||||||||||
| 245 | 848 | ▶ | sub looks_like_perl_code { | ||||||||||||||||||||||||||
|
Subroutine
looks_like_perl_code: called CC=12 SCAR=24.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 246 | 848 | my $PERL_NAME = '[A-Za-z_][A-Za-z0-9_]*'; | |||||||||||||||||||||||||||
| 247 | |||||||||||||||||||||||||||||
| 248 | # Class name | ||||||||||||||||||||||||||||
| 249 | # Foo::Bar | ||||||||||||||||||||||||||||
| 250 | # JSON::PP:: | ||||||||||||||||||||||||||||
| 251 | 848 | ▶ | return 1 if $_[0] =~ /\A | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 252 | [\+\$]? | ||||||||||||||||||||||||||||
| 253 | (?: $PERL_NAME :: )+ | ||||||||||||||||||||||||||||
| 254 | $PERL_NAME | ||||||||||||||||||||||||||||
| 255 | $PERL_NAME? | ||||||||||||||||||||||||||||
| 256 | \z/x; | ||||||||||||||||||||||||||||
| 257 | |||||||||||||||||||||||||||||
| 258 | # foo() | ||||||||||||||||||||||||||||
| 259 | 836 | ▶ | return 1 if $_[0] =~ /\A | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 260 | $PERL_NAME | ||||||||||||||||||||||||||||
| 261 | \( | ||||||||||||||||||||||||||||
| 262 | \s* | ||||||||||||||||||||||||||||
| 263 | ( \$ $PERL_NAME \s* , \s* )* | ||||||||||||||||||||||||||||
| 264 | ( \$ $PERL_NAME )? | ||||||||||||||||||||||||||||
| 265 | \s* | ||||||||||||||||||||||||||||
| 266 | \) | ||||||||||||||||||||||||||||
| 267 | \z/x; | ||||||||||||||||||||||||||||
| 268 | |||||||||||||||||||||||||||||
| 269 | # 5.8.x | ||||||||||||||||||||||||||||
| 270 | # 5.10.x | ||||||||||||||||||||||||||||
| 271 | 830 | ▶ | return 1 if $_[0] =~ /\A | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 272 | [0-9]+\.[0-9]+\.x | ||||||||||||||||||||||||||||
| 273 | \z/x; | ||||||||||||||||||||||||||||
| 274 | |||||||||||||||||||||||||||||
| 275 | # U+002F | ||||||||||||||||||||||||||||
| 276 | 828 | ▶ | return 1 if $_[0] =~ /\A | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 277 | U \+ [0-9a-fA-F]{4,} | ||||||||||||||||||||||||||||
| 278 | \z/x; | ||||||||||||||||||||||||||||
| 279 | |||||||||||||||||||||||||||||
| 280 | # \x00-\x1f\x22\x2f\x5c | ||||||||||||||||||||||||||||
| 281 | # \x2f | ||||||||||||||||||||||||||||
| 282 | 827 | ▶ | return 1 if $_[0] =~ /\A | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 283 | ( | ||||||||||||||||||||||||||||
| 284 | \\ x [0-9a-fA-F][0-9a-fA-F] -? | ||||||||||||||||||||||||||||
| 285 | )+ | ||||||||||||||||||||||||||||
| 286 | \z/x; | ||||||||||||||||||||||||||||
| 287 | |||||||||||||||||||||||||||||
| 288 | # $foo | ||||||||||||||||||||||||||||
| 289 | # %foo | ||||||||||||||||||||||||||||
| 290 | # @foo | ||||||||||||||||||||||||||||
| 291 | # *foo | ||||||||||||||||||||||||||||
| 292 | # \$foo | ||||||||||||||||||||||||||||
| 293 | 825 | ▶ | return 1 if $_[0] =~ /\A | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 294 | \\? | ||||||||||||||||||||||||||||
| 295 | [\*\@\$\%] | ||||||||||||||||||||||||||||
| 296 | $PERL_NAME | ||||||||||||||||||||||||||||
| 297 | \z/x; | ||||||||||||||||||||||||||||
| 298 | |||||||||||||||||||||||||||||
| 299 | # Spellunker->bar | ||||||||||||||||||||||||||||
| 300 | # Foo::Bar->bar | ||||||||||||||||||||||||||||
| 301 | # $foo->bar | ||||||||||||||||||||||||||||
| 302 | # $foo->bar() | ||||||||||||||||||||||||||||
| 303 | 806 | ▶ | return 1 if $_[0] =~ /\A | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 304 | (?: | ||||||||||||||||||||||||||||
| 305 | \$ $PERL_NAME | ||||||||||||||||||||||||||||
| 306 | | ( $PERL_NAME :: )* $PERL_NAME | ||||||||||||||||||||||||||||
| 307 | ) | ||||||||||||||||||||||||||||
| 308 | -> | ||||||||||||||||||||||||||||
| 309 | $PERL_NAME | ||||||||||||||||||||||||||||
| 310 | (?:\([^\)]*\))? | ||||||||||||||||||||||||||||
| 311 | \z/x; | ||||||||||||||||||||||||||||
| 312 | |||||||||||||||||||||||||||||
| 313 | # hash access | ||||||||||||||||||||||||||||
| 314 | 791 | ▶ | return 1 if $_[0] =~ /\A | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 315 | \$ $PERL_NAME \{ $PERL_NAME \} | ||||||||||||||||||||||||||||
| 316 | \z/x; | ||||||||||||||||||||||||||||
| 317 | |||||||||||||||||||||||||||||
| 318 | # hashref access | ||||||||||||||||||||||||||||
| 319 | 790 | ▶ | return 1 if $_[0] =~ /\A | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 320 | \$ $PERL_NAME -> \{ $PERL_NAME \} | ||||||||||||||||||||||||||||
| 321 | \z/x; | ||||||||||||||||||||||||||||
| 322 | |||||||||||||||||||||||||||||
| 323 | # JSON::XS-ish boolean value | ||||||||||||||||||||||||||||
| 324 | 789 | ▶ | return 1 if $_[0] eq '\1' || $_[0] eq '\1'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$_[0] eq "\\1" or $_[0] eq "\\1"
MC/DC0%0/2
$_[0] eq "\\1" or $_[0] eq "\\1"
$_[0] eq "\\1"
$_[0] eq "\\1"
Truth table33%1/3
A or B
A= $_[0] eq "\\1"B= $_[0] eq "\\1"
| |||||||||||||||||||||||||||||
| 325 | |||||||||||||||||||||||||||||
| 326 | 789 | return 0; | |||||||||||||||||||||||||||
| 327 | } | ||||||||||||||||||||||||||||
| 328 | |||||||||||||||||||||||||||||
| 329 | 11 | 1; | |||||||||||||||||||||||||||
| 330 | __END__ | ||||||||||||||||||||||||||||