File Coverage

blib/lib/Data/Transpose/Validator/String.pm
Criterion Covered Total %
statement 20 20 100.0
branch 8 8 100.0
condition n/a
subroutine 4 4 100.0
pod 1 1 100.0
total 33 33 100.0


line stmt bran cond sub pod time code
1             package Data::Transpose::Validator::String;
2              
3 5     5   3213 use strict;
  5         8  
  5         171  
4 5     5   24 use warnings;
  5         7  
  5         193  
5 5     5   26 use base 'Data::Transpose::Validator::Base';
  5         9  
  5         1086  
6              
7             =head1 NAME
8              
9             Data::Transpose::Validator::String Validator for strings
10              
11             =cut
12              
13             =head2 is_valid
14              
15             Check with C if the argument is a string. Return true on success
16             (the length of the string). It fails on the empty string.
17              
18             =cut
19              
20             sub is_valid {
21 91     91 1 179 my ($self, $string) = @_;
22 91         279 $self->reset_errors;
23 91 100       4720 unless (defined $string) {
24 1         8 $self->error(["undefined", "String is undefined"]);
25 1         7 return 0;
26             }
27 90 100       213 unless (ref($string) eq '') {
28 1         5 $self->error(["hash", "Not a string"]);
29 1         4 return 0;
30             }
31 89         126 my $length = length($string);
32 89 100       165 $self->error(["empty", "Empty string"]) unless $length;
33 89 100       277 $self->error ? return 0 : return $length;
34             }
35              
36             1;