line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package String::Elide::FromArray; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
our $DATE = '2017-07-28'; # DATE |
4
|
|
|
|
|
|
|
our $VERSION = '0.001'; # VERSION |
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
82334
|
use 5.010001; |
|
1
|
|
|
|
|
3
|
|
7
|
1
|
|
|
1
|
|
9
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
38
|
|
8
|
1
|
|
|
1
|
|
8
|
use warnings; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
48
|
|
9
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
6
|
use Exporter qw(import); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
360
|
|
11
|
|
|
|
|
|
|
our @EXPORT_OK = qw(elide); |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub _elide_str { |
14
|
11
|
|
|
11
|
|
36
|
my ($str, $len, $opts) = @_; |
15
|
11
|
|
50
|
|
|
30
|
$opts //= {}; |
16
|
11
|
|
50
|
|
|
35
|
$opts->{marker} //= '..'; |
17
|
|
|
|
|
|
|
|
18
|
11
|
100
|
|
|
|
50
|
return $str if length($str) <= $len; |
19
|
6
|
|
|
|
|
20
|
my $l = $len - length($opts->{marker}); |
20
|
6
|
50
|
|
|
|
33
|
$str = ($l > 0 ? substr($str, 0, $l) : '') . $opts->{marker}; |
21
|
6
|
50
|
|
|
|
61
|
return $str if length($str) <= $len; |
22
|
0
|
|
|
|
|
0
|
substr($str, 0, $len); |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub elide { |
26
|
11
|
|
|
11
|
1
|
28364
|
my ($ary, $len, $opts) = @_; |
27
|
11
|
|
100
|
|
|
70
|
$opts //= {}; |
28
|
11
|
|
100
|
|
|
87
|
$opts->{marker} //= '..'; |
29
|
11
|
|
100
|
|
|
64
|
$opts->{list_marker} //= '..'; |
30
|
11
|
|
100
|
|
|
60
|
$opts->{item_marker} //= '..'; |
31
|
11
|
|
100
|
|
|
60
|
$opts->{sep} //= ', '; |
32
|
|
|
|
|
|
|
|
33
|
11
|
|
|
|
|
21
|
my @ary; |
34
|
11
|
100
|
|
|
|
37
|
if ($opts->{max_item_len}) { |
35
|
2
|
|
|
|
|
9
|
@ary = map { _elide_str($_, $opts->{max_item_len}, |
36
|
7
|
|
|
|
|
34
|
{marker=>$opts->{item_marker}}) } @$ary; |
37
|
|
|
|
|
|
|
} else { |
38
|
9
|
|
|
|
|
32
|
@ary = @$ary; |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
11
|
|
|
|
|
26
|
my $str; |
42
|
11
|
100
|
|
|
|
39
|
if ($opts->{max_items}) { |
43
|
2
|
50
|
|
|
|
12
|
if (@ary > $opts->{max_items}) { |
44
|
2
|
|
|
|
|
8
|
splice @ary, $opts->{max_items}; |
45
|
2
|
|
|
|
|
7
|
push @ary, $opts->{list_marker}; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
} |
48
|
11
|
|
|
|
|
48
|
$str = join($opts->{sep}, @ary); |
49
|
|
|
|
|
|
|
|
50
|
11
|
100
|
|
|
|
36
|
if (length($str) <= $len) { |
51
|
7
|
|
|
|
|
66
|
return $str; |
52
|
|
|
|
|
|
|
} else { |
53
|
4
|
|
|
|
|
25
|
return _elide_str($str, $len, {marker=>$opts->{marker}}); |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
1; |
58
|
|
|
|
|
|
|
# ABSTRACT: Truncate string containing list of items |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
__END__ |