]>
Commit | Line | Data |
---|---|---|
1 | package App::TDWTF; | |
2 | ||
3 | use 5.014000; | |
4 | use strict; | |
5 | use warnings; | |
6 | ||
7 | use Encode qw/encode/; | |
8 | use HTML::FormatText; | |
9 | use WebService::TDWTF; | |
10 | ||
11 | our $VERSION = '0.003'; | |
12 | ||
13 | sub print_list { | |
14 | my $idlen = length $_[0]->Id; | |
15 | for my $art (@_) { | |
16 | my $str = sprintf "%${idlen}d %s (by %s) in %s on %s\n", $art->Id, $art->Title, $art->AuthorName, $art->SeriesTitle, $art->DisplayDate; | |
17 | print encode 'UTF-8', $str; | |
18 | } | |
19 | } | |
20 | ||
21 | sub print_article { | |
22 | my ($art) = @_; | |
23 | printf "%s (by %s) in %s on %s\n\n", $art->Title, $art->AuthorName, $art->SeriesTitle, $art->DisplayDate; | |
24 | say HTML::FormatText->format_string($art->Body) | |
25 | } | |
26 | ||
27 | sub print_series { | |
28 | for my $series (tdwtf_series) { | |
29 | $series->{$_} = encode 'UTF-8', ($series->{$_} // '') for keys %$series; | |
30 | say $series->{Slug}, ' ', $series->{Title}, "\n", $series->{Description}, "\n"; | |
31 | } | |
32 | } | |
33 | ||
34 | sub run { | |
35 | my ($args, @argv) = @_; | |
36 | return print_series if $args->{show_series}; | |
37 | return print_list tdwtf_list_recent @argv if $args->{recent}; | |
38 | return print_list tdwtf_list_series @argv if $args->{series}; | |
39 | return print_list tdwtf_list_author @argv if $args->{author}; | |
40 | print_article tdwtf_article @argv | |
41 | } | |
42 | ||
43 | 1; |