Skip to content

Commit

Permalink
delete combined
Browse files Browse the repository at this point in the history
  • Loading branch information
yegg committed May 9, 2012
2 parents 3b49ff8 + a3714a5 commit 7446035
Show file tree
Hide file tree
Showing 5 changed files with 120 additions and 0 deletions.
1 change: 1 addition & 0 deletions dist.ini
Expand Up @@ -22,6 +22,7 @@ Locale::SubCountry = 1.50
; causing problems because not pp: HTML::Barcode::QRCode = 0.09 ; causing problems because not pp: HTML::Barcode::QRCode = 0.09
Unicode::Char = 0.02 Unicode::Char = 0.02
Number::UN = 0.002 Number::UN = 0.002
Locale::Language = 3.21


[Prereqs / TestRequires] [Prereqs / TestRequires]
Test::More = 0.98 Test::More = 0.98
Expand Down
33 changes: 33 additions & 0 deletions lib/DDG/Goodie/ISO639.pm
@@ -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;
35 changes: 35 additions & 0 deletions lib/DDG/Goodie/ParseCron.pm
@@ -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;
30 changes: 30 additions & 0 deletions t/ISO639.t
@@ -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;
21 changes: 21 additions & 0 deletions t/ParseCron.t
@@ -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.