| 1 | package TUI::Validate::StringLookupValidator; | ||||||||||||||||||||
| 2 | # ABSTRACT: lookup validator backed by a string list | ||||||||||||||||||||
| 3 | |||||||||||||||||||||
| 4 | 5 | ▶ | use 5.010; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 5 | 5 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 6 | 5 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 7 | |||||||||||||||||||||
| 8 | 5 | our $VERSION = '2.000003'; | |||||||||||||||||||
| 9 | 5 | $VERSION =~ tr/_//d; | |||||||||||||||||||
| 10 | 5 | our $AUTHORITY = 'cpan:BRICKPOOL'; | |||||||||||||||||||
| 11 | |||||||||||||||||||||
| 12 | 5 | ▶ | use Exporter 'import'; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 13 | 5 | our @EXPORT = qw( | |||||||||||||||||||
| 14 | TStringLookupValidator | ||||||||||||||||||||
| 15 | new_TStringLookupValidator | ||||||||||||||||||||
| 16 | ); | ||||||||||||||||||||
| 17 | |||||||||||||||||||||
| 18 | 5 | ▶ | use Storable; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 19 | 5 | ▶ | use TUI::toolkit; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 20 | 5 | ▶ | use TUI::toolkit::Types qw( | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 21 | Maybe | ||||||||||||||||||||
| 22 | :is | ||||||||||||||||||||
| 23 | :types | ||||||||||||||||||||
| 24 | 5 | ); | |||||||||||||||||||
| 25 | |||||||||||||||||||||
| 26 | 5 | ▶ | use TUI::MsgBox::Const qw( | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 27 | mfError | ||||||||||||||||||||
| 28 | mfOKButton | ||||||||||||||||||||
| 29 | 5 | ); | |||||||||||||||||||
| 30 | 5 | ▶ | use TUI::MsgBox::MsgBoxText qw( messageBox ); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 31 | 5 | ▶ | use TUI::Validate::LookupValidator; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 32 | |||||||||||||||||||||
| 33 | sub TStringLookupValidator() { __PACKAGE__ } | ||||||||||||||||||||
| 34 | sub name() { 'TStringLookupValidator' }; | ||||||||||||||||||||
| 35 | 0 | ▶ | sub new_TStringLookupValidator { __PACKAGE__->from(@_) } | ||||||||||||||||||
|
Subroutine
new_TStringLookupValidator: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 36 | |||||||||||||||||||||
| 37 | 5 | extends TLookupValidator; | |||||||||||||||||||
| 38 | |||||||||||||||||||||
| 39 | # declare global variables | ||||||||||||||||||||
| 40 | 5 | our $errorMsg = "Input is not in list of valid strings"; | |||||||||||||||||||
| 41 | |||||||||||||||||||||
| 42 | # protected attributes | ||||||||||||||||||||
| 43 | 0 | ▶ | has strings => ( is => 'ro', default => sub { die 'required' } ); | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||||||||||
| 44 | |||||||||||||||||||||
| 45 | 0 | ▶ | sub BUILDARGS { # \%args (%args) | ||||||||||||||||||
|
Subroutine
BUILDARGS: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 46 | 0 | state $sig = signature( | |||||||||||||||||||
| 47 | method => 1, | ||||||||||||||||||||
| 48 | named => [ | ||||||||||||||||||||
| 49 | strings => Maybe[Object], { alias => 'aStrings' }, | ||||||||||||||||||||
| 50 | ], | ||||||||||||||||||||
| 51 | caller_level => +1, | ||||||||||||||||||||
| 52 | ); | ||||||||||||||||||||
| 53 | 0 | my ( $class, $args ) = $sig->( @_ ); | |||||||||||||||||||
| 54 | 0 | return { %$args }; | |||||||||||||||||||
| 55 | } | ||||||||||||||||||||
| 56 | |||||||||||||||||||||
| 57 | 0 | ▶ | sub from { # $obj ($aStrings|undef) | ||||||||||||||||||
|
Subroutine
from: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 58 | 0 | state $sig = signature( | |||||||||||||||||||
| 59 | method => 1, | ||||||||||||||||||||
| 60 | pos => [Maybe[Object]], | ||||||||||||||||||||
| 61 | ); | ||||||||||||||||||||
| 62 | 0 | my ( $class, $aStrings ) = $sig->( @_ ); | |||||||||||||||||||
| 63 | 0 | return $class->new( strings => $aStrings ); | |||||||||||||||||||
| 64 | } | ||||||||||||||||||||
| 65 | |||||||||||||||||||||
| 66 | 0 | ▶ | sub DEMOLISH { # void ($in_global_destruction) | ||||||||||||||||||
|
Subroutine
DEMOLISH: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||
| 67 | 0 | my ( $self, $in_global_destruction ) = @_; | |||||||||||||||||||
| 68 | 0 | ▶ | assert ( @_ == 2 ); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 69 | 0 | ▶ | assert ( is_Object $self ); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 70 | 0 | ▶ | assert ( is_Bool $in_global_destruction ); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 71 | 0 | ▶ | $self->newStringList( undef ) unless $in_global_destruction; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 72 | 0 | return; | |||||||||||||||||||
| 73 | } | ||||||||||||||||||||
| 74 | |||||||||||||||||||||
| 75 | 0 | ▶ | sub error { # void () | ||||||||||||||||||
|
Subroutine
error: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 76 | 0 | state $sig = signature( | |||||||||||||||||||
| 77 | method => Object, | ||||||||||||||||||||
| 78 | pos => [], | ||||||||||||||||||||
| 79 | ); | ||||||||||||||||||||
| 80 | 0 | my ( $self ) = $sig->( @_ ); | |||||||||||||||||||
| 81 | 0 | messageBox( mfError | mfOKButton, $errorMsg ); | |||||||||||||||||||
| 82 | 0 | return; | |||||||||||||||||||
| 83 | } | ||||||||||||||||||||
| 84 | |||||||||||||||||||||
| 85 | 0 | ▶ | my $stringMatch = sub { # $bool ($a1, $a2) | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=4 SCAR=30.0
| |||||||||||||||||||||
| 86 | 0 | my ( $a1, $a2 ) = @_; | |||||||||||||||||||
| 87 | 0 | ▶ | assert ( @_ == 2 ); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 88 | 0 | ▶ | assert ( is_Str $a1 ); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 89 | 0 | ▶ | assert ( is_Str $a2 ); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 90 | 0 | return $a1 eq $a2; | |||||||||||||||||||
| 91 | 5 | }; | |||||||||||||||||||
| 92 | |||||||||||||||||||||
| 93 | 0 | ▶ | sub lookup { # $bool ($s) | ||||||||||||||||||
|
Subroutine
lookup: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||
| 94 | 0 | state $sig = signature( | |||||||||||||||||||
| 95 | method => Object, | ||||||||||||||||||||
| 96 | pos => [Str], | ||||||||||||||||||||
| 97 | ); | ||||||||||||||||||||
| 98 | 0 | my ( $self, $s ) = $sig->( @_ ); | |||||||||||||||||||
| 99 | return $self->{strings} | ||||||||||||||||||||
| 100 | 0 | ▶ | && defined $self->{strings}->firstThat( $stringMatch, $s ); | ||||||||||||||||||
|
Condition0%0/3
$self->{'strings'} && defined $self->{'strings'}->firstThat($stringMatch, $s)
MC/DC0%0/2
$self->{'strings'} && defined $self->{'strings'}->firstThat($stringMatch, $s)
$self->{'strings'}
defined $self->{'strings'}->firstThat($stringMatch, $s)
Truth table0%0/3
A && B
A= $self->{'strings'}B= defined $self->{'strings'}->firstThat($stringMatch, $s)
| |||||||||||||||||||||
| 101 | } | ||||||||||||||||||||
| 102 | |||||||||||||||||||||
| 103 | 0 | ▶ | sub newStringList { # void ($aStrings|undef) | ||||||||||||||||||
|
Subroutine
newStringList: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||
| 104 | 0 | state $sig = signature( | |||||||||||||||||||
| 105 | method => Object, | ||||||||||||||||||||
| 106 | pos => [Maybe[Object]], | ||||||||||||||||||||
| 107 | ); | ||||||||||||||||||||
| 108 | 0 | my ( $self, $aStrings ) = $sig->( @_ ); | |||||||||||||||||||
| 109 | $self->destroy( $self->{strings} ) | ||||||||||||||||||||
| 110 | 0 | ▶ | if ( $self->{strings} ); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 111 | 0 | $self->{strings} = $aStrings; | |||||||||||||||||||
| 112 | 0 | return; | |||||||||||||||||||
| 113 | } | ||||||||||||||||||||
| 114 | |||||||||||||||||||||
| 115 | 0 | ▶ | sub write :method { # void ($os) | ||||||||||||||||||
|
Subroutine
write: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 116 | 0 | state $sig = signature( | |||||||||||||||||||
| 117 | method => Object, | ||||||||||||||||||||
| 118 | pos => [Object], | ||||||||||||||||||||
| 119 | ); | ||||||||||||||||||||
| 120 | 0 | my ( $self, $os ) = $sig->( @_ ); | |||||||||||||||||||
| 121 | 0 | $self->SUPER::write( $os ); | |||||||||||||||||||
| 122 | 0 | $os->put( $self->{strings} ); | |||||||||||||||||||
| 123 | 0 | return; | |||||||||||||||||||
| 124 | } | ||||||||||||||||||||
| 125 | |||||||||||||||||||||
| 126 | 0 | ▶ | sub read :method { # $self ($is) | ||||||||||||||||||
|
Subroutine
read: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 127 | 0 | state $sig = signature( | |||||||||||||||||||
| 128 | method => Object, | ||||||||||||||||||||
| 129 | pos => [Object], | ||||||||||||||||||||
| 130 | ); | ||||||||||||||||||||
| 131 | 0 | my ( $self, $is ) = $sig->( @_ ); | |||||||||||||||||||
| 132 | 0 | $self->SUPER::read( $is ); | |||||||||||||||||||
| 133 | 0 | $self->{strings} = $is->get(); | |||||||||||||||||||
| 134 | 0 | return $self; | |||||||||||||||||||
| 135 | } | ||||||||||||||||||||
| 136 | |||||||||||||||||||||
| 137 | 0 | ▶ | sub build { # $obj () | ||||||||||||||||||
|
Subroutine
build: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||
| 138 | 0 | my ( $class ) = @_; | |||||||||||||||||||
| 139 | 0 | ▶ | assert ( @_ == 1 ); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 140 | 0 | ▶ | assert ( is_Str $class ); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 141 | 0 | ▶ | assert ( Storable::is_retrieving ); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 142 | 0 | return $class->new( strings => undef ); | |||||||||||||||||||
| 143 | } | ||||||||||||||||||||
| 144 | |||||||||||||||||||||
| 145 | 5 | 1 | |||||||||||||||||||
| 146 | |||||||||||||||||||||
| 147 | __END__ | ||||||||||||||||||||