blib/lib/Games/Cards/Troika/Util.pm

filter: Statementstmt 51.1% 22 / 43 Branchbran 0.0% 0 / 8 Conditioncond 0.0% 0 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 71.4% 5 / 7 Podpod 100% 1 / 1 totaltotal 45.1% 28 / 62 CC 6 SCAR 26.3
CC
6
Cov
42%
troika_list_cards
30.0
__ANON__
6.0
BEGIN
1.0
CRAP 13.9
↑ Summary
1 package Games::Cards::Troika::Util;
2  
3 1 ▶use 5.010001;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 1 ▶use List::Util qw(shuffle);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use Perinci::Sub::Util qw(gen_modified_sub);
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 1 our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY
11 1 our $DATE = '2026-07-16'; # DATE
12 1 our $DIST = 'Games-Cards-Troika-Util'; # DIST
13 1 our $VERSION = '0.002'; # VERSION
14  
15 1 our %SPEC;
16  
17 $SPEC{troika_list_cards} = {
18 1 v => 1.1,
19 summary => 'Return the list of cards',
20 args => {
21 lang => {schema => ['str*', in=>['eng', 'ind', 'fra'], default=>'eng']},
22 descriptive => {schema => 'bool*'},
23 detail => {schema => 'bool*'},
24 },
25 args_rels => {
26 choose_one => [qw/descriptive detail/],
27 },
28 };
29 0 ▶sub troika_list_cards {
Subroutine troika_list_cards: not called CC=5 SCAR=34.0
Pod documented
30 0 my %args = @_;
31  
32 0 ▶ my $lang = $args{lang} // 'eng';
Condition0%0/2
$args{"lang"} // "eng"
l!l
00
MC/DC0%0/1
$args{"lang"} // "eng"
$args{"lang"}
Truth table0%0/2
A
A= $args{"lang"}
Aresult
11
00
33  
34 0 require TableData::Games::Cards::Troika;
35 0 my $t = TableData::Games::Cards::Troika->new;
36  
37 0 my @rows;
38 0 ▶ while ($t->has_next_row) {
Branch: 1 branch
BranchTrueFalseTotal
if ($t->has_next_row) 0 0 0
39 0 my $row = $t->get_next_row_hashref;
40 0 push @rows, $row;
41 }
42  
43 0 ▶ if ($args{detail}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($args{'detail'}) { } 0 0 0
elsif ($args{'descriptive'}) { } 0 0 0
44 0 1;
45 } elsif ($args{descriptive}) {
46 0 @rows = map { $_->{"${lang}_descriptive_name"} } @rows;
47  
48 } else {
49 0 @rows = map { $_->{"${lang}_short_name"} } @rows;
50 }
51  
52 0 [200, "OK", \@rows];
53 }
54  
55 gen_modified_sub(
56 output_name => 'troika_list_cards_shuffled',
57 base_name => 'troika_list_cards',
58 summary => 'Return the list of cards, shuffled',
59 0 ▶ wrap_code => sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
60 0 my $orig = shift;
61 0 my $res = $orig->(@_);
62 0 ▶ return $res unless $res->[0] == 200;
Branch: 1 branch
BranchTrueFalseTotal
unless $res->[0] == 200 0 0 0
63 0 $res->[2] = [shuffle(@{ $res->[2] })];
64 0 $res;
65 },
66 1 );
67  
68 1 1;
69 # ABSTRACT: Utilities related to the Anak Bos Troika card game
70  
71 __END__
↑ Summary