| 1 | package Class::Usul::TraitFor::DebugFlag; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 17 | ▶ | use namespace::autoclean; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | 17 | ▶ | use Class::Usul::Constants qw( FALSE TRUE ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 17 | ▶ | use Class::Usul::Functions qw( ns_environment ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 17 | ▶ | use Class::Usul::Types qw( Bool ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 17 | ▶ | use Moo::Role; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 17 | ▶ | use Class::Usul::Options; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 17 | requires qw( config is_interactive yorn ); | |||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | # Attribute constructors | ||||||||||||||||||||||||||||
| 14 | 5 | ▶ | my $_build_debug = sub { | ||||||||||||||||||||||||||
|
Subroutine
_build_debug: called CC=2 SCAR=7.0
Subroutine
__ANON__: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||
| 15 | 5 | ▶ | return !!ns_environment( $_[ 0 ]->config->appclass, 'debug' ) ? TRUE : FALSE; | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 16 | 17 | }; | |||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | # Public attributes | ||||||||||||||||||||||||||||
| 19 | 17 | option 'debug' => is => 'rwp', isa => Bool, builder => $_build_debug, | |||||||||||||||||||||||||||
| 20 | documentation => 'Turn debugging on. Prompts if interactive', | ||||||||||||||||||||||||||||
| 21 | short => 'D', lazy => TRUE; | ||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | 17 | option 'noask' => is => 'ro', isa => Bool, default => FALSE, | |||||||||||||||||||||||||||
| 24 | documentation => 'Do not prompt for debugging', short => 'n'; | ||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | # Private methods | ||||||||||||||||||||||||||||
| 27 | 0 | ▶ | my $_dont_ask = sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 28 | 0 | ▶ | my $self = shift; return $self->debug || !$self->is_interactive(); | ||||||||||||||||||||||||||
|
Condition0%0/3
$self->debug || !$self->is_interactive
MC/DC0%0/2
$self->debug || !$self->is_interactive
$self->debug
!$self->is_interactive
Truth table0%0/3
A || not(B)
A= $self->debugB= !$self->is_interactive
| |||||||||||||||||||||||||||||
| 29 | 17 | }; | |||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | 0 | ▶ | my $_get_debug_option = sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||
| 32 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | 0 | ▶ | ($self->noask or $self->$_dont_ask) and return $self->debug; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->noask or $self->$_dont_ask
MC/DC0%0/2
$self->noask or $self->$_dont_ask
$self->noask
$self->$_dont_ask
Truth table0%0/3
A or B
A= $self->noaskB= $self->$_dont_ask
| |||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | 0 | return $self->yorn( 'Do you want debugging turned on', FALSE, TRUE ); | |||||||||||||||||||||||||||
| 37 | 17 | }; | |||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | # Construction | ||||||||||||||||||||||||||||
| 40 | 21 | ▶ | around 'BUILDARGS' => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.2
| |||||||||||||||||||||||||||||
| 41 | 21 | my ($orig, $self, @args) = @_; my $attr = $orig->( $self, @args ); | |||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | 21 | ▶ | my $deprecated = delete $attr->{nodebug}; $attr->{noask} //= $deprecated; | ||||||||||||||||||||||||||
|
Condition33%1/3
$attr->{"noask"} //= $deprecated
MC/DC0%0/2
$attr->{"noask"} //= $deprecated
$attr->{"noask"}
$deprecated
Truth table33%1/3
A //= B
A= $attr->{"noask"}B= $deprecated
| |||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | 21 | return $attr; | |||||||||||||||||||||||||||
| 46 | 17 | }; | |||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | 0 | ▶ | sub BUILD { # Must not call logger before this executes | ||||||||||||||||||||||||||
|
Subroutine
BUILD: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 49 | 0 | my $self = shift; $self->_set_debug( $self->$_get_debug_option ); return; | |||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | # Public methods | ||||||||||||||||||||||||||||
| 53 | 2 | ▶ | sub debug_flag { | ||||||||||||||||||||||||||
|
Subroutine
debug_flag: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 54 | 2 | ▶ | my $self = shift; return $self->debug ? '-D' : '-n'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | 17 | 1; | |||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | __END__ | ||||||||||||||||||||||||||||