line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
1
|
|
|
1
|
|
1118
|
use strict; use warnings; |
|
1
|
|
|
1
|
|
1
|
|
|
1
|
|
|
|
|
22
|
|
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
26
|
|
2
|
|
|
|
|
|
|
package Swim::Command; |
3
|
1
|
|
|
1
|
|
3
|
use Pegex::Base; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
4
|
|
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
1152
|
use Swim; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
16
|
|
6
|
1
|
|
|
1
|
|
308
|
use Swim::Util; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
23
|
|
7
|
1
|
|
|
1
|
|
344
|
use FindBin; |
|
1
|
|
|
|
|
783
|
|
|
1
|
|
|
|
|
33
|
|
8
|
1
|
|
|
1
|
|
575
|
use Getopt::Long; |
|
1
|
|
|
|
|
8222
|
|
|
1
|
|
|
|
|
11
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
has argv => (); |
11
|
|
|
|
|
|
|
has to => 'html'; |
12
|
|
|
|
|
|
|
has meta => {}; |
13
|
|
|
|
|
|
|
has option => {}; |
14
|
|
|
|
|
|
|
has debug => 0; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub usage { |
17
|
0
|
|
|
0
|
0
|
|
print <<'...'; |
18
|
|
|
|
|
|
|
Usage: |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
swim --to= [ |
21
|
|
|
|
|
|
|
swim -h|--help |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
Formats: |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
html # HTML |
26
|
|
|
|
|
|
|
md # Markdown |
27
|
|
|
|
|
|
|
pod # Pod |
28
|
|
|
|
|
|
|
txt # Plain text |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
man # nroff / manpage |
31
|
|
|
|
|
|
|
pdf # PDF |
32
|
|
|
|
|
|
|
dvi # DVI |
33
|
|
|
|
|
|
|
ps # Postscript |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
byte # Swim Bytecode |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
Options: |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
--meta= # YAML or JSON file containing metadata |
40
|
|
|
|
|
|
|
--wrap # Attempt to wrap output to 80 cols |
41
|
|
|
|
|
|
|
--complete # Add header and footer output as appropriate |
42
|
|
|
|
|
|
|
--pod-upper-head # Convert header1 titles to uppercase |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
... |
45
|
0
|
|
|
|
|
|
exit 0 |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
my $meta = {}; |
49
|
|
|
|
|
|
|
sub run { |
50
|
0
|
|
|
0
|
0
|
|
my ($self) = @_; |
51
|
0
|
|
|
|
|
|
local @ARGV = @{$self->argv}; |
|
0
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
|
53
|
0
|
|
|
|
|
|
my $pod_cpan = 0; |
54
|
|
|
|
|
|
|
my %opt_spec = ( |
55
|
|
|
|
|
|
|
"h|help" => \&usage, |
56
|
|
|
|
|
|
|
"to=s" => \$self->{to}, |
57
|
|
|
|
|
|
|
"debug" => \$self->{debug}, |
58
|
|
|
|
|
|
|
"meta=s" => \&meta_opt, |
59
|
|
|
|
|
|
|
"complete!" => \$self->{option}{complete}, |
60
|
|
|
|
|
|
|
"wrap!" => \$self->{option}{wrap}, |
61
|
0
|
|
|
|
|
|
"pod-upper-head!" => \$self->{option}{'pod-upper-head'}, |
62
|
|
|
|
|
|
|
"pod-cpan" => \$pod_cpan, |
63
|
|
|
|
|
|
|
); |
64
|
0
|
0
|
|
|
|
|
GetOptions(%opt_spec) or die "Error in command line arguments"; |
65
|
0
|
0
|
|
|
|
|
if ($pod_cpan) { |
66
|
0
|
|
|
|
|
|
$self->{to} = 'pod'; |
67
|
0
|
|
|
|
|
|
$self->option->{complete} = 1; |
68
|
0
|
|
|
|
|
|
$self->option->{wrap} = 1; |
69
|
0
|
|
|
|
|
|
$self->option->{'pod-upper-head'} = 1; |
70
|
|
|
|
|
|
|
} |
71
|
0
|
|
|
|
|
|
$self->{meta} = $meta; |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
binmode(STDOUT, ':utf8') |
74
|
0
|
0
|
|
|
|
|
unless $self->{to} eq 'man'; |
75
|
0
|
|
|
|
|
|
my $text = Swim::Util->slurp(@ARGV); |
76
|
|
|
|
|
|
|
|
77
|
0
|
|
|
|
|
|
my $method = "to_" . $self->to; |
78
|
0
|
|
|
|
|
|
print Swim->new( |
79
|
|
|
|
|
|
|
text => $text, |
80
|
|
|
|
|
|
|
meta => $meta, |
81
|
|
|
|
|
|
|
option => $self->option, |
82
|
|
|
|
|
|
|
debug => $self->debug, |
83
|
|
|
|
|
|
|
)->$method(); |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
sub meta_opt { |
87
|
0
|
|
|
0
|
0
|
|
my ($option, $value) = @_; |
88
|
0
|
|
|
|
|
|
for my $file (split /,/, $value) { |
89
|
0
|
|
|
|
|
|
my $yaml = Swim::Util->slurp($file); |
90
|
0
|
|
|
|
|
|
$meta = Swim::Util->merge_meta($meta, $yaml); |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
1; |