Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

delete combined

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

0 notes on commit 7446035

Please sign in to comment.
Something went wrong with that request. Please try again.