File Coverage

blib/lib/Chess/Opening/Book/Entry.pm
Criterion Covered Total %
statement 24 30 80.0
branch 4 8 50.0
condition 3 6 50.0
subroutine 9 9 100.0
pod 6 6 100.0
total 46 59 77.9


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::Entry;
13             $Chess::Opening::Book::Entry::VERSION = '0.3';
14 3     3   25 use common::sense;
  3         6  
  3         28  
15              
16 3     3   182 use Locale::TextDomain 'com.cantanea.Chess-Opening';
  3         9  
  3         18  
17              
18 3     3   1688 use Chess::Opening::Book::Move;
  3         8  
  3         1456  
19              
20             sub new {
21 114     114 1 105658 my ($class, $fen) = @_;
22              
23 114         556 bless {
24             __fen => $fen,
25             __moves => {},
26             __count => 0,
27             }, $class;
28             }
29              
30             sub addMove {
31 288     288 1 1410 my ($self, %args) = @_;
32              
33 288 50       638 if (!exists $args{move}) {
34 0         0 require Carp;
35 0         0 Carp::croak(__x("the named argument '{arg}' is required",
36             arg => 'move'));
37             }
38 288 50       1060 if ($args{move} !~ /^[a-h][1-8][a-h][1-8][qrbn]?$/) {
39 0         0 require Carp;
40 0         0 Carp::croak(__x("invalid move '{move}'",
41             move => '$args{move}'));
42             }
43 288 50       592 $args{count} = $args{weight} if exists $args{weight};
44 288 50 66     1556 if (exists $args{count} && $args{count}
      33        
45             && $args{count} !~ /^[1-9][0-9]*$/) {
46 0         0 require Carp;
47 0         0 Carp::croak(__"count must be a positive integer");
48             }
49              
50 288         976 my $move = Chess::Opening::Book::Move->new(%args);
51 288         679 $self->{__moves}->{$args{move}} = $move;
52 288         678 $self->{__counts} += $move->count;
53              
54 288         811 return $self;
55             }
56              
57 2     2 1 1914 sub fen { shift->{__fen} }
58 2     2 1 1175 sub moves { shift->{__moves} }
59 2     2 1 1269 sub counts { shift->{__counts} }
60 2     2 1 1073 sub weights { shift->{__counts} }
61              
62             1;