Add CLI interface
authorMarius Gavrilescu <marius@ieval.ro>
Sat, 16 Jan 2016 20:51:16 +0000 (20:51 +0000)
committerMarius Gavrilescu <marius@ieval.ro>
Sat, 16 Jan 2016 20:51:16 +0000 (20:51 +0000)
MANIFEST
Makefile.PL
lib/App/TDWTF.pm [new file with mode: 0644]
t/App-TDWTF.t [new file with mode: 0644]
tdwtf [new file with mode: 0755]

index 3c842173e3715d149042b86d0036d880759a5f8f..859fc0066a51b202b419ce034f560c8144702273 100644 (file)
--- a/MANIFEST
+++ b/MANIFEST
@@ -2,6 +2,9 @@ Changes
 Makefile.PL
 MANIFEST
 README
+t/App-TDWTF.t
 t/WebService-TDWTF.t
+lib/App/TDWTF.pm
 lib/WebService/TDWTF.pm
 lib/WebService/TDWTF/Article.pm
+tdwtf
index adfd6f756dd048bf9271cde302130aecb3d925c0..d43f618c2ae2d8a6f14c018007c4c8f71e7461bf 100644 (file)
@@ -11,11 +11,13 @@ WriteMakefile(
        VERSION_FROM      => 'lib/WebService/TDWTF.pm',
        ABSTRACT_FROM     => 'lib/WebService/TDWTF.pm',
        AUTHOR            => 'Marius Gavrilescu <marius@ieval.ro>',
+       EXE_FILES         => ['tdwtf'],
        MIN_PERL_VERSION  => '5.14.0',
        LICENSE           => 'perl',
        SIGN              => 1,
        PREREQ_PM         => {
                qw/Class::Accessor::Fast 0
+                  HTML::FormatText      0
                   JSON::MaybeXS         0/,
        },
        @tr,
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
+}
diff --git a/t/App-TDWTF.t b/t/App-TDWTF.t
new file mode 100644 (file)
index 0000000..ddd02e5
--- /dev/null
@@ -0,0 +1,6 @@
+#!/usr/bin/perl
+use strict;
+use warnings;
+
+use Test::More tests => 1;
+BEGIN { use_ok('App::TDWTF') };
diff --git a/tdwtf b/tdwtf
new file mode 100755 (executable)
index 0000000..40d8e46
--- /dev/null
+++ b/tdwtf
@@ -0,0 +1,70 @@
+#!/usr/bin/perl
+use v5.14;
+use warnings;
+
+use App::TDWTF;
+use Getopt::Long;
+
+my %args;
+GetOptions(
+       recent => \$args{recent},
+       series => \$args{series},
+       author => \$args{author},
+);
+
+App::TDWTF::run(\%args, @ARGV);
+
+__END__
+
+=encoding utf-8
+
+=head1 NAME
+
+tdwtf - CLI interface to thedailywtf.com
+
+=head1 SYNOPSIS
+
+  tdwtf                  # prints a random article, as text
+  tdwtf 8339             # prints the article with ID 8339, as text
+  tdwtf --recent         # lists the most recent 8 articles
+  tdwtf --recent 10      # lists the most recent 10 articles
+  tdwtf --recent 2015 01 # lists all articles published in January 2015
+  tdwtf --series errord  # lists the most recent 8 Error'd articles
+  tdwtf --series errord 10
+  tdwtf --series errord 2015 01
+  tdwtf --author snoofle # lists the most recent 8 articles by snoofle
+  tdwtf --author snoofle 10
+  tdwtf --author snoofle 2015 01
+
+=head1 DESCRIPTION
+
+tdwtf is an CLI interface to the API of L<http://thedailywtf.com>.
+Quoting the website's sidebar:
+
+    Founded in 2004 by Alex Papadimoulis, The Daily WTF is your
+    how-not-to guide for developing software. We recount tales of
+    disastrous development, from project management gone spectacularly
+    bad to inexplicable coding choices.
+
+See SYNOPSIS for usage examples.
+
+=head1 SEE ALSO
+
+L<http://thedailywtf.com/>
+
+L<WebService::TDWTF>
+
+=head1 AUTHOR
+
+Marius Gavrilescu, E<lt>marius@ieval.roE<gt>
+
+=head1 COPYRIGHT AND LICENSE
+
+Copyright (C) 2016 by Marius Gavrilescu
+
+This library is free software; you can redistribute it and/or modify
+it under the same terms as Perl itself, either Perl version 5.20.2 or,
+at your option, any later version of Perl 5 you may have available.
+
+
+=cut
This page took 0.013616 seconds and 4 git commands to generate.