line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Sweat::Group; |
2
|
|
|
|
|
|
|
|
3
|
3
|
|
|
3
|
|
32
|
use warnings; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
108
|
|
4
|
3
|
|
|
3
|
|
18
|
use strict; |
|
3
|
|
|
|
|
4
|
|
|
3
|
|
|
|
|
72
|
|
5
|
3
|
|
|
3
|
|
15
|
use Types::Standard qw(ArrayRef Str); |
|
3
|
|
|
|
|
32
|
|
|
3
|
|
|
|
|
54
|
|
6
|
|
|
|
|
|
|
|
7
|
3
|
|
|
3
|
|
2542
|
use List::Util qw(shuffle); |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
178
|
|
8
|
3
|
|
|
3
|
|
18
|
use Try::Tiny; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
208
|
|
9
|
|
|
|
|
|
|
|
10
|
3
|
|
|
3
|
|
1203
|
use Sweat::Drill; |
|
3
|
|
|
|
|
11
|
|
|
3
|
|
|
|
|
117
|
|
11
|
|
|
|
|
|
|
|
12
|
3
|
|
|
3
|
|
25
|
use Moo; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
18
|
|
13
|
3
|
|
|
3
|
|
7967
|
use namespace::clean; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
33
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
has 'drills' => ( |
16
|
|
|
|
|
|
|
is => 'ro', |
17
|
|
|
|
|
|
|
required => 1, |
18
|
|
|
|
|
|
|
isa => ArrayRef, |
19
|
|
|
|
|
|
|
); |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
has 'name' => ( |
22
|
|
|
|
|
|
|
is => 'ro', |
23
|
|
|
|
|
|
|
required => 1, |
24
|
|
|
|
|
|
|
isa => Str, |
25
|
|
|
|
|
|
|
); |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
has 'sweat' => ( |
28
|
|
|
|
|
|
|
is => 'ro', |
29
|
|
|
|
|
|
|
required => 1, |
30
|
|
|
|
|
|
|
weaken => 1, |
31
|
|
|
|
|
|
|
); |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub BUILD { |
34
|
8
|
|
|
8
|
0
|
4806
|
my ( $self, $args ) = @_; |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
# We reset the drills immediately upon building so that restrictive |
37
|
|
|
|
|
|
|
# preferences (e.g. no-jumping) can get applied immediately. |
38
|
8
|
|
|
|
|
22
|
$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
|
|
|
10
|
0
|
12
|
my $self = shift; |
47
|
|
|
|
|
|
|
|
48
|
10
|
|
|
|
|
34
|
my %restriction_map = ( |
49
|
|
|
|
|
|
|
jumping => 'requires_jumping', |
50
|
|
|
|
|
|
|
chair => 'requires_a_chair', |
51
|
|
|
|
|
|
|
); |
52
|
|
|
|
|
|
|
|
53
|
10
|
|
|
|
|
14
|
for my $drill ( @{ $self->drills } ) { |
|
10
|
|
|
|
|
28
|
|
54
|
30
|
|
|
|
|
558
|
$drill->is_used(0); |
55
|
30
|
|
|
|
|
678
|
for my $restriction ( keys %restriction_map ) { |
56
|
60
|
|
|
|
|
138
|
my $attribute = $restriction_map{$restriction}; |
57
|
60
|
50
|
66
|
|
|
420
|
if ( $drill->$attribute && !$self->sweat->$restriction ) { |
58
|
0
|
|
|
|
|
0
|
$drill->is_used(1); |
59
|
0
|
|
|
|
|
0
|
last; |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
10
|
50
|
|
|
|
26
|
unless ($self->unused_drills) { |
65
|
0
|
|
|
|
|
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
|
|
|
2
|
0
|
32
|
my ( $class, $sweat, $data ) = @_; |
73
|
2
|
|
|
|
|
6
|
my @groups; |
74
|
|
|
|
|
|
|
try { |
75
|
2
|
|
|
2
|
|
92
|
for my $group_data ( @$data ) { |
76
|
8
|
|
|
|
|
12
|
my @drills; |
77
|
8
|
|
|
|
|
8
|
for my $drill_data ( @{$group_data->{drills} } ) { |
|
8
|
|
|
|
|
26
|
|
78
|
24
|
|
|
|
|
398
|
my $drill = Sweat::Drill->new( $drill_data ); |
79
|
24
|
|
|
|
|
10674
|
push @drills, $drill; |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
my $group = $class->new( |
82
|
|
|
|
|
|
|
drills => \@drills, |
83
|
|
|
|
|
|
|
name => $group_data->{name}, |
84
|
8
|
|
|
|
|
120
|
sweat => $sweat, |
85
|
|
|
|
|
|
|
); |
86
|
8
|
|
|
|
|
88
|
push @groups, $group; |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
catch { |
90
|
0
|
|
|
0
|
|
0
|
die "Sorry... I can't parse the provided drill-group config data. $_\n"; |
91
|
2
|
|
|
|
|
24
|
}; |
92
|
2
|
|
|
|
|
74
|
return @groups; |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
sub unused_drills { |
96
|
38
|
|
|
38
|
0
|
56
|
my $self = shift; |
97
|
|
|
|
|
|
|
|
98
|
38
|
|
|
|
|
54
|
return grep { not $_->is_used } @{ $self->drills }; |
|
114
|
|
|
|
|
1928
|
|
|
38
|
|
|
|
|
76
|
|
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
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> |