blib/lib/App/karr/Role/ClaimDefault.pm untested

filter: Statementstmt 0.0% 0 / 25 Branchbran 0.0% 0 / 12 Conditioncond 0.0% 0 / 18 MC/DCmcdc 0.0% 0 / 12 Subroutinesub 0.0% 0 / 7 Podpod 0.0% 0 / 5 totaltotal 0.0% 0 / 79 CC 7 SCAR 19.1
CC
7
Cov
0%
resolved_claim_for
12.0
env_claim
6.0
has_env_claim
6.0
CRAP 6.8
1 # ABSTRACT: Default a command's claim name from KARR_CLAIM when the flag is omitted
2  
3 package App::karr::Role::ClaimDefault;
4 our $VERSION = '0.602';
5 use Moo::Role;
6 # Loaded without importing, and every call below is qualified. A Moo::Role
7 # composes every sub in its package into its consumers, imported ones included
8 # (#38), so an imported from_octets_from_env would land as a method on every
9 # command that takes a claim.
10 use App::karr::Encoding ();
11  
12 # resolved_claim_for asks the board whether a status needs a claim. Every
13 # consumer brings store through App::karr::Role::BoardAccess, composed in the
14 # same `with`. claim and claimed_by cannot be listed here: they are each
15 # command's own `option`, declared after its `with` line runs.
16 requires 'store';
17  
18  
19 sub env_claim {
20 my ($self) = @_;
21 my $raw = $ENV{KARR_CLAIM};
22 return undef unless defined $raw && length $raw;
23 return App::karr::Encoding::from_octets_from_env($raw);
24 }
25  
26  
27 sub has_env_claim {
28 my ($self) = @_;
29 return ( defined $ENV{KARR_CLAIM} && length $ENV{KARR_CLAIM} ) ? 1 : 0;
30 }
31  
32  
33 sub resolved_claim {
34 my ($self) = @_;
35 return $self->claim if defined $self->claim && length $self->claim;
36 return $self->env_claim;
37 }
38  
39  
40 sub resolved_claim_for {
41 my ( $self, $status ) = @_;
42 return $self->claim if defined $self->claim && length $self->claim;
43 return $self->env_claim
44 if defined $status && $self->store->status_requires_claim($status);
45 return undef;
46 }
47  
48  
49 sub resolved_claimed_by {
50 my ($self) = @_;
51 return $self->claimed_by if defined $self->claimed_by && length $self->claimed_by;
52 return $self->env_claim;
53 }
54  
55 1;
56  
57 __END__