lib/TUI/Validate/StringLookupValidator.pm

filter: Statementstmt 48.6% 35 / 72 Branchbran 0.0% 0 / 16 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 50.0% 9 / 18 Podpod 85.7% 6 / 7 totaltotal 42.3% 50 / 118 CC 10 SCAR 23.1
CC
10
Cov
38%
DEMOLISH
30.0
__ANON__
20.0
lookup
6.0
CRAP 10.1
« lib/TUI/Objects/Object.pm ↑ Summary lib/TUI/Gadgets/HeapView/Unix.pm »
1 package TUI::Validate::StringLookupValidator;
2 # ABSTRACT: lookup validator backed by a string list
3
4 4 ▶use 5.010;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7
8 4 our $VERSION = '2.000002';
9 4 $VERSION =~ tr/_//d;
10 4 our $AUTHORITY = 'cpan:BRICKPOOL';
11
12 4 ▶use Exporter 'import';
Subroutine BEGIN: called CC=1 SCAR=0.0
13 4 our @EXPORT = qw(
14 TStringLookupValidator
15 new_TStringLookupValidator
16 );
17
18 4 ▶use TUI::toolkit;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 4 ▶use TUI::toolkit::Types qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
20 Maybe
21 :is
22 :types
23 4 );
24
25 4 ▶use TUI::MsgBox::Const qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
26 mfError
27 mfOKButton
28 4 );
29 4 ▶use TUI::MsgBox::MsgBoxText qw( messageBox );
Subroutine BEGIN: called CC=1 SCAR=0.0
30 4 ▶use TUI::Validate::LookupValidator;
Subroutine BEGIN: called CC=1 SCAR=0.0
31
32 sub TStringLookupValidator() { __PACKAGE__ }
33 sub name() { 'TStringLookupValidator' };
34 0 ▶sub new_TStringLookupValidator { __PACKAGE__->from(@_) }
Subroutine new_TStringLookupValidator: not called CC=1 SCAR=6.9
Pod documented
35
36 4 extends TLookupValidator;
37
38 # declare global variables
39 4 our $errorMsg = "Input is not in list of valid strings";
40
41 # protected attributes
42 0 ▶has strings => ( is => 'ro', default => sub { die 'required' } );
Subroutine __ANON__: not called CC=1 SCAR=1.2
43
44 0 ▶sub BUILDARGS { # \%args (%args)
Subroutine BUILDARGS: not called CC=1 SCAR=6.9
Pod documented
45 0 state $sig = signature(
46 method => 1,
47 named => [
48 strings => Object, { alias => 'aStrings' },
49 ],
50 caller_level => +1,
51 );
52 0 my ( $class, $args ) = $sig->( @_ );
53 0 return { %$args };
54 }
55
56 0 ▶sub from { # $obj ($aStrings)
Subroutine from: not called CC=1 SCAR=6.9
Pod undocumented
57 0 state $sig = signature(
58 method => 1,
59 pos => [Object],
60 );
61 0 my ( $class, $aStrings ) = $sig->( @_ );
62 0 return $class->new( strings => $aStrings );
63 }
64
65 0 ▶sub DEMOLISH { # void ($in_global_destruction)
Subroutine DEMOLISH: not called CC=5 SCAR=34.0
Pod documented
66 0 my ( $self, $in_global_destruction ) = @_;
67 0 ▶ assert ( @_ == 2 );
Branch: 1 branch
BranchTrueFalseTotal
unless @_ == 2 0 0 0
68 0 ▶ assert ( is_Object $self );
Branch: 1 branch
BranchTrueFalseTotal
unless &is_Object($self) 0 0 0
69 0 ▶ assert ( is_Bool $in_global_destruction );
Branch: 1 branch
BranchTrueFalseTotal
unless &is_Bool($in_global_destruction) 0 0 0
70 0 ▶ $self->newStringList( undef ) unless $in_global_destruction;
Branch: 1 branch
BranchTrueFalseTotal
unless $in_global_destruction 0 0 0
71 0 return;
72 }
73
74 0 ▶sub error { # void ()
Subroutine error: not called CC=1 SCAR=6.9
Pod documented
75 0 state $sig = signature(
76 method => Object,
77 pos => [],
78 );
79 0 my ( $self ) = $sig->( @_ );
80 0 messageBox( mfError | mfOKButton, $errorMsg );
81 0 return;
82 }
83
84 0 ▶my $stringMatch = sub { # $bool ($a1, $a2)
Subroutine __ANON__: not called CC=4 SCAR=30.0
85 0 my ( $a1, $a2 ) = @_;
86 0 ▶ assert ( @_ == 2 );
Branch: 1 branch
BranchTrueFalseTotal
unless @_ == 2 0 0 0
87 0 ▶ assert ( is_Str $a1 );
Branch: 1 branch
BranchTrueFalseTotal
unless &is_Str($a1) 0 0 0
88 0 ▶ assert ( is_Str $a2 );
Branch: 1 branch
BranchTrueFalseTotal
unless &is_Str($a2) 0 0 0
89 0 return $a1 eq $a2;
90 4 };
91
92 0 ▶sub lookup { # $bool ($s)
Subroutine lookup: not called CC=2 SCAR=17.9
Pod documented
93 0 state $sig = signature(
94 method => Object,
95 pos => [Str],
96 );
97 0 my ( $self, $s ) = $sig->( @_ );
98 return $self->{strings}
99 0 ▶ && defined $self->{strings}->firstThat( $stringMatch, $s );
Condition0%0/3
$self->{'strings'} && defined $self->{'strings'}->firstThat($stringMatch, $s)
!ll&&!rl&&r
000
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)
ABresult
0X0
100
111
100 }
101
102 0 ▶sub newStringList { # void ($aStrings|undef)
Subroutine newStringList: not called CC=2 SCAR=17.9
Pod documented
103 0 state $sig = signature(
104 method => Object,
105 pos => [Maybe[Object]],
106 );
107 0 my ( $self, $aStrings ) = $sig->( @_ );
108 $self->destroy( $self->{strings} )
109 0 ▶ if ( $self->{strings} );
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"strings"} 0 0 0
110 0 $self->{strings} = $aStrings;
111 0 return;
112 }
113
114 4 1
115
116 __END__
« lib/TUI/Objects/Object.pm ↑ Summary lib/TUI/Gadgets/HeapView/Unix.pm »