Commits

Toby Inkster  committed ade9204

use Lingua::Boolean::Tiny to process Y/N answers

  • Participants
  • Parent commits 6740351

Comments (0)

Files changed (3)

File lib/Ask/API.pm

 	requires 'entry';  # get a string of text
 	requires 'info';   # display a string of text
 	
+	sub _lang_support {
+		my $self = shift;
+		require Lingua::Boolean::Tiny;
+		"Lingua::Boolean::Tiny"->new(@_);
+	}
+	
 	sub is_usable {
 		my ($self) = @_;
 		return 1;
 
 	sub question {
 		my ($self, %o) = @_;
-		
-		$o{cancel} //= qr{^(no|n|cancel)$}i;
-		
+				
 		my $response = $self->entry(text => $o{text});
-		return !!1 if $response ~~ $o{ok};
-		return !!0 if $response ~~ $o{cancel};
-		return !!1;
+		my $lang     = $self->_lang_support($o{lang});
+		$lang->boolean($response);
 	}
 	
 	sub file_selection {

File meta/makefile.pret

 	requires          p`Moo 1.000006`;
 	requires          p`namespace::sweep 0.006`;
 	requires          p`Sub::Exporter::Progressive`;
+	requires          p`Lingua::Boolean::Tiny 0.003`;
 	recommends        p`File::Which`;
 	recommends        p`System::Command`;
 	recommends        p`Gtk2`;
+=head1 PURPOSE
+
+Check some basic IO works with L<Ask::Callback>.
+
+=head1 AUTHOR
+
+Toby Inkster E<lt>tobyink@cpan.orgE<gt>.
+
+=head1 COPYRIGHT AND LICENCE
+
+This software is copyright (c) 2012-2013 by Toby Inkster.
+
+This is free software; you can redistribute it and/or modify it under
+the same terms as the Perl 5 programming language system itself.
+
+=cut
+
+use strict;
+use warnings;
+use Test::More;
+
+BEGIN { $ENV{PERL_ASK_BACKEND} = 'Ask::Callback' };
+
+use Ask;
+
+my @input;
+my @output;
+
+sub flush_buffers {
+	@input = @output = ();
+}
+
+my $ask = Ask->detect(
+	input_callback  => sub { shift @input },
+	output_callback => sub { push @output, $_[0] },
+);
+
+{
+	@input = 'oui';
+	is(
+		!!$ask->question(text => 'Ca va bien?', lang => "fr"),
+		!!1,
+	);
+	flush_buffers();
+}
+
+{
+	@input = 'tidak';
+	is(
+		!!$ask->question(text => 'Anda ok?', lang => "ms"),
+		!!0,
+	);
+	flush_buffers();
+}
+
+done_testing;