| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Data::Unixish::wc; |
|
2
|
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
422
|
use 5.010; |
|
|
1
|
|
|
|
|
5
|
|
|
4
|
1
|
|
|
1
|
|
5
|
use strict; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
19
|
|
|
5
|
1
|
|
|
1
|
|
319
|
use syntax 'each_on_array'; # to support perl < 5.12 |
|
|
1
|
|
|
|
|
19465
|
|
|
|
1
|
|
|
|
|
5
|
|
|
6
|
1
|
|
|
1
|
|
3007
|
use warnings; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
23
|
|
|
7
|
|
|
|
|
|
|
#use Log::Any '$log'; |
|
8
|
|
|
|
|
|
|
|
|
9
|
1
|
|
|
1
|
|
415
|
use Data::Unixish::Util qw(%common_args); |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
245
|
|
|
10
|
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our $VERSION = '1.570'; # VERSION |
|
12
|
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
our %SPEC; |
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
$SPEC{wc} = { |
|
16
|
|
|
|
|
|
|
v => 1.1, |
|
17
|
|
|
|
|
|
|
summary => 'Print newline, word, and byte counts', |
|
18
|
|
|
|
|
|
|
description => <<'_', |
|
19
|
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
Behavior mimics that of the Unix utility. The order of the counts |
|
21
|
|
|
|
|
|
|
which is returned is always: newline, word, character, byte, maximum line |
|
22
|
|
|
|
|
|
|
length. |
|
23
|
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
_ |
|
25
|
|
|
|
|
|
|
args => { |
|
26
|
|
|
|
|
|
|
%common_args, |
|
27
|
|
|
|
|
|
|
bytes => { |
|
28
|
|
|
|
|
|
|
summary => "Return the bytes counts", |
|
29
|
|
|
|
|
|
|
schema => [bool => default => 0], |
|
30
|
|
|
|
|
|
|
cmdline_aliases => { c => {} }, |
|
31
|
|
|
|
|
|
|
}, |
|
32
|
|
|
|
|
|
|
chars => { |
|
33
|
|
|
|
|
|
|
summary => "Return the character counts", |
|
34
|
|
|
|
|
|
|
schema => [bool => default => 0], |
|
35
|
|
|
|
|
|
|
cmdline_aliases => { m => {} }, |
|
36
|
|
|
|
|
|
|
}, |
|
37
|
|
|
|
|
|
|
words => { |
|
38
|
|
|
|
|
|
|
summary => "Return the word counts", |
|
39
|
|
|
|
|
|
|
schema => [bool => default => 0], |
|
40
|
|
|
|
|
|
|
cmdline_aliases => { w => {} }, |
|
41
|
|
|
|
|
|
|
}, |
|
42
|
|
|
|
|
|
|
lines => { |
|
43
|
|
|
|
|
|
|
summary => "Return the newline counts", |
|
44
|
|
|
|
|
|
|
schema => [bool => default => 0], |
|
45
|
|
|
|
|
|
|
cmdline_aliases => { l => {} }, |
|
46
|
|
|
|
|
|
|
}, |
|
47
|
|
|
|
|
|
|
max_line_length => { |
|
48
|
|
|
|
|
|
|
summary => "Return the length of the longest line", |
|
49
|
|
|
|
|
|
|
schema => [bool => default => 0], |
|
50
|
|
|
|
|
|
|
cmdline_aliases => { L => {} }, |
|
51
|
|
|
|
|
|
|
}, |
|
52
|
|
|
|
|
|
|
}, |
|
53
|
|
|
|
|
|
|
tags => [qw/text group/], |
|
54
|
|
|
|
|
|
|
"x.dux.strip_newlines" => 0, # for duxapp < 1.41, will be removed later |
|
55
|
|
|
|
|
|
|
"x.app.dux.strip_newlines" => 0, |
|
56
|
|
|
|
|
|
|
}; |
|
57
|
|
|
|
|
|
|
sub wc { |
|
58
|
2
|
|
|
2
|
1
|
5
|
my %args = @_; |
|
59
|
2
|
|
|
|
|
4
|
my ($in, $out) = ($args{in}, $args{out}); |
|
60
|
|
|
|
|
|
|
|
|
61
|
2
|
|
|
|
|
3
|
my ($bytes, $chars, $words, $lines); |
|
62
|
2
|
|
|
|
|
3
|
my $maxllen = 0; |
|
63
|
2
|
|
|
|
|
9
|
while (my ($index, $item) = each @$in) { |
|
64
|
9
|
100
|
100
|
|
|
32
|
next if !defined($item) || ref($item); |
|
65
|
5
|
|
|
|
|
10
|
for my $line (split /^/, $item) { |
|
66
|
6
|
|
|
|
|
7
|
$lines++; |
|
67
|
6
|
|
|
|
|
8
|
$chars += length($line); |
|
68
|
1
|
|
|
1
|
|
481
|
{ use bytes; $bytes += length($line) } |
|
|
1
|
|
|
|
|
12
|
|
|
|
1
|
|
|
|
|
4
|
|
|
|
6
|
|
|
|
|
7
|
|
|
|
6
|
|
|
|
|
7
|
|
|
69
|
6
|
|
|
|
|
15
|
my @w = split /[ \t]+/o, $line; $words += @w; |
|
|
6
|
|
|
|
|
8
|
|
|
70
|
|
|
|
|
|
|
|
|
71
|
6
|
|
|
|
|
9
|
chomp($line); |
|
72
|
6
|
|
|
|
|
8
|
my $llen; |
|
73
|
1
|
|
|
1
|
|
65
|
{ use bytes; $llen = length($line) } |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
4
|
|
|
|
6
|
|
|
|
|
6
|
|
|
|
6
|
|
|
|
|
5
|
|
|
74
|
6
|
100
|
|
|
|
22
|
$maxllen = $llen if $llen > $maxllen; |
|
75
|
|
|
|
|
|
|
} |
|
76
|
|
|
|
|
|
|
} |
|
77
|
|
|
|
|
|
|
|
|
78
|
2
|
|
|
|
|
4
|
my $pbytes = $args{bytes}; |
|
79
|
2
|
|
|
|
|
2
|
my $pchars = $args{chars}; |
|
80
|
2
|
|
|
|
|
3
|
my $pwords = $args{words}; |
|
81
|
2
|
|
|
|
|
2
|
my $plines = $args{lines}; |
|
82
|
2
|
|
|
|
|
3
|
my $pmaxllen = $args{max_line_length}; |
|
83
|
2
|
50
|
66
|
|
|
27
|
if (!$pbytes && !$pchars && !$pwords && !$plines && !$pmaxllen) { |
|
|
|
|
33
|
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
84
|
1
|
|
|
|
|
2
|
$pbytes++; $pwords++; $plines++; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
2
|
|
|
85
|
|
|
|
|
|
|
} |
|
86
|
2
|
|
|
|
|
2
|
my @res; |
|
87
|
2
|
100
|
|
|
|
5
|
push @res, $lines if $plines; |
|
88
|
2
|
100
|
|
|
|
28
|
push @res, $words if $pwords; |
|
89
|
2
|
100
|
|
|
|
4
|
push @res, $chars if $pchars; |
|
90
|
2
|
50
|
|
|
|
4
|
push @res, $bytes if $pbytes; |
|
91
|
2
|
100
|
|
|
|
19
|
push @res, $maxllen if $pmaxllen; |
|
92
|
|
|
|
|
|
|
|
|
93
|
2
|
|
|
|
|
7
|
push @$out, join("\t", @res); |
|
94
|
2
|
|
|
|
|
8
|
[200, "OK"]; |
|
95
|
|
|
|
|
|
|
} |
|
96
|
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
1; |
|
98
|
|
|
|
|
|
|
# ABSTRACT: Print newline, word, and byte counts |
|
99
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
__END__ |