X-Git-Url: http://git.ieval.ro/?p=webservice-tdwtf.git;a=blobdiff_plain;f=lib%2FApp%2FTDWTF.pm;fp=lib%2FApp%2FTDWTF.pm;h=a8276dd243b758941e6f99f1c1f7a932678809af;hp=0000000000000000000000000000000000000000;hb=c89ffc8c746bd1c3a34f87e96dca52a40d8b5720;hpb=73e257085d6bdf17f78d7f9a9abc6bda6b435bc7 diff --git a/lib/App/TDWTF.pm b/lib/App/TDWTF.pm new file mode 100644 index 0000000..a8276dd --- /dev/null +++ b/lib/App/TDWTF.pm @@ -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 +}