blib/lib/App/karr/Role/DependencyArgs.pm

filter: Statementstmt 33.3% 6 / 18 Branchbran 0.0% 0 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 33.3% 1 / 3 Podpod 100% 2 / 2 totaltotal 29.0% 9 / 31 CC 7 SCAR 30.3
CC
7
Cov
23%
parse_dependency_ids
30.0
assert_dependencies_exist
12.0
BEGIN
1.0
CRAP 20.8
« blib/lib/App/karr/Role/Color.pm ↑ Summary blib/lib/App/karr/Foundation/State.pm »
1 # ABSTRACT: Turn the dependency ids a command was given into validated numbers
2  
3 package App::karr::Role::DependencyArgs;
4 3 our $VERSION = '0.602';
5 3 ▶use Moo::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 # What this role calls on its consumer (ticket #128's rule): usage_error from
8 # App::karr::Role::ExitCodes, find_task and normalize_task_id from
9 # App::karr::Role::BoardAccess. Both halves of the dependency pair need
10 # find_task -- deliberately the same lookup, see assert_dependencies_exist
11 # below -- and nothing else is shared, which is why the pair is two roles
12 # (ticket #137).
13 3 requires qw( find_task normalize_task_id usage_error );
14  
15  
16 # Ticket #124, gated on the CLI route existing; the move-time warning in
17 # App::karr::Role::DependencyCheck is #123.
18 #
19 # Both rejections here condemn the whole invocation rather than one id of a
20 # batch: a malformed or unknown dependency id is wrong for every id at once, so
21 # it is a usage error (exit 2) raised before anything is written -- ticket #54's
22 # rule, the same reason Cmd::Create runs them before allocating an id. The one
23 # per-id case, a self-reference, cannot live here: which id is "self" differs
24 # per batch id, so the caller checks it inside its batch loop (#61).
25 0 ▶sub parse_dependency_ids {
Subroutine parse_dependency_ids: not called CC=5 SCAR=34.0
Pod documented
26 0 my ( $self, $flag, $value ) = @_;
27 0 my ( @ids, %seen );
28 0 for my $raw ( split /,/, $value ) {
29 # The house kNNN spelling is accepted here too (k30 == 30): normalized
30 # to a bare number before validation so `--depends-on k30` names the
31 # same card `karr show k30` does. A token that is not k+digits comes
32 # back unchanged and still fails the numeric check below -- the error
33 # names the value as the caller typed it.
34 0 my $id = $self->normalize_task_id($raw);
35 0 ▶ $self->usage_error(
Branch: 1 branch
BranchTrueFalseTotal
unless $id =~ /\A[0-9]+\z/ 0 0 0
36 qq{invalid $flag id "$raw" (ids are comma-separated numbers or kNNN)} )
37 unless $id =~ /\A[0-9]+\z/;
38 # Numified on purpose: YAML::XS and JSON::MaybeXS both encode by the
39 # scalar's own type, so a string "2" would round-trip as '2' / "2" --
40 # which go-yaml refuses to unmarshal into kanban-md's IntSlice. Same
41 # care run_batch takes when echoing batch ids. Deduplicated here, once
42 # for every flag, so `--depends-on 2,2` cannot store [2,2]: a repeated
43 # id carries no meaning in any of the three flags, and edit's
44 # append-unique only guards against ids the card already carries.
45 0 ▶ push @ids, $id + 0 unless $seen{ $id + 0 }++;
Branch: 1 branch
BranchTrueFalseTotal
unless $seen{$id + 0}++ 0 0 0
46 }
47 0 ▶ $self->usage_error("$flag requires at least one id") unless @ids;
Branch: 1 branch
BranchTrueFalseTotal
unless @ids 0 0 0
48 0 return \@ids;
49 }
50  
51  
52 0 ▶sub assert_dependencies_exist {
Subroutine assert_dependencies_exist: not called CC=3 SCAR=24.8
Pod documented
53 0 my ( $self, $ids ) = @_;
54 0 for my $dep_id (@$ids) {
55 0 ▶ $self->usage_error(
Branch: 1 branch
BranchTrueFalseTotal
unless $self->find_task($dep_id) 0 0 0
56 "dependency task $dep_id does not exist on this board" )
57 unless $self->find_task($dep_id);
58 }
59 0 return $ids;
60 }
61  
62  
63 3 1;
64  
65 __END__
« blib/lib/App/karr/Role/Color.pm ↑ Summary blib/lib/App/karr/Foundation/State.pm »