| 1 | package Sweat::Group; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 3 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 3 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 3 | ▶ | use Types::Standard qw(ArrayRef Str); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 3 | ▶ | use List::Util qw(shuffle); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 3 | ▶ | use Try::Tiny; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 3 | ▶ | use Sweat::Drill; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 3 | ▶ | use Moo; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | 3 | ▶ | use namespace::clean; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | 3 | has 'drills' => ( | |||||||||||||||||||||||||||
| 16 | is => 'ro', | ||||||||||||||||||||||||||||
| 17 | required => 1, | ||||||||||||||||||||||||||||
| 18 | isa => ArrayRef, | ||||||||||||||||||||||||||||
| 19 | ); | ||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | 3 | has 'name' => ( | |||||||||||||||||||||||||||
| 22 | is => 'ro', | ||||||||||||||||||||||||||||
| 23 | required => 1, | ||||||||||||||||||||||||||||
| 24 | isa => Str, | ||||||||||||||||||||||||||||
| 25 | ); | ||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | 3 | has 'sweat' => ( | |||||||||||||||||||||||||||
| 28 | is => 'ro', | ||||||||||||||||||||||||||||
| 29 | required => 1, | ||||||||||||||||||||||||||||
| 30 | weaken => 1, | ||||||||||||||||||||||||||||
| 31 | ); | ||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | sub BUILD { | ||||||||||||||||||||||||||||
| 34 | 8 | ▶ | my ( $self, $args ) = @_; | ||||||||||||||||||||||||||
|
Subroutine
BUILD: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | # We reset the drills immediately upon building so that restrictive | ||||||||||||||||||||||||||||
| 37 | # preferences (e.g. no-jumping) can get applied immediately. | ||||||||||||||||||||||||||||
| 38 | 8 | $self->reset_drills; | |||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | # reset_drills: Set the "is_used" bit for each drill to 0, *unless* that drill | ||||||||||||||||||||||||||||
| 43 | # is restricted according to current config. In that case, it | ||||||||||||||||||||||||||||
| 44 | # gets "is_used" set to 1. | ||||||||||||||||||||||||||||
| 45 | sub reset_drills { | ||||||||||||||||||||||||||||
| 46 | 10 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
reset_drills: called CC=6 SCAR=19.6
Pod
undocumented
| |||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | 10 | my %restriction_map = ( | |||||||||||||||||||||||||||
| 49 | jumping => 'requires_jumping', | ||||||||||||||||||||||||||||
| 50 | chair => 'requires_a_chair', | ||||||||||||||||||||||||||||
| 51 | ); | ||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | 10 | for my $drill ( @{ $self->drills } ) { | |||||||||||||||||||||||||||
| 54 | 30 | $drill->is_used(0); | |||||||||||||||||||||||||||
| 55 | 30 | for my $restriction ( keys %restriction_map ) { | |||||||||||||||||||||||||||
| 56 | 60 | my $attribute = $restriction_map{$restriction}; | |||||||||||||||||||||||||||
| 57 | 60 | ▶ | if ( $drill->$attribute && !$self->sweat->$restriction ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$drill->$attribute and not $self->sweat->$restriction
MC/DC0%0/2
$drill->$attribute and not $self->sweat->$restriction
$drill->$attribute
not $self->sweat->$restriction
Truth table66%2/3
A and not(B)
A= $drill->$attributeB= not $self->sweat->$restriction
| |||||||||||||||||||||||||||||
| 58 | 0 | $drill->is_used(1); | |||||||||||||||||||||||||||
| 59 | 0 | last; | |||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | 10 | ▶ | unless ($self->unused_drills) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 65 | 0 | die "The current configuration makes every drill in the " | |||||||||||||||||||||||||||
| 66 | . $self->name | ||||||||||||||||||||||||||||
| 67 | . " group unavailable, and we can't have that.\n"; | ||||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | sub new_from_config_data { | ||||||||||||||||||||||||||||
| 72 | 2 | ▶ | my ( $class, $sweat, $data ) = @_; | ||||||||||||||||||||||||||
|
Subroutine
new_from_config_data: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 73 | 2 | my @groups; | |||||||||||||||||||||||||||
| 74 | try { | ||||||||||||||||||||||||||||
| 75 | 2 | ▶ | for my $group_data ( @$data ) { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||
| 76 | 8 | my @drills; | |||||||||||||||||||||||||||
| 77 | 8 | for my $drill_data ( @{$group_data->{drills} } ) { | |||||||||||||||||||||||||||
| 78 | 24 | my $drill = Sweat::Drill->new( $drill_data ); | |||||||||||||||||||||||||||
| 79 | 24 | push @drills, $drill; | |||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||
| 81 | my $group = $class->new( | ||||||||||||||||||||||||||||
| 82 | drills => \@drills, | ||||||||||||||||||||||||||||
| 83 | name => $group_data->{name}, | ||||||||||||||||||||||||||||
| 84 | 8 | sweat => $sweat, | |||||||||||||||||||||||||||
| 85 | ); | ||||||||||||||||||||||||||||
| 86 | 8 | push @groups, $group; | |||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||
| 89 | catch { | ||||||||||||||||||||||||||||
| 90 | 0 | ▶ | die "Sorry... I can't parse the provided drill-group config data. $_\n"; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 91 | 2 | }; | |||||||||||||||||||||||||||
| 92 | 2 | return @groups; | |||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | sub unused_drills { | ||||||||||||||||||||||||||||
| 96 | 38 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
unused_drills: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | 38 | return grep { not $_->is_used } @{ $self->drills }; | |||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | 3 | 1; | |||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | =head1 Sweat::Group - Library for the `sweat` command-line program | ||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | This library is intended for internal use by the L<sweat> command-line program, | ||||||||||||||||||||||||||||
| 108 | and as such offers no publicly documented methods. | ||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||
| 110 | =head1 SEE ALSO | ||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||
| 112 | L<sweat> | ||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||
| 114 | =head1 AUTHOR | ||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||
| 116 | Jason McIntosh <jmac@jmac.org> | ||||||||||||||||||||||||||||