File Coverage

blib/lib/Test/Kantan/Util.pm
Criterion Covered Total %
statement 18 33 54.5
branch 0 8 0.0
condition n/a
subroutine 6 8 75.0
pod 0 2 0.0
total 24 51 47.0


line stmt bran cond sub pod time code
1             package Test::Kantan::Util;
2 3     3   16 use strict;
  3         3  
  3         104  
3 3     3   15 use warnings;
  3         6  
  3         66  
4 3     3   17 use utf8;
  3         4  
  3         25  
5 3     3   110 use 5.010_001;
  3         11  
  3         100  
6 3     3   14 use parent qw(Exporter);
  3         6  
  3         21  
7 3     3   143 use Data::Dumper ();
  3         9  
  3         705  
8              
9             our @EXPORT = qw(dump_data truncstr);
10              
11             sub dump_data {
12 0     0 0   my ($value) = @_;
13              
14 0 0         unless (defined $value) {
15 0           return '(undef)';
16             }
17              
18 0 0         if (ref $value) {
19 0           local $Data::Dumper::Terse = 1;
20 0           local $Data::Dumper::Indent = 0;
21 0           local $Data::Dumper::Sortkeys = 1;
22 0           $value = Data::Dumper::Dumper($value);
23             }
24 0           $value =~ s/\n/\\n/g;
25 0           return $value;
26             }
27              
28             sub truncstr {
29 0     0 0   my ($message, $cutoff) = @_;
30 0 0         return $message unless defined $cutoff;
31              
32 0 0         if (length($message) > $cutoff) {
33 0           return substr($message, 0, $cutoff-3) . '...';
34             } else {
35 0           return $message;
36             }
37             }
38              
39             1;