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   4275 use strict;
  5         11  
  5         158  
4 5     5   25 use warnings;
  5         12  
  5         171  
5 5     5   28 use base 'Data::Transpose::Validator::Base';
  5         9  
  5         1224  
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 194 my ($self, $string) = @_;
22 91         304 $self->reset_errors;
23 91 100       4549 unless (defined $string) {
24 1         6 $self->error(["undefined", "String is undefined"]);
25 1         4 return 0;
26             }
27 90 100       210 unless (ref($string) eq '') {
28 1         6 $self->error(["hash", "Not a string"]);
29 1         5 return 0;
30             }
31 89         113 my $length = length($string);
32 89 100       176 $self->error(["empty", "Empty string"]) unless $length;
33 89 100       292 $self->error ? return 0 : return $length;
34             }
35              
36             1;