Permalink
Browse files

delete combined

  • Loading branch information...
2 parents 3b49ff8 + a3714a5 commit 74460353e468c332b79ec6766ef1ee95b5ca82f9 yegg committed May 9, 2012
Showing with 120 additions and 0 deletions.
  1. +1 −0 dist.ini
  2. +33 −0 lib/DDG/Goodie/ISO639.pm
  3. +35 −0 lib/DDG/Goodie/ParseCron.pm
  4. +30 −0 t/ISO639.t
  5. +21 −0 t/ParseCron.t
View
@@ -22,6 +22,7 @@ Locale::SubCountry = 1.50
; causing problems because not pp: HTML::Barcode::QRCode = 0.09
Unicode::Char = 0.02
Number::UN = 0.002
+Locale::Language = 3.21
[Prereqs / TestRequires]
Test::More = 0.98
View
@@ -0,0 +1,33 @@
+package DDG::Goodie::ISO639;
+# ABSTRACT: ISO 639 language names and codes
+
+use DDG::Goodie;
+use Locale::Language;
+
+use constant WPHREF => "https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes";
+
+zci answer_type => "language";
+
+# TODO: support "iso 639" and "iso-639"
+triggers start => "iso639";
+
+handle remainder => sub {
+ my ($lang, $code) = langpair(shift) or return;
+ my $text = sprintf qq(%s (ISO 639-1 %s)), $lang, $code;
+ my $html = sprintf qq(%s (<a href="%s">ISO 639-1 %s</a>)), $lang, WPHREF, $code;
+ return $text, html => $html;
+};
+
+sub langpair {
+ if (my $lang = code2language($_)) {
+ return ($lang, language2code($lang));
+ }
+ if (my $code = language2code($_)) {
+ return (code2language($code), $code);
+ }
+ return;
+}
+
+zci is_cached => 1;
+
+1;
@@ -0,0 +1,35 @@
+package DDG::Goodie::ParseCron;
+# ABSTRACT: Parsing Crontabs - Show next occurence of cron event in human-readable form.
+# Example input:
+# crontab 42 12 3 Feb Sat
+# Example output:
+# Event will start next at 12:42:00 on 2 Feb, 2013
+#
+
+use DDG::Goodie;
+use Schedule::Cron::Events;
+
+my @mon = qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec);
+my @day = qw(Mon Tue Wed Thu Fri Sat Sun);
+
+triggers start => 'crontab';
+zci is_cached => 0;
+handle remainder => sub {
+ my $crontab = $_;
+ # We replace Jan,Feb.. and Mon,Tue.. with 1,2..
+ foreach (0..$#mon) {
+ my $newmonth=$_+1;
+ $crontab =~ s/$mon[$_]/$newmonth/;
+ }
+ foreach (0..$#day) {
+ my $newday=$_+1;
+ $crontab =~ s/$day[$_]/$newday/;
+ }
+ my $cron = new Schedule::Cron::Events($crontab) or return;
+ my ($sec, $min, $hour, $day, $month, $year) = $cron->nextEvent;
+ $year = $year+1900;
+ my $text = sprintf qq(Event will start next at %02d:%02d:%02d on %d %s, %d), $hour, $min, $sec, $day, $mon[$month], $year;
+ return $text if $_;
+ return;
+};
+1;
View
@@ -0,0 +1,30 @@
+#!/usr/bin/env perl
+use utf8;
+use strict;
+use warnings;
+use Test::More;
+use DDG::Test::Goodie;
+
+zci is_cached => 1;
+
+ddg_goodie_test(
+ ["DDG::Goodie::ISO639"],
+ "iso639 ab" => test_zci(
+ qq(Abkhazian (ISO 639-1 ab)),
+ html => qq(Abkhazian (<a href="https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes">ISO 639-1 ab</a>)),
+ answer_type => "language"
+ ),
+ "iso639 english" => test_zci(
+ qq(English (ISO 639-1 en)),
+ html => qq(English (<a href="https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes">ISO 639-1 en</a>)),
+ answer_type => "language"
+ ),
+ "iso-639 en" => test_zci(
+ qq(English (ISO 639-1 en)),
+ html => qq(English (<a href="https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes">ISO 639-1 en</a>)),
+ answer_type => "language"
+ ),
+ "iso639 xyz" => undef,
+);
+
+done_testing;
View
@@ -0,0 +1,21 @@
+#!/usr/bin/env perl
+
+use strict;
+use warnings;
+use Test::More;
+use DDG::Test::Goodie;
+
+zci answer_type => 'parsecron';
+zci is_cached => 0;
+
+ddg_goodie_test(
+ [qw(
+ DDG::Goodie::ParseCron
+ )],
+ 'crontab * */3 * * *' => test_zci(qr/^Event will start next at \d{2}:\d{2}:\d{2} on \d{1,2} [a-zA-Z]{3}, \d{4}$/),
+ 'crontab 42 12 3 Feb Sat' => test_zci(qr/^Event will start next at \d{2}:\d{2}:\d{2} on \d{1,2} [a-zA-Z]{3}, \d{4}$/),
+);
+
+done_testing;
+
+

0 comments on commit 7446035

Please sign in to comment.