From bb9cf4b9f728b4dd083a6bddde624236663a05a5 Mon Sep 17 00:00:00 2001 From: Sergey Zasenko Date: Mon, 28 May 2012 23:02:54 +0300 Subject: [PATCH 1/3] Morse code convertor --- lib/DDG/Goodie/Morse.pm | 25 +++++++++++++++++++++++++ t/Morse.t | 21 +++++++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100644 lib/DDG/Goodie/Morse.pm create mode 100644 t/Morse.t diff --git a/lib/DDG/Goodie/Morse.pm b/lib/DDG/Goodie/Morse.pm new file mode 100644 index 000000000..aec3ae7e9 --- /dev/null +++ b/lib/DDG/Goodie/Morse.pm @@ -0,0 +1,25 @@ +package DDG::Goodie::Morse; +# ABSTRACT: Converts to/from Morse code + +use DDG::Goodie; +use Convert::Morse qw(is_morse as_ascii as_morse); + +attribution + web => 'http://und3f.com', + twitter => 'und3f', + github => 'und3f', + cpan => 'UNDEF'; + +triggers start => 'morse'; + +zci is_cached => 1; +zci answer_type => 'chars'; + +handle remainder => sub { + return unless $_; + + my $convertor = is_morse($_) ? \&as_ascii : \&as_morse; + return "Morse: " . $convertor->($_); +}; + +1; diff --git a/t/Morse.t b/t/Morse.t new file mode 100644 index 000000000..64ad644ae --- /dev/null +++ b/t/Morse.t @@ -0,0 +1,21 @@ +#!/usr/bin/env perl + +use strict; +use warnings; +use utf8; +use Test::More; +use DDG::Test::Goodie; + +zci answer_type => 'chars'; +zci is_cached => 1; + +ddg_goodie_test( + [qw( + DDG::Goodie::Morse + )], + 'morse ... --- ...' => test_zci('Morse: SOS'), + 'morse hello, duck' => + test_zci('Morse: .... . .-.. .-.. --- --..-- -.. ..- -.-. -.-'), +); + +done_testing; From 283d0dc3f5035dd7edd54a65d16cd5e8f5756115 Mon Sep 17 00:00:00 2001 From: Dylan Lloyd Date: Tue, 29 May 2012 13:29:46 -0400 Subject: [PATCH 2/3] Added Convert::Morse dependency --- dist.ini | 1 + 1 file changed, 1 insertion(+) diff --git a/dist.ini b/dist.ini index 685c2d114..c19325989 100644 --- a/dist.ini +++ b/dist.ini @@ -25,6 +25,7 @@ Number::UN = 0.002 Locale::Language = 3.21 ; ParseCron Schedule::Cron::Events = 0 +Convert::Morse = 0.05 [Prereqs / TestRequires] Test::More = 0.98 From 89e47024042839dcc464c4daaef118978cccc096 Mon Sep 17 00:00:00 2001 From: Dylan Lloyd Date: Tue, 29 May 2012 13:48:15 -0400 Subject: [PATCH 3/3] expanded morse trigger --- lib/DDG/Goodie/Morse.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/DDG/Goodie/Morse.pm b/lib/DDG/Goodie/Morse.pm index aec3ae7e9..2a3daa2b4 100644 --- a/lib/DDG/Goodie/Morse.pm +++ b/lib/DDG/Goodie/Morse.pm @@ -10,7 +10,7 @@ attribution github => 'und3f', cpan => 'UNDEF'; -triggers start => 'morse'; +triggers startend => 'morse'; zci is_cached => 1; zci answer_type => 'chars';