Add CLI interface
[webservice-tdwtf.git] / lib / App / TDWTF.pm
diff --git a/lib/App/TDWTF.pm b/lib/App/TDWTF.pm
new file mode 100644 (file)
index 0000000..a8276dd
--- /dev/null
@@ -0,0 +1,33 @@
+package App::TDWTF;
+
+use 5.014000;
+use strict;
+use warnings;
+
+use Encode qw/encode/;
+use HTML::FormatText;
+use WebService::TDWTF;
+
+our $VERSION = '0.001';
+
+sub print_list {
+       my $idlen = length $_[0]->Id;
+       for my $art (@_) {
+               my $str = sprintf "%${idlen}d %s (by %s) in %s on %s\n", $art->Id, $art->Title, $art->AuthorName, $art->SeriesTitle, $art->DisplayDate;
+               print encode 'UTF-8', $str;
+       }
+}
+
+sub print_article {
+       my ($art) = @_;
+       printf "%s (by %s) in %s on %s\n\n", $art->Title, $art->AuthorName, $art->SeriesTitle, $art->DisplayDate;
+       say HTML::FormatText->format_string($art->Body)
+}
+
+sub run {
+       my ($args, @argv) = @_;
+       return print_list tdwtf_list_recent @argv if $args->{recent};
+       return print_list tdwtf_list_series @argv if $args->{series};
+       return print_list tdwtf_list_author @argv if $args->{author};
+       print_article tdwtf_article @argv
+}
This page took 0.009361 seconds and 4 git commands to generate.