line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#!/usr/bin/env perl |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
=pod |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
=head1 NAME |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
wrt-feed - print an Atom or JSON feed from given wrt entries |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
=head1 USAGE |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
# Print most recent entries: |
12
|
|
|
|
|
|
|
wrt feed |
13
|
|
|
|
|
|
|
wrt feed --json |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
# Print entries for a specific month: |
16
|
|
|
|
|
|
|
wrt feed 2019/11 |
17
|
|
|
|
|
|
|
wrt feed --json 2019/11 |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
=head1 DESCRIPTION |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
Detailed documentation can be found in the L man page or at |
22
|
|
|
|
|
|
|
L. |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
=head1 LICENSE |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
wrt is free software; you can redistribute it and/or modify |
27
|
|
|
|
|
|
|
it under the terms of the GNU General Public License as published by |
28
|
|
|
|
|
|
|
the Free Software Foundation; either version 2 of the License, or |
29
|
|
|
|
|
|
|
(at your option) any later version. |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
=head1 AUTHOR |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
Brennen Bearnes |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
=cut |
36
|
|
|
|
|
|
|
|
37
|
1
|
|
|
1
|
|
479
|
use 5.14.0; |
|
1
|
|
|
|
|
3
|
|
38
|
|
|
|
|
|
|
|
39
|
1
|
|
|
1
|
|
6
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
17
|
|
40
|
1
|
|
|
1
|
|
3
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
33
|
|
41
|
1
|
|
|
1
|
|
4
|
no warnings 'uninitialized'; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
47
|
|
42
|
1
|
|
|
1
|
|
5
|
use utf8; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
4
|
|
43
|
1
|
|
|
1
|
|
474
|
use open qw(:std :utf8); |
|
1
|
|
|
|
|
999
|
|
|
1
|
|
|
|
|
5
|
|
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
# use Data::Dumper; |
46
|
1
|
|
|
1
|
|
438
|
use App::WRT; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
36
|
|
47
|
|
|
|
|
|
|
|
48
|
1
|
|
|
1
|
|
6
|
use Carp; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
62
|
|
49
|
1
|
|
|
1
|
|
5
|
use Getopt::Long qw(GetOptionsFromArray); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
9
|
|
50
|
1
|
|
|
1
|
|
132
|
use Pod::Usage; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
444
|
|
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
# If invoked directly from the command-line, caller() will return undef. |
53
|
|
|
|
|
|
|
# Execute main() with a callback to print output directly, and a copy of |
54
|
|
|
|
|
|
|
# our real @ARGV: |
55
|
|
|
|
|
|
|
if (not caller()) { |
56
|
|
|
|
|
|
|
my $output = sub { say @_; }; |
57
|
|
|
|
|
|
|
my $retval = main($output, @ARGV); |
58
|
|
|
|
|
|
|
exit($retval); |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub main { |
62
|
1
|
|
|
1
|
|
519
|
my ($output, @local_argv) = @_; |
63
|
|
|
|
|
|
|
# Handle options, including help generated from the POD above. See: |
64
|
|
|
|
|
|
|
# - http://perldoc.perl.org/Getopt/Long.html#User-defined-subroutines-to-handle-options |
65
|
|
|
|
|
|
|
# - https://metacpan.org/pod/Pod::Usage |
66
|
|
|
|
|
|
|
# - http://michael.thegrebs.com/2014/06/08/Pod-Usage/ |
67
|
1
|
|
|
|
|
3
|
my $from_stdin = 0; |
68
|
1
|
|
|
|
|
1
|
my $print_json = 0; |
69
|
1
|
|
|
|
|
2
|
my $config_file = 'wrt.json'; |
70
|
|
|
|
|
|
|
GetOptionsFromArray( |
71
|
|
|
|
|
|
|
\@local_argv, |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
stdin => \$from_stdin, |
74
|
|
|
|
|
|
|
json => \$print_json, |
75
|
|
|
|
|
|
|
'config=s' => \$config_file, |
76
|
0
|
|
|
0
|
|
0
|
help => sub { pod2usage(0) }, |
77
|
|
|
|
|
|
|
|
78
|
1
|
50
|
|
|
|
5
|
) or pod2usage(2); |
79
|
|
|
|
|
|
|
|
80
|
1
|
50
|
|
|
|
328
|
unless (-e $config_file) { |
81
|
0
|
|
|
|
|
0
|
croak "No wrt config file found. Tried: $config_file"; |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
1
|
|
|
|
|
4
|
my $w = App::WRT::new_from_file($config_file); |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
# With --stdin, take names of entries to display from standard input, one line |
87
|
|
|
|
|
|
|
# per name. Otherwise, take names from arguments if any are given, or fall |
88
|
|
|
|
|
|
|
# back to most recent entries. |
89
|
1
|
|
|
|
|
4
|
my @to_display = (); |
90
|
1
|
50
|
|
|
|
5
|
if ($from_stdin) { |
|
|
50
|
|
|
|
|
|
91
|
0
|
|
|
|
|
0
|
while (my $entry = <>) { |
92
|
0
|
|
|
|
|
0
|
chomp($entry); |
93
|
0
|
|
|
|
|
0
|
push @to_display, $entry; |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
} elsif (@local_argv) { |
96
|
0
|
|
|
|
|
0
|
(@to_display) = @local_argv; |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
1
|
|
|
|
|
2
|
my (@expanded_to_display) = map { $w->expand_alias($_) } @to_display; |
|
0
|
|
|
|
|
0
|
|
100
|
|
|
|
|
|
|
|
101
|
1
|
|
|
|
|
3
|
foreach my $entry (@expanded_to_display) { |
102
|
0
|
0
|
|
|
|
0
|
unless ($w->{entries}->is_extant($entry)) { |
103
|
|
|
|
|
|
|
# TODO: Better error reporting strategy, print this on stderr: |
104
|
0
|
|
|
|
|
0
|
say("No such entry: $entry"); |
105
|
0
|
|
|
|
|
0
|
return 1; |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
|
109
|
1
|
50
|
|
|
|
2
|
if (@expanded_to_display) { |
110
|
0
|
0
|
|
|
|
0
|
if ($print_json) { |
111
|
0
|
|
|
|
|
0
|
$output->( $w->feed_print_json(@expanded_to_display) ); |
112
|
|
|
|
|
|
|
} else { |
113
|
0
|
|
|
|
|
0
|
$output->( $w->feed_print(@expanded_to_display) ); |
114
|
|
|
|
|
|
|
} |
115
|
|
|
|
|
|
|
} else { |
116
|
1
|
50
|
|
|
|
4
|
if ($print_json) { |
117
|
0
|
|
|
|
|
0
|
$output->( $w->feed_print_json_recent() ); |
118
|
|
|
|
|
|
|
} else { |
119
|
1
|
|
|
|
|
5
|
$output->( $w->feed_print_recent() ); |
120
|
|
|
|
|
|
|
} |
121
|
|
|
|
|
|
|
} |
122
|
|
|
|
|
|
|
|
123
|
1
|
|
|
|
|
342
|
return 0; |
124
|
|
|
|
|
|
|
} |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
1; |