File Coverage

blib/lib/Chess/Opening/Book/Move.pm
Criterion Covered Total %
statement 16 23 69.5
branch 5 8 62.5
condition 5 8 62.5
subroutine 6 7 85.7
pod 5 5 100.0
total 37 51 72.5


line stmt bran cond sub pod time code
1             #! /bin/false
2              
3             # Copyright (C) 2019 Guido Flohr ,
4             # all rights reserved.
5              
6             # This program is free software. It comes without any warranty, to
7             # the extent permitted by applicable law. You can redistribute it
8             # and/or modify it under the terms of the Do What the Fuck You Want
9             # to Public License, Version 2, as published by Sam Hocevar. See
10             # http://www.wtfpl.net/ for more details.
11              
12             package Chess::Opening::Book::Move;
13             $Chess::Opening::Book::Move::VERSION = '0.3';
14 3     3   22 use common::sense;
  3         7  
  3         16  
15              
16 3     3   168 use Locale::TextDomain 'com.cantanea.Chess-Opening';
  3         7  
  3         17  
17              
18             sub new {
19 288     288 1 710 my ($class, %args) = @_;
20              
21 288 50       596 if (!exists $args{move}) {
22 0         0 require Carp;
23 0         0 Carp::croak(__x("the named argument '{arg}' is required",
24             arg => 'move'));
25             }
26 288 50       821 if ($args{move} !~ /^[a-h][1-8][a-h][1-8][qrbn]?$/) {
27 0         0 require Carp;
28 0         0 Carp::croak(__x("invalid move '{move}'",
29             move => '$args{move}'));
30             }
31 288 50 66     1269 if (exists $args{count} && $args{count}
      33        
32             && $args{count} !~ /^[1-9][0-9]*$/) {
33 0         0 require Carp;
34 0         0 Carp::croak(__"count must be a positive integer");
35             }
36 288   100     619 $args{count} ||= 1;
37 288 100       589 $args{learn} = '0' if !exists $args{learn};
38              
39             bless {
40             __move => $args{move},
41             __count => $args{count},
42             __learn => $args{learn},
43 288         1252 }, $class;
44             }
45              
46 0     0 1 0 sub weight { shift->{__count} }
47 310     310 1 720 sub count { shift->{__count} }
48 22     22 1 10376 sub move { shift->{__move} }
49 22     22 1 124 sub learn { shift->{__learn} }
50              
51             1;