| 1 | package TUI::Validate::FilterValidator; | ||||||||||
| 2 | # ABSTRACT: character-set validator for input fields | ||||||||||
| 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.000002'; | |||||||||
| 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 | TFilterValidator | ||||||||||
| 15 | new_TFilterValidator | ||||||||||
| 16 | ); | ||||||||||
| 17 | |||||||||||
| 18 | 5 | ▶ | use TUI::toolkit; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 19 | 5 | ▶ | use TUI::toolkit::Types qw( | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 20 | Maybe | ||||||||||
| 21 | :types | ||||||||||
| 22 | 5 | ); | |||||||||
| 23 | |||||||||||
| 24 | 5 | ▶ | use TUI::MsgBox::Const qw( | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 25 | mfError | ||||||||||
| 26 | mfOKButton | ||||||||||
| 27 | 5 | ); | |||||||||
| 28 | 5 | ▶ | use TUI::MsgBox::MsgBoxText qw( messageBox ); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 29 | 5 | ▶ | use TUI::Validate::Validator; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 30 | |||||||||||
| 31 | sub TFilterValidator() { __PACKAGE__ } | ||||||||||
| 32 | sub name() { 'TFilterValidator' }; | ||||||||||
| 33 | 0 | ▶ | sub new_TFilterValidator { __PACKAGE__->from(@_) } | ||||||||
|
Subroutine
new_TFilterValidator: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 34 | |||||||||||
| 35 | 5 | extends TValidator; | |||||||||
| 36 | |||||||||||
| 37 | # declare global variables | ||||||||||
| 38 | 5 | our $errorMsg = "Invalid character in input"; | |||||||||
| 39 | |||||||||||
| 40 | # protected attributes | ||||||||||
| 41 | 5 | has validChars => ( is => 'ro', default => '' ); | |||||||||
| 42 | |||||||||||
| 43 | 0 | ▶ | sub BUILDARGS { # \%args (%args) | ||||||||
|
Subroutine
BUILDARGS: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 44 | 0 | state $sig = signature( | |||||||||
| 45 | method => 1, | ||||||||||
| 46 | named => [ | ||||||||||
| 47 | validChars => Str, { optional => 1, alias => 'aValidChars' }, | ||||||||||
| 48 | ], | ||||||||||
| 49 | caller_level => +1, | ||||||||||
| 50 | ); | ||||||||||
| 51 | 0 | my ( $class, $args ) = $sig->( @_ ); | |||||||||
| 52 | 0 | return { %$args }; | |||||||||
| 53 | } | ||||||||||
| 54 | |||||||||||
| 55 | 0 | ▶ | sub from { # $obj ($aValidChars|undef) | ||||||||
|
Subroutine
from: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||
| 56 | 0 | state $sig = signature( | |||||||||
| 57 | method => 1, | ||||||||||
| 58 | pos => [Maybe[Str]], | ||||||||||
| 59 | ); | ||||||||||
| 60 | 0 | my ( $class, $aValidChars ) = $sig->( @_ ); | |||||||||
| 61 | 0 | ▶ | return $class->new( defined $aValidChars | ||||||||
|
Branch: 1 branch
| |||||||||||
| 62 | ? ( validChars => $aValidChars ) | ||||||||||
| 63 | : () | ||||||||||
| 64 | ); | ||||||||||
| 65 | } | ||||||||||
| 66 | |||||||||||
| 67 | 0 | ▶ | sub DEMOLISH { # void ($in_global_destruction) | ||||||||
|
Subroutine
DEMOLISH: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||
| 68 | 0 | my ( $self, $in_global_destruction ) = @_; | |||||||||
| 69 | 0 | ▶ | assert ( @_ == 2 ); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 70 | 0 | ▶ | assert ( is_Object $self ); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 71 | 0 | $self->{validChars} = undef; | |||||||||
| 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 | ▶ | sub isValidInput { # $bool ($s, $suppressFill) | ||||||||
|
Subroutine
isValidInput: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 86 | 0 | state $sig = signature( | |||||||||
| 87 | method => Object, | ||||||||||
| 88 | pos => [Str, Bool], | ||||||||||
| 89 | ); | ||||||||||
| 90 | 0 | my ( $self, $s, $suppressFill ) = $sig->( @_ ); | |||||||||
| 91 | 0 | my $validChars = $self->{validChars}; | |||||||||
| 92 | 0 | return $s !~ /[^$validChars]/; | |||||||||
| 93 | } | ||||||||||
| 94 | |||||||||||
| 95 | 0 | ▶ | sub isValid { # $bool ($s) | ||||||||
|
Subroutine
isValid: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 96 | 0 | state $sig = signature( | |||||||||
| 97 | method => Object, | ||||||||||
| 98 | pos => [Str], | ||||||||||
| 99 | ); | ||||||||||
| 100 | 0 | my ( $self, $s ) = $sig->( @_ ); | |||||||||
| 101 | 0 | my $validChars = $self->{validChars}; | |||||||||
| 102 | 0 | return $s !~ /[^$validChars]/; | |||||||||
| 103 | } | ||||||||||
| 104 | |||||||||||
| 105 | 5 | 1 | |||||||||
| 106 | |||||||||||
| 107 | __END__ | ||||||||||