merge morse-code goodie

master
Dylan Lloyd 2012-05-29 13:50:25 -04:00
commit 99a8b230f5
3 changed files with 47 additions and 0 deletions

View File

@ -27,6 +27,7 @@ Locale::Language = 3.21
Schedule::Cron::Events = 0
Convert::Color = 0.08
Convert::Color::Library = 0.03
Convert::Morse = 0.05
[Prereqs / TestRequires]
Test::More = 0.98

25
lib/DDG/Goodie/Morse.pm Normal file
View File

@ -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 startend => '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;

21
t/Morse.t Normal file
View File

@ -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;