File Coverage

blib/lib/Salvation/TC/Type/Text.pm
Criterion Covered Total %
statement 18 20 90.0
branch 2 4 50.0
condition 7 11 63.6
subroutine 6 7 85.7
pod 1 2 50.0
total 34 44 77.2


line stmt bran cond sub pod time code
1             package Salvation::TC::Type::Text;
2              
3 4     4   231 use strict;
  4         8  
  4         139  
4 4     4   15 use warnings;
  4         6  
  4         98  
5              
6 4     4   15 use base 'Salvation::TC::Type';
  4         3  
  4         253  
7              
8 4     4   17 use Salvation::TC::Exception::WrongType ();
  4         7  
  4         559  
9              
10              
11             sub Check {
12 0     0 1 0 my ( $class, $value ) = @_;
13 0 0 0     0 ( ! ref( $value ) && $value ne '' ) || Salvation::TC::Exception::WrongType -> throw( 'type' => 'Text', 'value' => $value );
14             }
15              
16             sub create_length_validator {
17              
18 9     9 0 18 my ( $class, $min, $max ) = @_;
19              
20             return sub {
21              
22 22     22   26 my $len = length( $_[ 0 ] );
23              
24 22 100 100     115 if( ( $len < $min ) || ( defined $max && ( $len > $max ) ) ) {
      66        
25              
26 7   100     61 Salvation::TC::Exception::WrongType -> throw(
27             'type' => sprintf( 'Text{%s,%s}', $min, ( $max // '' ) ),
28             'value' => $_[ 0 ]
29             );
30             }
31              
32 15         39 1;
33 9         47 };
34             }
35              
36             1
37             __END__