Lazy/Role/Check/Trim.pm

filter: Statementstmt 96.1% 25 / 26 Branchbran 85.7% 12 / 14 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 5 / 5 Podpod 100% 1 / 1 totaltotal 86.2% 44 / 51 CC 10 SCAR 20.5
CC
10
Cov
88%
check
10.5
BEGIN
1.0
BEGIN
1.0
CRAP 7.8
« Lazy/Role/Check/CountryCode.pm ↑ Summary Lazy/Role/Check/Form.pm »
1 package Validator::Lazy::Role::Check::Trim;
2  
3 2 our $VERSION = '0.03';
4  
5 =head1 NAME
6  
7 Validator::Lazy::Role::Check::Trim
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( { trim => { Trim => 'all' } } ); # trim all unwanted spaces from a value
19  
20 my( $ok,$data ) = $v->check( trim => ' john smith ' );
21  
22 say $data->{trim}; # 'john smith'
23  
24  
25 =head1 DESCRIPTION
26  
27 An internal Role for Validator::Lazy, part of Validator::Lazy package.
28  
29 Provides "Trim" type for Validator::Lazy config.
30 Allows to trim value's spaces.
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 or list. can have one or any of values = [ left right inner all ]
45 $value - your value to do with.
46  
47  
48 =head1 SUPPORT AND DOCUMENTATION
49  
50 After installing, you can find documentation for this module with the perldoc command.
51  
52 perldoc Validator::Lazy
53  
54 You can also look for information at:
55  
56 RT, CPAN's request tracker (report bugs here)
57 http://rt.cpan.org/NoAuth/Bugs.html?Dist=Validator-Lazy
58  
59 AnnoCPAN, Annotated CPAN documentation
60 http://annocpan.org/dist/Validator-Lazy
61  
62 CPAN Ratings
63 http://cpanratings.perl.org/d/Validator-Lazy
64  
65 Search CPAN
66 http://search.cpan.org/dist/Validator-Lazy/
67  
68  
69 =head1 AUTHOR
70  
71 ANTONC <antonc@cpan.org>
72  
73 =head1 LICENSE
74  
75 This program is free software; you can redistribute it and/or modify it
76 under the terms of the the Artistic License (2.0). You may obtain a
77 copy of the full license at:
78  
79 L<http://www.perlfoundation.org/artistic_license_2_0>
80  
81 =cut
82  
83 2 ▶use v5.14.0;
Subroutine BEGIN: called CC=1 SCAR=0.0
84 2 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
85 2 ▶use Modern::Perl;
Subroutine BEGIN: called CC=1 SCAR=0.0
86 2 ▶use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
87  
88 5 ▶sub check {
Subroutine check: called CC=10 SCAR=23.5
Pod documented
89 5 my ( $self, $value, $param ) = @_;
90  
91 5 ▶ return $value unless $value && $param;
Branch: 1 branch
BranchTrueFalseTotal
unless $value and $param 0 5 5
Condition33%1/3
$value and $param
!ll&&!rl&&r
005
MC/DC0%0/2
$value and $param
$value $param
Truth table33%1/3
A and B
A= $valueB= $param
ABresult
0X0
100
111
92  
93 5 ▶ $param = [ $param ] unless ref $param;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $param 4 1 5
94 5 my @rules = @$param;
95  
96 5 ▶ if ( grep /^all$/, @rules ) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep /^all$/u, @rules) 1 4 5
97 1 push @rules, qw/ left right inner /;
98 };
99  
100 5 for ( @rules ) {
101 9 ▶ if ( /^left$/ ) { $value =~ s/^\s+//smg; }
Branch: 4 branches
BranchTrueFalseTotal
if (/^left$/u) { } 3 6 9
elsif (/^right$/u) { } 3 3 6
elsif (/^inner$/u) { } 2 1 3
elsif (/^all$/u) { } 1 0 1
102 3 elsif ( /^right$/ ) { $value =~ s/\s+$//smg; }
103 2 elsif ( /^inner$/ ) { $value =~ s/(?<=\S)\s+(?=\S)/ /smg; }
104 elsif ( /^all$/ ) { } # do nothing, this rule splitted on 'left' + 'right' + 'inner'
105 0 else { confess 'Unknown rule: ' . $_ };
106 };
107  
108 5 return $value;
109 };
110  
111 2 1;
« Lazy/Role/Check/CountryCode.pm ↑ Summary Lazy/Role/Check/Form.pm »