line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# $Id: /mirror/perl/Data-Validate-Japanese/trunk/lib/Data/Validate/Japanese.pm 2553 2007-09-19T01:14:58.848056Z daisuke $ |
2
|
|
|
|
|
|
|
# |
3
|
|
|
|
|
|
|
# Copyright (c) 2007 Daisuke Maki |
4
|
|
|
|
|
|
|
# All rights reserved. |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
package Data::Validate::Japanese; |
7
|
3
|
|
|
3
|
|
212463
|
use strict; |
|
3
|
|
|
|
|
10
|
|
|
3
|
|
|
|
|
101
|
|
8
|
3
|
|
|
3
|
|
20
|
use warnings; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
82
|
|
9
|
3
|
|
|
3
|
|
109
|
use 5.008; |
|
3
|
|
|
|
|
17
|
|
|
3
|
|
|
|
|
132
|
|
10
|
3
|
|
|
3
|
|
18
|
use vars qw($VERSION); |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
306
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
$VERSION = '0.01001'; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
my %regexps = ( |
15
|
3
|
|
|
3
|
|
3324
|
katakana => qr(\p{InKatakana}), |
|
3
|
|
|
|
|
32
|
|
|
3
|
|
|
|
|
46
|
|
16
|
|
|
|
|
|
|
hiragana => qr(\p{InHiragana}), |
17
|
|
|
|
|
|
|
kanji => qr(\p{InCJKUnifiedIdeographs}), |
18
|
|
|
|
|
|
|
h_katakana => qr(\p{InHalfwidthAndFullwidthForms}), |
19
|
|
|
|
|
|
|
ascii => qr([[:ascii]]) |
20
|
|
|
|
|
|
|
); |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub new |
23
|
|
|
|
|
|
|
{ |
24
|
3
|
|
|
3
|
1
|
54
|
bless {}, shift; |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
{ |
28
|
|
|
|
|
|
|
foreach my $type (keys %regexps) { |
29
|
0
|
|
|
0
|
1
|
0
|
eval <<" EOSUB"; |
|
0
|
|
|
0
|
1
|
0
|
|
|
0
|
|
|
6
|
1
|
0
|
|
|
0
|
|
|
6
|
1
|
0
|
|
|
6
|
|
|
6
|
1
|
2610
|
|
|
6
|
|
|
|
|
35
|
|
|
6
|
|
|
|
|
3335
|
|
|
6
|
|
|
|
|
31
|
|
|
6
|
|
|
|
|
3760
|
|
|
6
|
|
|
|
|
30
|
|
30
|
|
|
|
|
|
|
sub is_$type { |
31
|
|
|
|
|
|
|
my (\$self, \$value, \$opts) = \@_; |
32
|
|
|
|
|
|
|
\$self->contains_only(\$value, { $type => 1 }); |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
EOSUB |
35
|
|
|
|
|
|
|
die if $@; |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
sub contains_only |
40
|
|
|
|
|
|
|
{ |
41
|
18
|
|
|
18
|
1
|
28
|
my ($self, $value, $opts) = @_; |
42
|
18
|
|
50
|
|
|
48
|
$opts ||= {}; |
43
|
|
|
|
|
|
|
|
44
|
18
|
|
|
|
|
20
|
my $re = do { |
45
|
18
|
|
|
|
|
98
|
my $str = sprintf( |
46
|
|
|
|
|
|
|
'^(?:%s)$', |
47
|
18
|
|
|
|
|
53
|
join('|', map { "$regexps{$_}+" } grep { $opts->{$_} } keys %regexps) |
|
90
|
|
|
|
|
128
|
|
48
|
|
|
|
|
|
|
); |
49
|
18
|
|
|
|
|
137
|
qr($str); |
50
|
|
|
|
|
|
|
}; |
51
|
|
|
|
|
|
|
|
52
|
18
|
|
|
|
|
673
|
return $value =~ /$re/; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
1; |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
__END__ |