| 1 | package TUI::Validate::FilterValidator; | ||||||||||
| 2 | # ABSTRACT: character-set validator for input fields | ||||||||||
| 3 | |||||||||||
| 4 | 7 | ▶ | use 5.010; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 7 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 7 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | |||||||||||
| 8 | 7 | our $VERSION = '2.000003'; | |||||||||
| 9 | 7 | $VERSION =~ tr/_//d; | |||||||||
| 10 | 7 | our $AUTHORITY = 'cpan:BRICKPOOL'; | |||||||||
| 11 | |||||||||||
| 12 | 7 | ▶ | use Exporter 'import'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 13 | 7 | our @EXPORT = qw( | |||||||||
| 14 | TFilterValidator | ||||||||||
| 15 | new_TFilterValidator | ||||||||||
| 16 | ); | ||||||||||
| 17 | |||||||||||
| 18 | 7 | ▶ | use Storable; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 19 | 7 | ▶ | use TUI::toolkit; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 20 | 7 | ▶ | use TUI::toolkit::Types qw( | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 21 | Maybe | ||||||||||
| 22 | :types | ||||||||||
| 23 | 7 | ); | |||||||||
| 24 | |||||||||||
| 25 | 7 | ▶ | use TUI::MsgBox::Const qw( | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 26 | mfError | ||||||||||
| 27 | mfOKButton | ||||||||||
| 28 | 7 | ); | |||||||||
| 29 | 7 | ▶ | use TUI::MsgBox::MsgBoxText qw( messageBox ); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 30 | 7 | ▶ | use TUI::Validate::Validator; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 31 | |||||||||||
| 32 | sub TFilterValidator() { __PACKAGE__ } | ||||||||||
| 33 | sub name() { 'TFilterValidator' }; | ||||||||||
| 34 | 0 | ▶ | sub new_TFilterValidator { __PACKAGE__->from(@_) } | ||||||||
|
Subroutine
new_TFilterValidator: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 35 | |||||||||||
| 36 | 7 | extends TValidator; | |||||||||
| 37 | |||||||||||
| 38 | # declare global variables | ||||||||||
| 39 | 7 | our $errorMsg = "Invalid character in input"; | |||||||||
| 40 | |||||||||||
| 41 | # protected attributes | ||||||||||
| 42 | 7 | has validChars => ( is => 'ro', default => '' ); | |||||||||
| 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 | validChars => Str, { optional => 1, alias => 'aValidChars' }, | ||||||||||
| 49 | ], | ||||||||||
| 50 | caller_level => +1, | ||||||||||
| 51 | ); | ||||||||||
| 52 | 0 | my ( $class, $args ) = $sig->( @_ ); | |||||||||
| 53 | 0 | return { %$args }; | |||||||||
| 54 | } | ||||||||||
| 55 | |||||||||||
| 56 | 0 | ▶ | sub from { # $obj ($aValidChars|undef) | ||||||||
|
Subroutine
from: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||
| 57 | 0 | state $sig = signature( | |||||||||
| 58 | method => 1, | ||||||||||
| 59 | pos => [Maybe[Str]], | ||||||||||
| 60 | ); | ||||||||||
| 61 | 0 | my ( $class, $aValidChars ) = $sig->( @_ ); | |||||||||
| 62 | 0 | ▶ | return $class->new( defined $aValidChars | ||||||||
|
Branch: 1 branch
| |||||||||||
| 63 | ? ( validChars => $aValidChars ) | ||||||||||
| 64 | : () | ||||||||||
| 65 | ); | ||||||||||
| 66 | } | ||||||||||
| 67 | |||||||||||
| 68 | 0 | ▶ | sub DEMOLISH { # void ($in_global_destruction) | ||||||||
|
Subroutine
DEMOLISH: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||
| 69 | 0 | my ( $self, $in_global_destruction ) = @_; | |||||||||
| 70 | 0 | ▶ | assert ( @_ == 2 ); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 71 | 0 | ▶ | assert ( is_Object $self ); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 72 | 0 | $self->{validChars} = undef; | |||||||||
| 73 | 0 | return; | |||||||||
| 74 | } | ||||||||||
| 75 | |||||||||||
| 76 | 0 | ▶ | sub error { # void () | ||||||||
|
Subroutine
error: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 77 | 0 | state $sig = signature( | |||||||||
| 78 | method => Object, | ||||||||||
| 79 | pos => [], | ||||||||||
| 80 | ); | ||||||||||
| 81 | 0 | my ( $self ) = $sig->( @_ ); | |||||||||
| 82 | 0 | messageBox( mfError | mfOKButton, $errorMsg ); | |||||||||
| 83 | 0 | return; | |||||||||
| 84 | } | ||||||||||
| 85 | |||||||||||
| 86 | 0 | ▶ | sub isValidInput { # $bool ($s, $suppressFill) | ||||||||
|
Subroutine
isValidInput: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 87 | 0 | state $sig = signature( | |||||||||
| 88 | method => Object, | ||||||||||
| 89 | pos => [Str, Bool], | ||||||||||
| 90 | ); | ||||||||||
| 91 | 0 | my ( $self, $s, $suppressFill ) = $sig->( @_ ); | |||||||||
| 92 | 0 | my $validChars = $self->{validChars}; | |||||||||
| 93 | 0 | return $s !~ /[^$validChars]/; | |||||||||
| 94 | } | ||||||||||
| 95 | |||||||||||
| 96 | 0 | ▶ | sub isValid { # $bool ($s) | ||||||||
|
Subroutine
isValid: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 97 | 0 | state $sig = signature( | |||||||||
| 98 | method => Object, | ||||||||||
| 99 | pos => [Str], | ||||||||||
| 100 | ); | ||||||||||
| 101 | 0 | my ( $self, $s ) = $sig->( @_ ); | |||||||||
| 102 | 0 | my $validChars = $self->{validChars}; | |||||||||
| 103 | 0 | return $s !~ /[^$validChars]/; | |||||||||
| 104 | } | ||||||||||
| 105 | |||||||||||
| 106 | 0 | ▶ | sub write :method { # void ($os) | ||||||||
|
Subroutine
write: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 107 | 0 | state $sig = signature( | |||||||||
| 108 | method => Object, | ||||||||||
| 109 | pos => [Object], | ||||||||||
| 110 | ); | ||||||||||
| 111 | 0 | my ( $self, $os ) = $sig->( @_ ); | |||||||||
| 112 | 0 | $self->SUPER::write( $os ); | |||||||||
| 113 | 0 | $os->put( $self->{validChars} ); | |||||||||
| 114 | 0 | return; | |||||||||
| 115 | } | ||||||||||
| 116 | |||||||||||
| 117 | 0 | ▶ | sub read :method { # $self ($is) | ||||||||
|
Subroutine
read: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 118 | 0 | state $sig = signature( | |||||||||
| 119 | method => Object, | ||||||||||
| 120 | pos => [Object], | ||||||||||
| 121 | ); | ||||||||||
| 122 | 0 | my ( $self, $is ) = $sig->( @_ ); | |||||||||
| 123 | 0 | $self->SUPER::read( $is ); | |||||||||
| 124 | 0 | $self->{validChars} = $is->get(); | |||||||||
| 125 | 0 | return $self; | |||||||||
| 126 | } | ||||||||||
| 127 | |||||||||||
| 128 | 0 | ▶ | sub build { # $obj () | ||||||||
|
Subroutine
build: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||
| 129 | 0 | my ( $class ) = @_; | |||||||||
| 130 | 0 | ▶ | assert ( @_ == 1 ); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 131 | 0 | ▶ | assert ( is_Str $class ); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 132 | 0 | ▶ | assert ( Storable::is_retrieving ); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 133 | 0 | return $class->new(); | |||||||||
| 134 | } | ||||||||||
| 135 | |||||||||||
| 136 | 7 | 1 | |||||||||
| 137 | |||||||||||
| 138 | __END__ | ||||||||||