blib/lib/Data/Validate/Japanese.pm

filter: Statementstmt 89.1% 33 / 37 Branchbran 50.0% 1 / 2 Conditioncond 50.0% 1 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 81.8% 9 / 11 Podpod 100% 7 / 7 totaltotal 85.0% 51 / 60 CC 2 SCAR 1.7
CC
2
Cov
85%
contains_only
2.0
is_ascii
1.0
is_h_katakana
1.0
CRAP 1.2
↑ Summary
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 <daisuke@endeworks.jp>
4 # All rights reserved.
5  
6 package Data::Validate::Japanese;
7 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 3 ▶use 5.008;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 3 ▶use vars qw($VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 3 $VERSION = '0.01001';
13  
14 3 my %regexps = (
15 katakana => qr(\p{InKatakana}),
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 3 ▶{
Subroutine new: called CC=1 SCAR=0.0
Pod documented
24 3 bless {}, shift;
25 }
26  
27 {
28 3 foreach my $type (keys %regexps) {
29 0 ▶ eval <<" EOSUB";
Subroutine is_ascii: not called CC=1 SCAR=0.5
Subroutine is_h_katakana: not called CC=1 SCAR=0.5
Subroutine is_hiragana: called CC=1 SCAR=0.5
Subroutine is_kanji: called CC=1 SCAR=0.5
Subroutine is_katakana: called CC=1 SCAR=0.5
Pod documented
Pod documented
Pod documented
Pod documented
Pod documented
30 sub is_$type {
31 my (\$self, \$value, \$opts) = \@_;
32 \$self->contains_only(\$value, { $type => 1 });
33 }
34 EOSUB
35 15 ▶ die if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 15 15
36 }
37 }
38  
39 sub contains_only
40 18 ▶{
Subroutine contains_only: called CC=2 SCAR=7.0
Pod documented
41 18 my ($self, $value, $opts) = @_;
42 18 ▶ $opts ||= {};
Condition50%1/2
$opts ||= {}
l!l
180
MC/DC0%0/1
$opts ||= {}
$opts
Truth table50%1/2
A
A= $opts
Aresult
11
00
43  
44 18 my $re = do {
45 my $str = sprintf(
46 '^(?:%s)$',
47 18 join('|', map { "$regexps{$_}+" } grep { $opts->{$_} } keys %regexps)
48 );
49 18 qr($str);
50 };
51  
52 18 return $value =~ /$re/;
53 }
54  
55 3 1;
56  
57 __END__
↑ Summary