| 1 | package xt::Util; | ||||||||||||||
| 2 | 13 | ▶ | use strict; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 3 | 13 | ▶ | use warnings; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 4 | 13 | ▶ | use Exporter qw/import/; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 5 | 13 | ▶ | use Time::Piece qw/gmtime/; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 6 | |||||||||||||||
| 7 | 13 | our %EXPORT_TAGS = ( | |||||||||||||
| 8 | cmp_deeply => [qw( | ||||||||||||||
| 9 | cmp_deeply | ||||||||||||||
| 10 | hash | ||||||||||||||
| 11 | array_of_hashes | ||||||||||||||
| 12 | uri | ||||||||||||||
| 13 | integer | ||||||||||||||
| 14 | real | ||||||||||||||
| 15 | datetime | ||||||||||||||
| 16 | game_result | ||||||||||||||
| 17 | user_name | ||||||||||||||
| 18 | user_rank | ||||||||||||||
| 19 | )], | ||||||||||||||
| 20 | ); | ||||||||||||||
| 21 | |||||||||||||||
| 22 | 13 | our @EXPORT_OK = ( 'build_gokgs', map { @$_ } values %EXPORT_TAGS ); | |||||||||||||
| 23 | |||||||||||||||
| 24 | 0 | ▶ | sub build_gokgs { | ||||||||||||
|
Subroutine
build_gokgs: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||
| 25 | 0 | my $gokgs = do { | |||||||||||||
| 26 | 0 | ▶ | if ( $ENV{WWW_GOKGS_LIBXML} ) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 27 | 0 | require WWW::GoKGS::LibXML; | |||||||||||||
| 28 | 0 | WWW::GoKGS::LibXML->new( from => 'anazawa@cpan.org' ); | |||||||||||||
| 29 | } | ||||||||||||||
| 30 | else { | ||||||||||||||
| 31 | 0 | require WWW::GoKGS; | |||||||||||||
| 32 | 0 | WWW::GoKGS->new( from => 'anazawa@cpan.org' ); | |||||||||||||
| 33 | } | ||||||||||||||
| 34 | }; | ||||||||||||||
| 35 | |||||||||||||||
| 36 | 0 | $gokgs->user_agent->delay( 1/60 ); | |||||||||||||
| 37 | |||||||||||||||
| 38 | 0 | $gokgs; | |||||||||||||
| 39 | } | ||||||||||||||
| 40 | |||||||||||||||
| 41 | 0 | ▶ | sub cmp_deeply { | ||||||||||||
|
Subroutine
cmp_deeply: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||
| 42 | 0 | my ( $got, $expected, $name ) = @_; | |||||||||||||
| 43 | |||||||||||||||
| 44 | Test::More::subtest( | ||||||||||||||
| 45 | $name || 'unknown', | ||||||||||||||
| 46 | 0 | ▶ | sub { $expected->( $got ) } | ||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||
| 47 | 0 | ▶ | ); | ||||||||||||
|
Condition0%0/2
$name || 'unknown'
MC/DC0%0/1
$name || 'unknown'
$name
Truth table0%0/2
A
A= $name
| |||||||||||||||
| 48 | |||||||||||||||
| 49 | 0 | return; | |||||||||||||
| 50 | } | ||||||||||||||
| 51 | |||||||||||||||
| 52 | 0 | ▶ | sub hash { | ||||||||||||
|
Subroutine
hash: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||
| 53 | 0 | my %expected = @_; | |||||||||||||
| 54 | |||||||||||||||
| 55 | 0 | ▶ | sub { | ||||||||||||
|
Subroutine
__ANON__: not called CC=8 SCAR=42.8
| |||||||||||||||
| 56 | 0 | my $got = shift; | |||||||||||||
| 57 | 0 | ▶ | my $name = shift || '$hash'; | ||||||||||||
|
Condition0%0/2
shift() || '$hash'
MC/DC0%0/1
shift() || '$hash'
shift()
Truth table0%0/2
A
A= shift()
| |||||||||||||||
| 58 | |||||||||||||||
| 59 | 0 | Test::More::isa_ok( $got, 'HASH', $name ); | |||||||||||||
| 60 | |||||||||||||||
| 61 | 0 | for my $key ( keys %$got ) { | |||||||||||||
| 62 | 0 | my $value = $got->{$key}; | |||||||||||||
| 63 | 0 | my $n = "$name\->{$key}"; | |||||||||||||
| 64 | |||||||||||||||
| 65 | 0 | ▶ | if ( ref $expected{$key} eq 'CODE' ) { | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 66 | 0 | local $_ = $value; | |||||||||||||
| 67 | 0 | my $bool = $expected{$key}->( $value, $n ); | |||||||||||||
| 68 | 0 | ▶ | Test::More::ok( $bool, $n ) if defined $bool; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 69 | } | ||||||||||||||
| 70 | elsif ( ref $expected{$key} eq 'ARRAY' ) { | ||||||||||||||
| 71 | 0 | for my $e ( @{$expected{$key}} ) { | |||||||||||||
| 72 | 0 | local $_ = $value; | |||||||||||||
| 73 | 0 | my $bool = $e->( $value, $n ); | |||||||||||||
| 74 | 0 | ▶ | Test::More::ok( $bool, $n ) if defined $bool; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 75 | } | ||||||||||||||
| 76 | } | ||||||||||||||
| 77 | } | ||||||||||||||
| 78 | |||||||||||||||
| 79 | 0 | return; | |||||||||||||
| 80 | 0 | }; | |||||||||||||
| 81 | } | ||||||||||||||
| 82 | |||||||||||||||
| 83 | 0 | ▶ | sub array_of_hashes { | ||||||||||||
|
Subroutine
array_of_hashes: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||
| 84 | 0 | my $expected = hash( @_ ); | |||||||||||||
| 85 | |||||||||||||||
| 86 | 0 | ▶ | sub { | ||||||||||||
|
Subroutine
__ANON__: not called CC=4 SCAR=30.0
| |||||||||||||||
| 87 | 0 | my $got = shift; | |||||||||||||
| 88 | 0 | ▶ | my $name = shift || '$array'; | ||||||||||||
|
Condition0%0/2
shift() || '$array'
MC/DC0%0/1
shift() || '$array'
shift()
Truth table0%0/2
A
A= shift()
| |||||||||||||||
| 89 | |||||||||||||||
| 90 | 0 | Test::More::isa_ok( $got, 'ARRAY', $name ); | |||||||||||||
| 91 | |||||||||||||||
| 92 | 0 | my $i = 0; | |||||||||||||
| 93 | 0 | for my $g ( @$got ) { | |||||||||||||
| 94 | 0 | local $_ = $g; | |||||||||||||
| 95 | 0 | my $n = "$name\->[$i]"; | |||||||||||||
| 96 | 0 | my $bool = $expected->( $g, $n ); | |||||||||||||
| 97 | 0 | ▶ | Test::More::ok( $bool, $n ) if defined $bool; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 98 | 0 | $i++; | |||||||||||||
| 99 | } | ||||||||||||||
| 100 | |||||||||||||||
| 101 | 0 | return; | |||||||||||||
| 102 | 0 | }; | |||||||||||||
| 103 | } | ||||||||||||||
| 104 | |||||||||||||||
| 105 | 0 | ▶ | sub uri { | ||||||||||||
|
Subroutine
uri: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||
| 106 | 0 | ▶ | sub { | ||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||
| 107 | 0 | my ( $got, $name ) = @_; | |||||||||||||
| 108 | 0 | Test::More::isa_ok( $got, 'URI', $name ); | |||||||||||||
| 109 | 0 | return; | |||||||||||||
| 110 | 0 | }; | |||||||||||||
| 111 | } | ||||||||||||||
| 112 | |||||||||||||||
| 113 | 0 | ▶ | sub integer { | ||||||||||||
|
Subroutine
integer: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||
| 114 | 0 | ▶ | sub { | ||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||
| 115 | 0 | my ( $got, $name ) = @_; | |||||||||||||
| 116 | |||||||||||||||
| 117 | 0 | Test::More::like( | |||||||||||||
| 118 | $got, | ||||||||||||||
| 119 | qr{^(?:0|\-?[1-9][0-9]*)$}, | ||||||||||||||
| 120 | "'$name' should be integer" | ||||||||||||||
| 121 | ); | ||||||||||||||
| 122 | |||||||||||||||
| 123 | 0 | return; | |||||||||||||
| 124 | 0 | }; | |||||||||||||
| 125 | } | ||||||||||||||
| 126 | |||||||||||||||
| 127 | 0 | ▶ | sub real { | ||||||||||||
|
Subroutine
real: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||
| 128 | 0 | ▶ | sub { | ||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||
| 129 | 0 | my ( $got, $name ) = @_; | |||||||||||||
| 130 | |||||||||||||||
| 131 | 0 | Test::More::like( | |||||||||||||
| 132 | $got, | ||||||||||||||
| 133 | qr{^(?:0|\-?[1-9][0-9]*(?:\.[0-9]*[1-9])?)$}, | ||||||||||||||
| 134 | "'$name' should be real" | ||||||||||||||
| 135 | ); | ||||||||||||||
| 136 | |||||||||||||||
| 137 | 0 | return; | |||||||||||||
| 138 | 0 | }; | |||||||||||||
| 139 | } | ||||||||||||||
| 140 | |||||||||||||||
| 141 | 0 | ▶ | sub datetime { | ||||||||||||
|
Subroutine
datetime: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||
| 142 | 0 | my $format = shift; | |||||||||||||
| 143 | |||||||||||||||
| 144 | 0 | ▶ | sub { | ||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||
| 145 | 0 | my ( $got, $name ) = @_; | |||||||||||||
| 146 | 0 | eval { gmtime->strptime( $got, $format ) }; | |||||||||||||
| 147 | 0 | Test::More::ok( !$@, "'$name' ($got) should be '$format': $@" ); | |||||||||||||
| 148 | 0 | return; | |||||||||||||
| 149 | 0 | }; | |||||||||||||
| 150 | } | ||||||||||||||
| 151 | |||||||||||||||
| 152 | 0 | ▶ | sub game_result { | ||||||||||||
|
Subroutine
game_result: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||
| 153 | 0 | ▶ | sub { | ||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||
| 154 | 0 | my ( $got, $name ) = @_; | |||||||||||||
| 155 | |||||||||||||||
| 156 | 0 | Test::More::like( | |||||||||||||
| 157 | $got, | ||||||||||||||
| 158 | qr{^(?: | ||||||||||||||
| 159 | Unfinished | ||||||||||||||
| 160 | | Draw | ||||||||||||||
| 161 | | (?:B|W)\+(?: | ||||||||||||||
| 162 | Resign | ||||||||||||||
| 163 | | Forfeit | ||||||||||||||
| 164 | | Time | ||||||||||||||
| 165 | | (?:0|[1-9][0-9]*)(?:\.5)? ) | ||||||||||||||
| 166 | )$}x, | ||||||||||||||
| 167 | $name | ||||||||||||||
| 168 | ); | ||||||||||||||
| 169 | |||||||||||||||
| 170 | 0 | return; | |||||||||||||
| 171 | 0 | }; | |||||||||||||
| 172 | } | ||||||||||||||
| 173 | |||||||||||||||
| 174 | 0 | ▶ | sub user_name { | ||||||||||||
|
Subroutine
user_name: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||
| 175 | 0 | ▶ | sub { | ||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||
| 176 | 0 | my ( $got, $name ) = @_; | |||||||||||||
| 177 | 0 | Test::More::like( $got, qr/^[a-zA-Z][a-zA-Z0-9]{0,9}$/, $name ); | |||||||||||||
| 178 | 0 | return; | |||||||||||||
| 179 | 0 | }; | |||||||||||||
| 180 | } | ||||||||||||||
| 181 | |||||||||||||||
| 182 | 0 | ▶ | sub user_rank { | ||||||||||||
|
Subroutine
user_rank: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||
| 183 | 0 | ▶ | sub { | ||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||
| 184 | 0 | my ( $got, $name ) = @_; | |||||||||||||
| 185 | |||||||||||||||
| 186 | 0 | Test::More::like( | |||||||||||||
| 187 | $got, | ||||||||||||||
| 188 | qr{^(?: | ||||||||||||||
| 189 | \- | ||||||||||||||
| 190 | | \? | ||||||||||||||
| 191 | | [1-9](?:p|d\??|k\??) | ||||||||||||||
| 192 | | [12][0-9]k\?? | ||||||||||||||
| 193 | | 30k\?? | ||||||||||||||
| 194 | )$}x, | ||||||||||||||
| 195 | $name | ||||||||||||||
| 196 | ); | ||||||||||||||
| 197 | |||||||||||||||
| 198 | 0 | return; | |||||||||||||
| 199 | 0 | }; | |||||||||||||
| 200 | } | ||||||||||||||
| 201 | |||||||||||||||
| 202 | 13 | 1; | |||||||||||||