| 1 | package Validator::Lazy::Role::Check::Case; | ||||||||||||
| 2 | |||||||||||||
| 3 | 2 | our $VERSION = '0.03'; | |||||||||||
| 4 | |||||||||||||
| 5 | =head1 NAME | ||||||||||||
| 6 | |||||||||||||
| 7 | Validator::Lazy::Role::Check::Case | ||||||||||||
| 8 | |||||||||||||
| 9 | |||||||||||||
| 10 | =head1 VERSION | ||||||||||||
| 11 | |||||||||||||
| 12 | Version 0.03 | ||||||||||||
| 13 | |||||||||||||
| 14 | |||||||||||||
| 15 | =head1 SYNOPSIS | ||||||||||||
| 16 | |||||||||||||
| 17 | use Validator::Lazy; | ||||||||||||
| 18 | my $v = Validator::Lazy->new( { case => { Case => 'all_first_upper' } } ); # upper lower first_upper all_first_upper | ||||||||||||
| 19 | |||||||||||||
| 20 | my( $ok,$data ) = $v->check( case => 'john smith' ); | ||||||||||||
| 21 | |||||||||||||
| 22 | say $data->{case}; # John Smith | ||||||||||||
| 23 | |||||||||||||
| 24 | |||||||||||||
| 25 | =head1 DESCRIPTION | ||||||||||||
| 26 | |||||||||||||
| 27 | An internal Role for Validator::Lazy, part of Validator::Lazy package. | ||||||||||||
| 28 | |||||||||||||
| 29 | Provides "Case" type for Validator::Lazy config. | ||||||||||||
| 30 | Allows to change case for checked data scalars. | ||||||||||||
| 31 | Do not performs any validations. | ||||||||||||
| 32 | |||||||||||||
| 33 | |||||||||||||
| 34 | =head1 METHODS | ||||||||||||
| 35 | |||||||||||||
| 36 | =head2 C<check> | ||||||||||||
| 37 | |||||||||||||
| 38 | Called from inside if Validator::Lazy->check process | ||||||||||||
| 39 | |||||||||||||
| 40 | Temporary overrides internal Validator::Lazy::check method like this: | ||||||||||||
| 41 | |||||||||||||
| 42 | $validator->check( $value, $param ); | ||||||||||||
| 43 | |||||||||||||
| 44 | $param - scalar. can be one of [ upper, lower, first_upper, all_first_upper ] | ||||||||||||
| 45 | $value - your value to check, that should be converted as demanded by $param | ||||||||||||
| 46 | |||||||||||||
| 47 | param value means: | ||||||||||||
| 48 | |||||||||||||
| 49 | upper - all letters in value will be converted to upper case | ||||||||||||
| 50 | lower - all letters in value will be converted to lower case | ||||||||||||
| 51 | first_upper - just the first letter will be converted to upper case | ||||||||||||
| 52 | all_first_upper - first letter of each word in the $value will be converted to upper case | ||||||||||||
| 53 | |||||||||||||
| 54 | |||||||||||||
| 55 | =head1 SUPPORT AND DOCUMENTATION | ||||||||||||
| 56 | |||||||||||||
| 57 | After installing, you can find documentation for this module with the perldoc command. | ||||||||||||
| 58 | |||||||||||||
| 59 | perldoc Validator::Lazy | ||||||||||||
| 60 | |||||||||||||
| 61 | You can also look for information at: | ||||||||||||
| 62 | |||||||||||||
| 63 | RT, CPAN's request tracker (report bugs here) | ||||||||||||
| 64 | http://rt.cpan.org/NoAuth/Bugs.html?Dist=Validator-Lazy | ||||||||||||
| 65 | |||||||||||||
| 66 | AnnoCPAN, Annotated CPAN documentation | ||||||||||||
| 67 | http://annocpan.org/dist/Validator-Lazy | ||||||||||||
| 68 | |||||||||||||
| 69 | CPAN Ratings | ||||||||||||
| 70 | http://cpanratings.perl.org/d/Validator-Lazy | ||||||||||||
| 71 | |||||||||||||
| 72 | Search CPAN | ||||||||||||
| 73 | http://search.cpan.org/dist/Validator-Lazy/ | ||||||||||||
| 74 | |||||||||||||
| 75 | |||||||||||||
| 76 | =head1 AUTHOR | ||||||||||||
| 77 | |||||||||||||
| 78 | ANTONC <antonc@cpan.org> | ||||||||||||
| 79 | |||||||||||||
| 80 | =head1 LICENSE | ||||||||||||
| 81 | |||||||||||||
| 82 | This program is free software; you can redistribute it and/or modify it | ||||||||||||
| 83 | under the terms of the the Artistic License (2.0). You may obtain a | ||||||||||||
| 84 | copy of the full license at: | ||||||||||||
| 85 | |||||||||||||
| 86 | L<http://www.perlfoundation.org/artistic_license_2_0> | ||||||||||||
| 87 | |||||||||||||
| 88 | =cut | ||||||||||||
| 89 | |||||||||||||
| 90 | 2 | ▶ | use v5.14.0; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 91 | 2 | ▶ | use utf8; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 92 | 2 | ▶ | use Modern::Perl; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 93 | 2 | ▶ | use Moose::Role; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 94 | |||||||||||||
| 95 | |||||||||||||
| 96 | 5 | ▶ | sub check { | ||||||||||
|
Subroutine
check: called CC=3 SCAR=11.4
Pod
documented
| |||||||||||||
| 97 | 5 | my ( $self, $value, $param ) = @_; | |||||||||||
| 98 | |||||||||||||
| 99 | 5 | ▶ | return $value unless $value; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 100 | |||||||||||||
| 101 | 5 | ▶ | $param //= 'upper'; | ||||||||||
|
Condition50%1/2
$param //= "upper"
MC/DC0%0/1
$param //= "upper"
$param
Truth table50%1/2
A
A= $param
| |||||||||||||
| 102 | |||||||||||||
| 103 | return { | ||||||||||||
| 104 | upper => uc( $value ), | ||||||||||||
| 105 | lower => lc( $value ), | ||||||||||||
| 106 | first_upper => _fuc( $value ), | ||||||||||||
| 107 | all_first_upper => _afuc( $value ), | ||||||||||||
| 108 | 5 | }->{ $param }; | |||||||||||
| 109 | }; | ||||||||||||
| 110 | |||||||||||||
| 111 | |||||||||||||
| 112 | 10 | ▶ | sub _fuc { | ||||||||||
|
Subroutine
_fuc: called CC=1 SCAR=0.0
| |||||||||||||
| 113 | 10 | my $value = shift; | |||||||||||
| 114 | |||||||||||||
| 115 | 10 | $value = lc $value; | |||||||||||
| 116 | 10 | $value =~ s/^(.)/uc($1)/eg; | |||||||||||
| 117 | |||||||||||||
| 118 | 10 | return $value; | |||||||||||
| 119 | } | ||||||||||||
| 120 | |||||||||||||
| 121 | |||||||||||||
| 122 | 5 | ▶ | sub _afuc { | ||||||||||
|
Subroutine
_afuc: called CC=1 SCAR=0.0
| |||||||||||||
| 123 | 5 | my $value = shift; | |||||||||||
| 124 | |||||||||||||
| 125 | 5 | $value = lc $value; | |||||||||||
| 126 | 5 | $value = _fuc( $value ); | |||||||||||
| 127 | 5 | $value =~ s/(?<=\W)(.)/uc($1)/eg; | |||||||||||
| 128 | |||||||||||||
| 129 | 5 | return $value; | |||||||||||
| 130 | } | ||||||||||||
| 131 | |||||||||||||
| 132 | |||||||||||||
| 133 | 2 | 1; | |||||||||||