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   17 use strict;
  4         6  
  4         94  
4 4     4   11 use warnings;
  4         4  
  4         72  
5              
6 4     4   11 use base 'Salvation::TC::Type';
  4         5  
  4         236  
7              
8 4     4   16 use Salvation::TC::Exception::WrongType ();
  4         2  
  4         509  
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 13 my ( $class, $min, $max ) = @_;
19              
20             return sub {
21              
22 22     22   24 my $len = length( $_[ 0 ] );
23              
24 22 100 100     86 if( ( $len < $min ) || ( defined $max && ( $len > $max ) ) ) {
      66        
25              
26 7   100     57 Salvation::TC::Exception::WrongType -> throw(
27             'type' => sprintf( 'Text{%s,%s}', $min, ( $max // '' ) ),
28             'value' => $_[ 0 ]
29             );
30             }
31              
32 15         29 1;
33 9         43 };
34             }
35              
36             1
37             __END__