Add CLI interface
[webservice-tdwtf.git] / lib / App / TDWTF.pm
CommitLineData
c89ffc8c
MG
1package App::TDWTF;
2
3use 5.014000;
4use strict;
5use warnings;
6
7use Encode qw/encode/;
8use HTML::FormatText;
9use WebService::TDWTF;
10
11our $VERSION = '0.001';
12
13sub 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
21sub 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
27sub run {
28 my ($args, @argv) = @_;
29 return print_list tdwtf_list_recent @argv if $args->{recent};
30 return print_list tdwtf_list_series @argv if $args->{series};
31 return print_list tdwtf_list_author @argv if $args->{author};
32 print_article tdwtf_article @argv
33}
This page took 0.010212 seconds and 4 git commands to generate.