| 1 | package TUI::Menus::StatusDef; | ||||||||||||||||||||||||||||
| 2 | # ABSTRACT: Class linking a range of helps with a list of status line items | ||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||
| 4 | 41 | ▶ | use 5.010; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 41 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 41 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 41 | our $VERSION = '2.000002'; | |||||||||||||||||||||||||||
| 9 | 41 | $VERSION =~ tr/_//d; | |||||||||||||||||||||||||||
| 10 | 41 | our $AUTHORITY = 'cpan:BRICKPOOL'; | |||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 41 | ▶ | use Exporter 'import'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | 41 | our @EXPORT = qw( | |||||||||||||||||||||||||||
| 14 | TStatusDef | ||||||||||||||||||||||||||||
| 15 | new_TStatusDef | ||||||||||||||||||||||||||||
| 16 | ); | ||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 41 | ▶ | use Carp (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 19 | 41 | ▶ | use TUI::toolkit; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 20 | 41 | ▶ | use TUI::toolkit::Types qw( | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 21 | is_Object | ||||||||||||||||||||||||||||
| 22 | :types | ||||||||||||||||||||||||||||
| 23 | 41 | ); | |||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | 41 | ▶ | use TUI::Menus::StatusItem; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | sub TStatusDef() { __PACKAGE__ } | ||||||||||||||||||||||||||||
| 28 | 4 | ▶ | sub new_TStatusDef { __PACKAGE__->from(@_) } | ||||||||||||||||||||||||||
|
Subroutine
new_TStatusDef: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | # public attributes | ||||||||||||||||||||||||||||
| 31 | 41 | has next => ( is => 'rw' ); | |||||||||||||||||||||||||||
| 32 | 0 | ▶ | has min => ( is => 'rw', default => sub { die 'required' } ); | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||||||||||||||||||
| 33 | 0 | ▶ | has max => ( is => 'rw', default => sub { die 'required' } ); | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||||||||||||||||||
| 34 | 41 | has items => ( is => 'rw' ); | |||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | # predeclare private methods | ||||||||||||||||||||||||||||
| 37 | my ( | ||||||||||||||||||||||||||||
| 38 | 41 | $add_status_item, | |||||||||||||||||||||||||||
| 39 | $add_status_def, | ||||||||||||||||||||||||||||
| 40 | ); | ||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | 5 | ▶ | sub BUILDARGS { # \%args (%args) | ||||||||||||||||||||||||||
|
Subroutine
BUILDARGS: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 43 | 5 | state $sig = signature( | |||||||||||||||||||||||||||
| 44 | method => 1, | ||||||||||||||||||||||||||||
| 45 | named => [ | ||||||||||||||||||||||||||||
| 46 | min => PositiveOrZeroInt, { alias => 'aMin' }, | ||||||||||||||||||||||||||||
| 47 | max => PositiveOrZeroInt, { alias => 'aMax' }, | ||||||||||||||||||||||||||||
| 48 | items => Object, { alias => 'someItems', optional => 1 }, | ||||||||||||||||||||||||||||
| 49 | next => Object, { alias => 'aNext', optional => 1 }, | ||||||||||||||||||||||||||||
| 50 | ], | ||||||||||||||||||||||||||||
| 51 | caller_level => +1, | ||||||||||||||||||||||||||||
| 52 | ); | ||||||||||||||||||||||||||||
| 53 | 5 | my ( $class, $args ) = $sig->( @_ ); | |||||||||||||||||||||||||||
| 54 | 5 | return { %$args }; | |||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | 4 | ▶ | sub from { # $obj ($aMin, $aMax, |$someItems, |$aNext) | ||||||||||||||||||||||||||
|
Subroutine
from: called CC=5 SCAR=23.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 58 | 4 | state $sig = signature( | |||||||||||||||||||||||||||
| 59 | method => 1, | ||||||||||||||||||||||||||||
| 60 | pos => [ | ||||||||||||||||||||||||||||
| 61 | PositiveOrZeroInt, | ||||||||||||||||||||||||||||
| 62 | PositiveOrZeroInt, | ||||||||||||||||||||||||||||
| 63 | Object, { optional => 1 }, | ||||||||||||||||||||||||||||
| 64 | Object, { optional => 1 }, | ||||||||||||||||||||||||||||
| 65 | ], | ||||||||||||||||||||||||||||
| 66 | ); | ||||||||||||||||||||||||||||
| 67 | 4 | my ( $class, @args ) = $sig->( @_ ); | |||||||||||||||||||||||||||
| 68 | 4 | SWITCH: for ( scalar @args ) { | |||||||||||||||||||||||||||
| 69 | 4 | ▶ | $_ == 2 and return $class->new( min => $args[0], max => $args[1] ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 70 | 0 | ▶ | $_ == 3 and return $class->new( min => $args[0], max => $args[1], | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 71 | items => $args[2] ); | ||||||||||||||||||||||||||||
| 72 | 0 | ▶ | $_ == 4 and return $class->new( min => $args[0], max => $args[1], | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 73 | items => $args[2], next => $args[3] ); | ||||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||
| 75 | 0 | return ; | |||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | 2 | ▶ | sub _add_status_item { goto &$add_status_item } | ||||||||||||||||||||||||||
|
Subroutine
_add_status_item: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 79 | 5 | ▶ | $add_status_item = sub { # $s1 ($s1, $s2, |undef) | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=9 SCAR=23.4
| |||||||||||||||||||||||||||||
| 80 | 5 | my ( $s1, $s2 ) = @_; | |||||||||||||||||||||||||||
| 81 | 5 | ▶ | assert ( @_ >= 2 && @_ <= 3 ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
@_ >= 2 and @_ <= 3
MC/DC0%0/2
@_ >= 2 and @_ <= 3
@_ >= 2
@_ <= 3
Truth table33%1/3
A and B
A= @_ >= 2B= @_ <= 3
| |||||||||||||||||||||||||||||
| 82 | 5 | ▶ | assert ( is_Object $s1 ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 83 | 5 | ▶ | assert ( is_Object $s2 and $s2->isa( TStatusItem ) ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
&is_Object($s2) and $s2->isa("TUI::Menus::StatusItem")
MC/DC0%0/2
&is_Object($s2) and $s2->isa("TUI::Menus::StatusItem")
&is_Object($s2)
$s2->isa("TUI::Menus::StatusItem")
Truth table33%1/3
A and B
A= &is_Object($s2)B= $s2->isa("TUI::Menus::StatusItem")
| |||||||||||||||||||||||||||||
| 84 | 5 | my $def = $s1; | |||||||||||||||||||||||||||
| 85 | 5 | ▶ | while ( $def->{next} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 86 | 2 | $def = $def->{next}; | |||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||
| 88 | 5 | ▶ | if ( !$def->{items} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 89 | 3 | $def->{items} = $s2; | |||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||
| 91 | else { | ||||||||||||||||||||||||||||
| 92 | 2 | my $cur = $def->{items}; | |||||||||||||||||||||||||||
| 93 | 2 | ▶ | while ( $cur->{next} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 94 | 0 | $cur = $cur->{next}; | |||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||
| 96 | 2 | $cur->{next} = $s2; | |||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||
| 98 | 5 | return $s1; | |||||||||||||||||||||||||||
| 99 | 41 | }; | |||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | 1 | ▶ | sub _add_status_def { goto &$add_status_def } | ||||||||||||||||||||||||||
|
Subroutine
_add_status_def: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 102 | 2 | ▶ | $add_status_def = sub { # $s1 ($s1, $s2, |undef) | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=7 SCAR=22.0
| |||||||||||||||||||||||||||||
| 103 | 2 | my ( $s1, $s2 ) = @_; | |||||||||||||||||||||||||||
| 104 | 2 | ▶ | assert ( @_ >= 2 && @_ <= 3 ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
@_ >= 2 and @_ <= 3
MC/DC0%0/2
@_ >= 2 and @_ <= 3
@_ >= 2
@_ <= 3
Truth table33%1/3
A and B
A= @_ >= 2B= @_ <= 3
| |||||||||||||||||||||||||||||
| 105 | 2 | ▶ | assert ( is_Object $s1 ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 106 | 2 | ▶ | assert ( is_Object $s2 and $s2->isa( TStatusDef ) ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
&is_Object($s2) and $s2->isa("TUI::Menus::StatusDef")
MC/DC0%0/2
&is_Object($s2) and $s2->isa("TUI::Menus::StatusDef")
&is_Object($s2)
$s2->isa("TUI::Menus::StatusDef")
Truth table33%1/3
A and B
A= &is_Object($s2)B= $s2->isa("TUI::Menus::StatusDef")
| |||||||||||||||||||||||||||||
| 107 | 2 | my $cur = $s1; | |||||||||||||||||||||||||||
| 108 | 2 | ▶ | while ( $cur->{next} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 109 | 0 | $cur = $cur->{next}; | |||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||
| 111 | 2 | $cur->{next} = $s2; | |||||||||||||||||||||||||||
| 112 | 2 | return $s1; | |||||||||||||||||||||||||||
| 113 | 41 | }; | |||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||
| 115 | 4 | ▶ | sub add { # $s1 ($s1, $s2, |$swap) | ||||||||||||||||||||||||||
|
Subroutine
add: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 116 | 4 | state $sig = signature( | |||||||||||||||||||||||||||
| 117 | pos => [ | ||||||||||||||||||||||||||||
| 118 | Object, | ||||||||||||||||||||||||||||
| 119 | Object, | ||||||||||||||||||||||||||||
| 120 | Bool, { optional => 1 } | ||||||||||||||||||||||||||||
| 121 | ], | ||||||||||||||||||||||||||||
| 122 | ); | ||||||||||||||||||||||||||||
| 123 | 4 | my ( $s1, $s2, $swap ) = $sig->( @_ ); | |||||||||||||||||||||||||||
| 124 | 4 | ▶ | assert ( not $swap ); # test if operands have been swapped | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 125 | 4 | ▶ | $s2->isa( TStatusDef ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 126 | ? goto &$add_status_def | ||||||||||||||||||||||||||||
| 127 | : goto &$add_status_item | ||||||||||||||||||||||||||||
| 128 | } | ||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||
| 130 | use overload | ||||||||||||||||||||||||||||
| 131 | 41 | ▶ | '+' => \&add, | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 132 | 41 | fallback => 1; | |||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||
| 134 | 41 | 1 | |||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||
| 136 | __END__ | ||||||||||||||||||||||||||||